Skip to content

Commit 67f47ca

Browse files
committed
Tighten the error span for explort_name null byte check
Simply because it looks a little bit prettier that way, IMO
1 parent da2202c commit 67f47ca

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -252,22 +252,21 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
252252
codegen_fn_attrs.flags |= CodegenFnAttrFlags::TRACK_CALLER
253253
}
254254
sym::export_name => {
255-
if let Some(s) = attr.value_str() {
256-
if s.as_str().contains('\0') {
255+
if let Some(exported_name) = attr.value_str() {
256+
let value_span = attr.value_span().expect("attibute has value but not a span");
257+
if exported_name.as_str().contains('\0') {
257258
// `#[export_name = ...]` will be converted to a null-terminated string,
258259
// so it may not contain any null characters.
259-
tcx.dcx().emit_err(errors::NullOnExport { span: attr.span() });
260+
tcx.dcx().emit_err(errors::NullOnExport { span: value_span });
260261
}
261-
if s.as_str().starts_with("llvm.") {
262+
if exported_name.as_str().starts_with("llvm.") {
262263
// Symbols starting with "llvm." are reserved by LLVM
263264
// trying to define those would produce invalid IR.
264265
// LLVM complain about those *if* we enable LLVM verification checks
265266
// but we often don't enable them by default due to perf reasons.
266-
tcx.dcx().emit_err(errors::ExportNameLLVMIntrinsic {
267-
span: attr.value_span().expect("attibute has value but not a span"),
268-
});
267+
tcx.dcx().emit_err(errors::ExportNameLLVMIntrinsic { span: value_span });
269268
}
270-
codegen_fn_attrs.export_name = Some(s);
269+
codegen_fn_attrs.export_name = Some(exported_name);
271270
mixed_export_name_no_mangle_lint_state.track_export_name(attr.span());
272271
}
273272
}

tests/ui/attributes/export_name-checks.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ LL | #[export_name = "llvm.x86.qwerty"]
1515
= note: symbols starting with "llvm." are reserved for LLVM intrinsics and cannot be defined in user code
1616

1717
error[E0648]: `export_name` may not contain null characters
18-
--> $DIR/export_name-checks.rs:17:1
18+
--> $DIR/export_name-checks.rs:17:15
1919
|
2020
LL | #[export_name="ab\0cd"]
21-
| ^^^^^^^^^^^^^^^^^^^^^^^
21+
| ^^^^^^^^
2222

2323
error: aborting due to 3 previous errors
2424

tests/ui/error-codes/E0648.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0648]: `export_name` may not contain null characters
2-
--> $DIR/E0648.rs:1:1
2+
--> $DIR/E0648.rs:1:15
33
|
44
LL | #[export_name="\0foo"]
5-
| ^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^
66

77
error: aborting due to 1 previous error
88

0 commit comments

Comments
 (0)