Skip to content

Commit 715cda2

Browse files
authored
Rollup merge of #92316 - petrochenkov:extmangle, r=wesleywiser
mangling_v0: Skip extern blocks during mangling There's no need to include the dummy `Nt` into the symbol name, items in extern blocks belong to their parent modules for all purposes except for inheriting the ABI and attributes. Follow up to #92032 (There's also a drive-by fix to the `rust-demangler` tool's tests, which don't run on CI, I initially attempted using them for testing this PR.)
2 parents 5e57faa + 333a5cc commit 715cda2

File tree

4 files changed

+58
-19
lines changed

4 files changed

+58
-19
lines changed

compiler/rustc_symbol_mangling/src/v0.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -772,9 +772,9 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
772772
disambiguated_data: &DisambiguatedDefPathData,
773773
) -> Result<Self::Path, Self::Error> {
774774
let ns = match disambiguated_data.data {
775-
// FIXME: It shouldn't be necessary to add anything for extern block segments,
776-
// but we add 't' for backward compatibility.
777-
DefPathData::ForeignMod => 't',
775+
// Extern block segments can be skipped, names from extern blocks
776+
// are effectively living in their parent modules.
777+
DefPathData::ForeignMod => return print_prefix(self),
778778

779779
// Uppercase categories are more stable than lowercase ones.
780780
DefPathData::TypeNs(_) => 't',
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// build-fail
2+
// compile-flags: -C symbol-mangling-version=v0
3+
4+
#![feature(extern_types)]
5+
#![feature(rustc_attrs)]
6+
7+
extern "C" {
8+
type ForeignType;
9+
}
10+
11+
struct Check<T: ?Sized>(T);
12+
13+
#[rustc_symbol_name]
14+
//~^ ERROR symbol-name(_RMCs
15+
//~| ERROR demangling(<foreign_types[
16+
//~| ERROR demangling-alt(<foreign_types::Check<foreign_types::ForeignType>>)
17+
impl Check<ForeignType> {}
18+
19+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: symbol-name(_RMCsCRATE_HASH_13foreign_typesINtB<REF>_5CheckNvB<REF>_11ForeignTypeE)
2+
--> $DIR/foreign-types.rs:13:1
3+
|
4+
LL | #[rustc_symbol_name]
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
7+
error: demangling(<foreign_types[HASH]::Check<foreign_types[HASH]::ForeignType>>)
8+
--> $DIR/foreign-types.rs:13:1
9+
|
10+
LL | #[rustc_symbol_name]
11+
| ^^^^^^^^^^^^^^^^^^^^
12+
13+
error: demangling-alt(<foreign_types::Check<foreign_types::ForeignType>>)
14+
--> $DIR/foreign-types.rs:13:1
15+
|
16+
LL | #[rustc_symbol_name]
17+
| ^^^^^^^^^^^^^^^^^^^^
18+
19+
error: aborting due to 3 previous errors
20+

src/tools/rust-demangler/tests/lib.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ cc[4d6468d6c9fd4bb3]::spawn::{closure#0}::{closure#0}
2929
<core[846817f741e54dfd]::slice::Iter<u8> as core[846817f741e54dfd]::iter::iterator::Iterator>::rposition::<core[846817f741e54dfd]::slice::memchr::memrchr::{closure#1}>::{closure#0}
3030
alloc[f15a878b47eb696b]::alloc::box_free::<dyn alloc[f15a878b47eb696b]::boxed::FnBox<(), Output = ()>>
3131
INtC8arrayvec8ArrayVechKj7b_E
32-
<const_generic[317d481089b8c8fe]::Unsigned<11: u8>>
33-
<const_generic[317d481089b8c8fe]::Signed<152: i16>>
34-
<const_generic[317d481089b8c8fe]::Signed<-11: i8>>
35-
<const_generic[317d481089b8c8fe]::Bool<false: bool>>
36-
<const_generic[317d481089b8c8fe]::Bool<true: bool>>
37-
<const_generic[317d481089b8c8fe]::Char<'v': char>>
38-
<const_generic[317d481089b8c8fe]::Char<'\n': char>>
39-
<const_generic[317d481089b8c8fe]::Char<'∂': char>>
32+
<const_generic[317d481089b8c8fe]::Unsigned<11u8>>
33+
<const_generic[317d481089b8c8fe]::Signed<152i16>>
34+
<const_generic[317d481089b8c8fe]::Signed<-11i8>>
35+
<const_generic[317d481089b8c8fe]::Bool<false>>
36+
<const_generic[317d481089b8c8fe]::Bool<true>>
37+
<const_generic[317d481089b8c8fe]::Char<'v'>>
38+
<const_generic[317d481089b8c8fe]::Char<'\n'>>
39+
<const_generic[317d481089b8c8fe]::Char<'∂'>>
4040
<const_generic[317d481089b8c8fe]::Foo<_>>::foo::FOO
4141
foo[0]
4242
foo[0]
@@ -51,14 +51,14 @@ cc::spawn::{closure#0}::{closure#0}
5151
<core::slice::Iter<u8> as core::iter::iterator::Iterator>::rposition::<core::slice::memchr::memrchr::{closure#1}>::{closure#0}
5252
alloc::alloc::box_free::<dyn alloc::boxed::FnBox<(), Output = ()>>
5353
INtC8arrayvec8ArrayVechKj7b_E
54-
<const_generic::Unsigned<11: u8>>
55-
<const_generic::Signed<152: i16>>
56-
<const_generic::Signed<-11: i8>>
57-
<const_generic::Bool<false: bool>>
58-
<const_generic::Bool<true: bool>>
59-
<const_generic::Char<'v': char>>
60-
<const_generic::Char<'\n': char>>
61-
<const_generic::Char<'∂': char>>
54+
<const_generic::Unsigned<11u8>>
55+
<const_generic::Signed<152i16>>
56+
<const_generic::Signed<-11i8>>
57+
<const_generic::Bool<false>>
58+
<const_generic::Bool<true>>
59+
<const_generic::Char<'v'>>
60+
<const_generic::Char<'\n'>>
61+
<const_generic::Char<'∂'>>
6262
<const_generic::Foo<_>>::foo::FOO
6363
foo[0]
6464
foo[0]

0 commit comments

Comments
 (0)