From 6a1f9e6fc7272599de76fec37e31db4978780649 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 26 Dec 2021 22:12:41 +0800 Subject: [PATCH 1/3] mangling_v0: Update tests for the rust-demangler tool --- src/tools/rust-demangler/tests/lib.rs | 32 +++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/tools/rust-demangler/tests/lib.rs b/src/tools/rust-demangler/tests/lib.rs index 5a67b42322535..85019df7867dd 100644 --- a/src/tools/rust-demangler/tests/lib.rs +++ b/src/tools/rust-demangler/tests/lib.rs @@ -29,14 +29,14 @@ cc[4d6468d6c9fd4bb3]::spawn::{closure#0}::{closure#0} as core[846817f741e54dfd]::iter::iterator::Iterator>::rposition::::{closure#0} alloc[f15a878b47eb696b]::alloc::box_free::> INtC8arrayvec8ArrayVechKj7b_E -> -> -> -> -> -> -> -> +> +> +> +> +> +> +> +> >::foo::FOO foo[0] foo[0] @@ -51,14 +51,14 @@ cc::spawn::{closure#0}::{closure#0} as core::iter::iterator::Iterator>::rposition::::{closure#0} alloc::alloc::box_free::> INtC8arrayvec8ArrayVechKj7b_E -> -> -> -> -> -> -> -> +> +> +> +> +> +> +> +> >::foo::FOO foo[0] foo[0] From 1b8daf8c58267a5d9fae2021a311dfbbda11b02f Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Mon, 27 Dec 2021 20:05:22 +0800 Subject: [PATCH 2/3] mangling_v0: Add a test for mangling of foreign types --- src/test/ui/symbol-names/foreign-types.rs | 19 ++++++++++++++++++ src/test/ui/symbol-names/foreign-types.stderr | 20 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/test/ui/symbol-names/foreign-types.rs create mode 100644 src/test/ui/symbol-names/foreign-types.stderr diff --git a/src/test/ui/symbol-names/foreign-types.rs b/src/test/ui/symbol-names/foreign-types.rs new file mode 100644 index 0000000000000..33c5e6adfef29 --- /dev/null +++ b/src/test/ui/symbol-names/foreign-types.rs @@ -0,0 +1,19 @@ +// build-fail +// compile-flags: -Z symbol-mangling-version=v0 + +#![feature(extern_types)] +#![feature(rustc_attrs)] + +extern "C" { + type ForeignType; +} + +struct Check(T); + +#[rustc_symbol_name] +//~^ ERROR symbol-name(_RMCs +//~| ERROR demangling(>) +impl Check {} + +fn main() {} diff --git a/src/test/ui/symbol-names/foreign-types.stderr b/src/test/ui/symbol-names/foreign-types.stderr new file mode 100644 index 0000000000000..c6c59a6c82ea7 --- /dev/null +++ b/src/test/ui/symbol-names/foreign-types.stderr @@ -0,0 +1,20 @@ +error: symbol-name(_RMCsCRATE_HASH_13foreign_typesINtB_5CheckNvNtB_011ForeignTypeE) + --> $DIR/foreign-types.rs:13:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling(>) + --> $DIR/foreign-types.rs:13:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling-alt(>) + --> $DIR/foreign-types.rs:13:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 3 previous errors + From 333a5cc3691a96aab461ebcbc6064ee79356f1ae Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Mon, 27 Dec 2021 20:09:20 +0800 Subject: [PATCH 3/3] mangling_v0: Skip extern blocks during mangling --- compiler/rustc_symbol_mangling/src/v0.rs | 6 +++--- src/test/ui/symbol-names/foreign-types.rs | 2 +- src/test/ui/symbol-names/foreign-types.stderr | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index c2519adcbe416..fbb9e28d182f8 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -771,9 +771,9 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> { disambiguated_data: &DisambiguatedDefPathData, ) -> Result { let ns = match disambiguated_data.data { - // FIXME: It shouldn't be necessary to add anything for extern block segments, - // but we add 't' for backward compatibility. - DefPathData::ForeignMod => 't', + // Extern block segments can be skipped, names from extern blocks + // are effectively living in their parent modules. + DefPathData::ForeignMod => return print_prefix(self), // Uppercase categories are more stable than lowercase ones. DefPathData::TypeNs(_) => 't', diff --git a/src/test/ui/symbol-names/foreign-types.rs b/src/test/ui/symbol-names/foreign-types.rs index 33c5e6adfef29..8f5b07769caff 100644 --- a/src/test/ui/symbol-names/foreign-types.rs +++ b/src/test/ui/symbol-names/foreign-types.rs @@ -1,5 +1,5 @@ // build-fail -// compile-flags: -Z symbol-mangling-version=v0 +// compile-flags: -C symbol-mangling-version=v0 #![feature(extern_types)] #![feature(rustc_attrs)] diff --git a/src/test/ui/symbol-names/foreign-types.stderr b/src/test/ui/symbol-names/foreign-types.stderr index c6c59a6c82ea7..fcffdd2a8ec15 100644 --- a/src/test/ui/symbol-names/foreign-types.stderr +++ b/src/test/ui/symbol-names/foreign-types.stderr @@ -1,4 +1,4 @@ -error: symbol-name(_RMCsCRATE_HASH_13foreign_typesINtB_5CheckNvNtB_011ForeignTypeE) +error: symbol-name(_RMCsCRATE_HASH_13foreign_typesINtB_5CheckNvB_11ForeignTypeE) --> $DIR/foreign-types.rs:13:1 | LL | #[rustc_symbol_name]