Skip to content

Commit 654d059

Browse files
committed
rustc_codegen_utils: test demangler output, not just symbol names.
1 parent e898905 commit 654d059

File tree

9 files changed

+78
-13
lines changed

9 files changed

+78
-13
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2688,6 +2688,7 @@ dependencies = [
26882688
"flate2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
26892689
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
26902690
"rustc 0.0.0",
2691+
"rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
26912692
"rustc_data_structures 0.0.0",
26922693
"rustc_metadata 0.0.0",
26932694
"rustc_mir 0.0.0",

src/librustc_codegen_utils/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ test = false
1313
[dependencies]
1414
flate2 = "1.0"
1515
log = "0.4"
16+
rustc-demangle = "0.1.15"
1617

1718
syntax = { path = "../libsyntax" }
1819
syntax_pos = { path = "../libsyntax_pos" }

src/librustc_codegen_utils/symbol_names_test.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ impl<'a, 'tcx> SymbolNamesTest<'a, 'tcx> {
3939
if attr.check_name(SYMBOL_NAME) {
4040
// for now, can only use on monomorphic names
4141
let instance = Instance::mono(tcx, def_id);
42-
let name = self.tcx.symbol_name(instance);
43-
tcx.sess.span_err(attr.span, &format!("symbol-name({})", name));
42+
let mangled = self.tcx.symbol_name(instance);
43+
tcx.sess.span_err(attr.span, &format!("symbol-name({})", mangled));
44+
if let Ok(demangling) = rustc_demangle::try_demangle(&mangled.as_str()) {
45+
tcx.sess.span_err(attr.span, &format!("demangling({})", demangling));
46+
tcx.sess.span_err(attr.span, &format!("demangling-alt({:#})", demangling));
47+
}
4448
} else if attr.check_name(DEF_PATH) {
4549
let path = tcx.def_path_str(def_id);
4650
tcx.sess.span_err(attr.span, &format!("def-path({})", path));

src/test/ui/symbol-names/basic.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#![feature(rustc_attrs)]
22

3-
#[rustc_symbol_name] //~ ERROR _ZN5basic4main
3+
#[rustc_symbol_name]
4+
//~^ ERROR symbol-name(_ZN5basic4main
5+
//~| ERROR demangling(basic::main
6+
//~| ERROR demangling-alt(basic::main)
47
#[rustc_def_path] //~ ERROR def-path(main)
58
fn main() {
69
}

src/test/ui/symbol-names/basic.stderr

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,23 @@ error: symbol-name(_ZN5basic4main17hd72940ef9669d526E)
44
LL | #[rustc_symbol_name]
55
| ^^^^^^^^^^^^^^^^^^^^
66

7+
error: demangling(basic::main::hd72940ef9669d526)
8+
--> $DIR/basic.rs:3:1
9+
|
10+
LL | #[rustc_symbol_name]
11+
| ^^^^^^^^^^^^^^^^^^^^
12+
13+
error: demangling-alt(basic::main)
14+
--> $DIR/basic.rs:3:1
15+
|
16+
LL | #[rustc_symbol_name]
17+
| ^^^^^^^^^^^^^^^^^^^^
18+
719
error: def-path(main)
8-
--> $DIR/basic.rs:4:1
20+
--> $DIR/basic.rs:7:1
921
|
1022
LL | #[rustc_def_path]
1123
| ^^^^^^^^^^^^^^^^^
1224

13-
error: aborting due to 2 previous errors
25+
error: aborting due to 4 previous errors
1426

src/test/ui/symbol-names/impl1.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ mod foo {
55
pub struct Foo { x: u32 }
66

77
impl Foo {
8-
#[rustc_symbol_name] //~ ERROR _ZN5impl13foo3Foo3bar
8+
#[rustc_symbol_name]
9+
//~^ ERROR symbol-name(_ZN5impl13foo3Foo3bar
10+
//~| ERROR demangling(impl1::foo::Foo::bar
11+
//~| ERROR demangling-alt(impl1::foo::Foo::bar)
912
#[rustc_def_path] //~ ERROR def-path(foo::Foo::bar)
1013
fn bar() { }
1114
}
@@ -15,7 +18,10 @@ mod bar {
1518
use foo::Foo;
1619

1720
impl Foo {
18-
#[rustc_symbol_name] //~ ERROR _ZN5impl13bar33_$LT$impl$u20$impl1..foo..Foo$GT$3baz
21+
#[rustc_symbol_name]
22+
//~^ ERROR symbol-name(_ZN5impl13bar33_$LT$impl$u20$impl1..foo..Foo$GT$3baz
23+
//~| ERROR demangling(impl1::bar::<impl impl1::foo::Foo>::baz
24+
//~| ERROR demangling-alt(impl1::bar::<impl impl1::foo::Foo>::baz)
1925
#[rustc_def_path] //~ ERROR def-path(bar::<impl foo::Foo>::baz)
2026
fn baz() { }
2127
}

src/test/ui/symbol-names/impl1.stderr

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,47 @@ error: symbol-name(_ZN5impl13foo3Foo3bar17he53b9bee7600ed8dE)
44
LL | #[rustc_symbol_name]
55
| ^^^^^^^^^^^^^^^^^^^^
66

7+
error: demangling(impl1::foo::Foo::bar::he53b9bee7600ed8d)
8+
--> $DIR/impl1.rs:8:9
9+
|
10+
LL | #[rustc_symbol_name]
11+
| ^^^^^^^^^^^^^^^^^^^^
12+
13+
error: demangling-alt(impl1::foo::Foo::bar)
14+
--> $DIR/impl1.rs:8:9
15+
|
16+
LL | #[rustc_symbol_name]
17+
| ^^^^^^^^^^^^^^^^^^^^
18+
719
error: def-path(foo::Foo::bar)
8-
--> $DIR/impl1.rs:9:9
20+
--> $DIR/impl1.rs:12:9
921
|
1022
LL | #[rustc_def_path]
1123
| ^^^^^^^^^^^^^^^^^
1224

1325
error: symbol-name(_ZN5impl13bar33_$LT$impl$u20$impl1..foo..Foo$GT$3baz17h86c41f0462d901d4E)
14-
--> $DIR/impl1.rs:18:9
26+
--> $DIR/impl1.rs:21:9
27+
|
28+
LL | #[rustc_symbol_name]
29+
| ^^^^^^^^^^^^^^^^^^^^
30+
31+
error: demangling(impl1::bar::<impl impl1::foo::Foo>::baz::h86c41f0462d901d4)
32+
--> $DIR/impl1.rs:21:9
33+
|
34+
LL | #[rustc_symbol_name]
35+
| ^^^^^^^^^^^^^^^^^^^^
36+
37+
error: demangling-alt(impl1::bar::<impl impl1::foo::Foo>::baz)
38+
--> $DIR/impl1.rs:21:9
1539
|
1640
LL | #[rustc_symbol_name]
1741
| ^^^^^^^^^^^^^^^^^^^^
1842

1943
error: def-path(bar::<impl foo::Foo>::baz)
20-
--> $DIR/impl1.rs:19:9
44+
--> $DIR/impl1.rs:25:9
2145
|
2246
LL | #[rustc_def_path]
2347
| ^^^^^^^^^^^^^^^^^
2448

25-
error: aborting due to 4 previous errors
49+
error: aborting due to 8 previous errors
2650

src/test/ui/symbol-names/issue-60925.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ mod foo {
1414

1515
impl Foo<::llvm::Foo> {
1616
#[rustc_symbol_name]
17-
//~^ ERROR _ZN11issue_609253foo36Foo$LT$issue_60925..llv$6d$..Foo$GT$3foo17h059a991a004536adE
17+
//~^ ERROR symbol-name(_ZN11issue_609253foo36Foo$LT$issue_60925..llv$6d$..Foo$GT$3foo
18+
//~| ERROR demangling(issue_60925::foo::Foo<issue_60925::llv$6d$..Foo$GT$::foo
19+
//~| ERROR demangling-alt(issue_60925::foo::Foo<issue_60925::llv$6d$..Foo$GT$::foo)
1820
pub(crate) fn foo() {
1921
for _ in 0..0 {
2022
for _ in &[::dummy()] {

src/test/ui/symbol-names/issue-60925.stderr

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,17 @@ error: symbol-name(_ZN11issue_609253foo36Foo$LT$issue_60925..llv$6d$..Foo$GT$3fo
44
LL | #[rustc_symbol_name]
55
| ^^^^^^^^^^^^^^^^^^^^
66

7-
error: aborting due to previous error
7+
error: demangling(issue_60925::foo::Foo<issue_60925::llv$6d$..Foo$GT$::foo::h059a991a004536ad)
8+
--> $DIR/issue-60925.rs:16:9
9+
|
10+
LL | #[rustc_symbol_name]
11+
| ^^^^^^^^^^^^^^^^^^^^
12+
13+
error: demangling-alt(issue_60925::foo::Foo<issue_60925::llv$6d$..Foo$GT$::foo)
14+
--> $DIR/issue-60925.rs:16:9
15+
|
16+
LL | #[rustc_symbol_name]
17+
| ^^^^^^^^^^^^^^^^^^^^
18+
19+
error: aborting due to 3 previous errors
820

0 commit comments

Comments
 (0)