Skip to content

Commit 7968195

Browse files
update error not to leak implementation details
1 parent 7c97742 commit 7968195

File tree

3 files changed

+19
-28
lines changed

3 files changed

+19
-28
lines changed

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -626,35 +626,31 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
626626
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL)
627627
&& codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NO_MANGLE)
628628
{
629-
let (span, lang_item) = lang_items::extract(attrs)
630-
.map_or((None, None), |(name, span)| (Some(span), LangItem::from_name(name)));
629+
let lang_item =
630+
lang_items::extract(attrs).map_or(None, |(name, _span)| LangItem::from_name(name));
631631
// This should never use the default as `no_mangle` is present in the attributes list
632632
let no_mangle_span = no_mangle_span.unwrap_or_default();
633-
let label = if let Some(lang_item) = lang_item {
634-
format!("should be the {} item", lang_item.name())
635-
} else {
636-
format!("should be the internal language item")
637-
};
638633
let mut err = tcx
639634
.dcx()
640635
.struct_span_err(
641636
no_mangle_span,
642637
"`#[no_mangle]` cannot be used on internal language items",
643638
)
644639
.with_note("Rustc requires this item to have a specific mangled name.")
645-
.with_note("If you are trying to prevent mangling to ease debugging, many")
646-
.with_note("debuggers support a command such as `rbreak {sym}` to")
647-
.with_note("match `.*{sym}.*` instead of `break {sym}` on a specific name")
648-
.with_span_label(tcx.def_span(did), label);
640+
.with_span_label(tcx.def_span(did), "should be the internal language item");
649641
if let Some(lang_item) = lang_item {
650-
if let Some(span) = span {
651-
let label_attr = format!("this defines it as the `{}` item", lang_item.name());
652-
err = err.with_span_label(span, label_attr);
653-
}
654642
if let Some(link_name) = lang_item.link_name() {
655-
let renamed =
656-
format!("In this case it is automatically renamed to `{}`", link_name);
657-
err = err.with_note(renamed);
643+
// let renamed =
644+
// format!("In this case it is automatically renamed to `{}`", link_name);
645+
// err = err.with_note(renamed);
646+
err = err
647+
.with_note("If you are trying to prevent mangling to ease debugging, many")
648+
.with_note(format!(
649+
"debuggers support a command such as `rbreak {link_name}` to"
650+
))
651+
.with_note(format!(
652+
"match `.*{link_name}.*` instead of `break {link_name}` on a specific name"
653+
))
658654
}
659655
}
660656

tests/ui/codegen/no-mangle-on-internal-lang-items.stderr

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ LL | #[unsafe(no_mangle)]
66
LL | fn internal_lang_function () {
77
| ---------------------------- should be the internal language item
88
|
9-
= note: The linker requires specific names for internal language items.
10-
= note: If you are trying to prevent mangling to ease debugging, many
11-
= note: debuggers support a command such as `rbreak {sym}` to
12-
= note: match `.*{sym}.*` instead of `break {sym}` on a specific name
9+
= note: Rustc requires this item to have a specific mangled name.
1310

1411
error: aborting due to 1 previous error
1512

tests/ui/codegen/no-mangle-on-panic-handler.stderr

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ error: `#[no_mangle]` cannot be used on internal language items
44
LL | #[unsafe(no_mangle)]
55
| ^^^^^^^^^^^^^^^^^^^^
66
LL | #[panic_handler]
7-
| ---------------- this defines it as the `panic_impl` item
87
LL | pub unsafe fn panic_fmt(pi: &PanicInfo) -> ! {
9-
| -------------------------------------------- should be the panic_impl item
8+
| -------------------------------------------- should be the internal language item
109
|
11-
= note: The linker requires specific names for internal language items.
10+
= note: Rustc requires this item to have a specific mangled name.
1211
= note: If you are trying to prevent mangling to ease debugging, many
13-
= note: debuggers support a command such as `rbreak {sym}` to
14-
= note: match `.*{sym}.*` instead of `break {sym}` on a specific name
15-
= note: In this case it is automatically renamed to `rust_begin_unwind`
12+
= note: debuggers support a command such as `rbreak rust_begin_unwind` to
13+
= note: match `.*rust_begin_unwind.*` instead of `break rust_begin_unwind` on a specific name
1614

1715
error: aborting due to 1 previous error
1816

0 commit comments

Comments
 (0)