diff --git a/Cargo.lock b/Cargo.lock index 81806b60635..5a981b3f08f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2688,6 +2688,7 @@ dependencies = [ "flate2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "rustc 0.0.0", + "rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_data_structures 0.0.0", "rustc_metadata 0.0.0", "rustc_mir 0.0.0", diff --git a/src/librustc_codegen_utils/Cargo.toml b/src/librustc_codegen_utils/Cargo.toml index c75208b9e06..531c5abb147 100644 --- a/src/librustc_codegen_utils/Cargo.toml +++ b/src/librustc_codegen_utils/Cargo.toml @@ -13,6 +13,7 @@ test = false [dependencies] flate2 = "1.0" log = "0.4" +rustc-demangle = "0.1.15" syntax = { path = "../libsyntax" } syntax_pos = { path = "../libsyntax_pos" } diff --git a/src/librustc_codegen_utils/symbol_names_test.rs b/src/librustc_codegen_utils/symbol_names_test.rs index 27ae0b97e59..b935ccb7398 100644 --- a/src/librustc_codegen_utils/symbol_names_test.rs +++ b/src/librustc_codegen_utils/symbol_names_test.rs @@ -39,8 +39,12 @@ fn process_attrs(&mut self, if attr.check_name(SYMBOL_NAME) { // for now, can only use on monomorphic names let instance = Instance::mono(tcx, def_id); - let name = self.tcx.symbol_name(instance); - tcx.sess.span_err(attr.span, &format!("symbol-name({})", name)); + let mangled = self.tcx.symbol_name(instance); + tcx.sess.span_err(attr.span, &format!("symbol-name({})", mangled)); + if let Ok(demangling) = rustc_demangle::try_demangle(&mangled.as_str()) { + tcx.sess.span_err(attr.span, &format!("demangling({})", demangling)); + tcx.sess.span_err(attr.span, &format!("demangling-alt({:#})", demangling)); + } } else if attr.check_name(DEF_PATH) { let path = tcx.def_path_str(def_id); tcx.sess.span_err(attr.span, &format!("def-path({})", path)); diff --git a/src/test/ui/symbol-names/basic.rs b/src/test/ui/symbol-names/basic.rs index 086b903b973..1459ac014ea 100644 --- a/src/test/ui/symbol-names/basic.rs +++ b/src/test/ui/symbol-names/basic.rs @@ -1,6 +1,9 @@ #![feature(rustc_attrs)] -#[rustc_symbol_name] //~ ERROR _ZN5basic4main +#[rustc_symbol_name] +//~^ ERROR symbol-name(_ZN5basic4main +//~| ERROR demangling(basic::main +//~| ERROR demangling-alt(basic::main) #[rustc_def_path] //~ ERROR def-path(main) fn main() { } diff --git a/src/test/ui/symbol-names/basic.stderr b/src/test/ui/symbol-names/basic.stderr index 7539cbada8b..ebb8b4390d2 100644 --- a/src/test/ui/symbol-names/basic.stderr +++ b/src/test/ui/symbol-names/basic.stderr @@ -4,11 +4,23 @@ error: symbol-name(_ZN5basic4main17hd72940ef9669d526E) LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ +error: demangling(basic::main::hd72940ef9669d526) + --> $DIR/basic.rs:3:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling-alt(basic::main) + --> $DIR/basic.rs:3:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + error: def-path(main) - --> $DIR/basic.rs:4:1 + --> $DIR/basic.rs:7:1 | LL | #[rustc_def_path] | ^^^^^^^^^^^^^^^^^ -error: aborting due to 2 previous errors +error: aborting due to 4 previous errors diff --git a/src/test/ui/symbol-names/impl1.rs b/src/test/ui/symbol-names/impl1.rs index c712137e828..803fa856b60 100644 --- a/src/test/ui/symbol-names/impl1.rs +++ b/src/test/ui/symbol-names/impl1.rs @@ -5,7 +5,10 @@ mod foo { pub struct Foo { x: u32 } impl Foo { - #[rustc_symbol_name] //~ ERROR _ZN5impl13foo3Foo3bar + #[rustc_symbol_name] + //~^ ERROR symbol-name(_ZN5impl13foo3Foo3bar + //~| ERROR demangling(impl1::foo::Foo::bar + //~| ERROR demangling-alt(impl1::foo::Foo::bar) #[rustc_def_path] //~ ERROR def-path(foo::Foo::bar) fn bar() { } } @@ -15,7 +18,10 @@ mod bar { use foo::Foo; impl Foo { - #[rustc_symbol_name] //~ ERROR _ZN5impl13bar33_$LT$impl$u20$impl1..foo..Foo$GT$3baz + #[rustc_symbol_name] + //~^ ERROR symbol-name(_ZN5impl13bar33_$LT$impl$u20$impl1..foo..Foo$GT$3baz + //~| ERROR demangling(impl1::bar::::baz + //~| ERROR demangling-alt(impl1::bar::::baz) #[rustc_def_path] //~ ERROR def-path(bar::::baz) fn baz() { } } diff --git a/src/test/ui/symbol-names/impl1.stderr b/src/test/ui/symbol-names/impl1.stderr index 20e48782a3a..3a7d540c488 100644 --- a/src/test/ui/symbol-names/impl1.stderr +++ b/src/test/ui/symbol-names/impl1.stderr @@ -4,23 +4,47 @@ error: symbol-name(_ZN5impl13foo3Foo3bar17he53b9bee7600ed8dE) LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ +error: demangling(impl1::foo::Foo::bar::he53b9bee7600ed8d) + --> $DIR/impl1.rs:8:9 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling-alt(impl1::foo::Foo::bar) + --> $DIR/impl1.rs:8:9 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + error: def-path(foo::Foo::bar) - --> $DIR/impl1.rs:9:9 + --> $DIR/impl1.rs:12:9 | LL | #[rustc_def_path] | ^^^^^^^^^^^^^^^^^ error: symbol-name(_ZN5impl13bar33_$LT$impl$u20$impl1..foo..Foo$GT$3baz17h86c41f0462d901d4E) - --> $DIR/impl1.rs:18:9 + --> $DIR/impl1.rs:21:9 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling(impl1::bar::::baz::h86c41f0462d901d4) + --> $DIR/impl1.rs:21:9 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling-alt(impl1::bar::::baz) + --> $DIR/impl1.rs:21:9 | LL | #[rustc_symbol_name] | ^^^^^^^^^^^^^^^^^^^^ error: def-path(bar::::baz) - --> $DIR/impl1.rs:19:9 + --> $DIR/impl1.rs:25:9 | LL | #[rustc_def_path] | ^^^^^^^^^^^^^^^^^ -error: aborting due to 4 previous errors +error: aborting due to 8 previous errors diff --git a/src/test/ui/symbol-names/issue-60925.rs b/src/test/ui/symbol-names/issue-60925.rs index e9f763ad7cf..22efa978bd2 100644 --- a/src/test/ui/symbol-names/issue-60925.rs +++ b/src/test/ui/symbol-names/issue-60925.rs @@ -14,7 +14,9 @@ mod foo { impl Foo<::llvm::Foo> { #[rustc_symbol_name] -//~^ ERROR _ZN11issue_609253foo36Foo$LT$issue_60925..llv$6d$..Foo$GT$3foo17h059a991a004536adE + //~^ ERROR symbol-name(_ZN11issue_609253foo36Foo$LT$issue_60925..llv$6d$..Foo$GT$3foo + //~| ERROR demangling(issue_60925::foo::Foo $DIR/issue-60925.rs:16:9 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling-alt(issue_60925::foo::Foo $DIR/issue-60925.rs:16:9 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 3 previous errors