Skip to content

Commit b4fcf1b

Browse files
committed
tests: add v0 structural const value demangling test.
1 parent af002c1 commit b4fcf1b

File tree

2 files changed

+257
-0
lines changed

2 files changed

+257
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// build-fail
2+
// compile-flags: -Z symbol-mangling-version=v0 --crate-name=c
3+
4+
// NOTE(eddyb) we need `core` for `core::option::Option`, normalize away its
5+
// disambiguator hash, which can/should change (including between stage{1,2}).
6+
// normalize-stderr-test: "Cs[0-9a-zA-Z]+_4core" -> "Cs$$HASH_4core"
7+
// normalize-stderr-test: "core\[[0-9a-f]+\]" -> "core[$$HASH_HEX]"
8+
9+
#![feature(const_generics, decl_macro, rustc_attrs)]
10+
#![allow(incomplete_features)]
11+
12+
pub struct RefByte<const RB: &'static u8>;
13+
14+
#[rustc_symbol_name]
15+
//~^ ERROR symbol-name(_RMCsno73SFvQKx_1cINtB0_7RefByteKRh7b_E)
16+
//~| ERROR demangling(<c[464da6a86cb672f]::RefByte<{&123u8}>>)
17+
//~| ERROR demangling-alt(<c::RefByte<{&123}>>)
18+
impl RefByte<{&123}> {}
19+
20+
// FIXME(eddyb) this was supposed to be `RefMutZst` with `&mut []`,
21+
// but that is currently not allowed in const generics.
22+
pub struct RefZst<const RMZ: &'static [u8; 0]>;
23+
24+
#[rustc_symbol_name]
25+
//~^ ERROR symbol-name(_RMs_Csno73SFvQKx_1cINtB2_6RefZstKRAEE)
26+
//~| ERROR demangling(<c[464da6a86cb672f]::RefZst<{&[]}>>)
27+
//~| ERROR demangling-alt(<c::RefZst<{&[]}>>)
28+
impl RefZst<{&[]}> {}
29+
30+
pub struct Array3Bytes<const A3B: [u8; 3]>;
31+
32+
#[rustc_symbol_name]
33+
//~^ ERROR symbol-name(_RMs0_Csno73SFvQKx_1cINtB3_11Array3BytesKAh1_h2_h3_EE)
34+
//~| ERROR demangling(<c[464da6a86cb672f]::Array3Bytes<{[1u8, 2u8, 3u8]}>>)
35+
//~| ERROR demangling-alt(<c::Array3Bytes<{[1, 2, 3]}>>)
36+
impl Array3Bytes<{[1, 2, 3]}> {}
37+
38+
pub struct TupleByteBool<const TBB: (u8, bool)>;
39+
40+
#[rustc_symbol_name]
41+
//~^ ERROR symbol-name(_RMs1_Csno73SFvQKx_1cINtB3_13TupleByteBoolKTh1_b0_EE)
42+
//~| ERROR demangling(<c[464da6a86cb672f]::TupleByteBool<{(1u8, false)}>>)
43+
//~| ERROR demangling-alt(<c::TupleByteBool<{(1, false)}>>)
44+
impl TupleByteBool<{(1, false)}> {}
45+
46+
pub struct OptionUsize<const OU: Option<usize>>;
47+
48+
// HACK(eddyb) the full mangling is only in `.stderr` because we can normalize
49+
// the `core` disambiguator hash away there, but not here.
50+
#[rustc_symbol_name]
51+
//~^ ERROR symbol-name(_RMs2_Csno73SFvQKx_1cINtB3_11OptionUsizeKVNtINtNtCs
52+
//~| ERROR demangling(<c[464da6a86cb672f]::OptionUsize<{core[
53+
//~| ERROR demangling-alt(<c::OptionUsize<{core::option::Option::<usize>::None}>>)
54+
impl OptionUsize<{None}> {}
55+
56+
// HACK(eddyb) the full mangling is only in `.stderr` because we can normalize
57+
// the `core` disambiguator hash away there, but not here.
58+
#[rustc_symbol_name]
59+
//~^ ERROR symbol-name(_RMs3_Csno73SFvQKx_1cINtB3_11OptionUsizeKVNtINtNtCs
60+
//~| ERROR demangling(<c[464da6a86cb672f]::OptionUsize<{core[
61+
//~| ERROR demangling-alt(<c::OptionUsize<{core::option::Option::<usize>::Some(0)}>>)
62+
impl OptionUsize<{Some(0)}> {}
63+
64+
#[derive(PartialEq, Eq)]
65+
pub struct Foo {
66+
s: &'static str,
67+
ch: char,
68+
slice: &'static [u8],
69+
}
70+
pub struct Foo_<const F: Foo>;
71+
72+
#[rustc_symbol_name]
73+
//~^ ERROR symbol-name(_RMs4_Csno73SFvQKx_1cINtB3_4Foo_KVNtB3_3FooS1sRe616263_2chc78_5sliceRAh1_h2_h3_EEE)
74+
//~| ERROR demangling(<c[464da6a86cb672f]::Foo_<{c[464da6a86cb672f]::Foo { s: "abc", ch: 'x', slice: &[1u8, 2u8, 3u8] }}>>)
75+
//~| ERROR demangling-alt(<c::Foo_<{c::Foo { s: "abc", ch: 'x', slice: &[1, 2, 3] }}>>)
76+
impl Foo_<{Foo { s: "abc", ch: 'x', slice: &[1, 2, 3] }}> {}
77+
78+
// NOTE(eddyb) this tests specifically the use of disambiguators in field names,
79+
// using macros 2.0 hygiene to create a `struct` with conflicting field names.
80+
macro duplicate_field_name_test($x:ident) {
81+
#[derive(PartialEq, Eq)]
82+
pub struct Bar {
83+
$x: u8,
84+
x: u16,
85+
}
86+
pub struct Bar_<const B: Bar>;
87+
88+
#[rustc_symbol_name]
89+
//~^ ERROR symbol-name(_RMs9_Csno73SFvQKx_1cINtB3_4Bar_KVNtB3_3BarS1xh7b_s_1xt1000_EE)
90+
//~| ERROR demangling(<c[464da6a86cb672f]::Bar_<{c[464da6a86cb672f]::Bar { x: 123u8, x: 4096u16 }}>>)
91+
//~| ERROR demangling-alt(<c::Bar_<{c::Bar { x: 123, x: 4096 }}>>)
92+
impl Bar_<{Bar { $x: 123, x: 4096 }}> {}
93+
}
94+
duplicate_field_name_test!(x);
95+
96+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
error: symbol-name(_RMCsno73SFvQKx_1cINtB0_7RefByteKRh7b_E)
2+
--> $DIR/const-generics-structural-demangling.rs:14:1
3+
|
4+
LL | #[rustc_symbol_name]
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
7+
error: demangling(<c[464da6a86cb672f]::RefByte<{&123u8}>>)
8+
--> $DIR/const-generics-structural-demangling.rs:14:1
9+
|
10+
LL | #[rustc_symbol_name]
11+
| ^^^^^^^^^^^^^^^^^^^^
12+
13+
error: demangling-alt(<c::RefByte<{&123}>>)
14+
--> $DIR/const-generics-structural-demangling.rs:14:1
15+
|
16+
LL | #[rustc_symbol_name]
17+
| ^^^^^^^^^^^^^^^^^^^^
18+
19+
error: symbol-name(_RMs_Csno73SFvQKx_1cINtB2_6RefZstKRAEE)
20+
--> $DIR/const-generics-structural-demangling.rs:24:1
21+
|
22+
LL | #[rustc_symbol_name]
23+
| ^^^^^^^^^^^^^^^^^^^^
24+
25+
error: demangling(<c[464da6a86cb672f]::RefZst<{&[]}>>)
26+
--> $DIR/const-generics-structural-demangling.rs:24:1
27+
|
28+
LL | #[rustc_symbol_name]
29+
| ^^^^^^^^^^^^^^^^^^^^
30+
31+
error: demangling-alt(<c::RefZst<{&[]}>>)
32+
--> $DIR/const-generics-structural-demangling.rs:24:1
33+
|
34+
LL | #[rustc_symbol_name]
35+
| ^^^^^^^^^^^^^^^^^^^^
36+
37+
error: symbol-name(_RMs0_Csno73SFvQKx_1cINtB3_11Array3BytesKAh1_h2_h3_EE)
38+
--> $DIR/const-generics-structural-demangling.rs:32:1
39+
|
40+
LL | #[rustc_symbol_name]
41+
| ^^^^^^^^^^^^^^^^^^^^
42+
43+
error: demangling(<c[464da6a86cb672f]::Array3Bytes<{[1u8, 2u8, 3u8]}>>)
44+
--> $DIR/const-generics-structural-demangling.rs:32:1
45+
|
46+
LL | #[rustc_symbol_name]
47+
| ^^^^^^^^^^^^^^^^^^^^
48+
49+
error: demangling-alt(<c::Array3Bytes<{[1, 2, 3]}>>)
50+
--> $DIR/const-generics-structural-demangling.rs:32:1
51+
|
52+
LL | #[rustc_symbol_name]
53+
| ^^^^^^^^^^^^^^^^^^^^
54+
55+
error: symbol-name(_RMs1_Csno73SFvQKx_1cINtB3_13TupleByteBoolKTh1_b0_EE)
56+
--> $DIR/const-generics-structural-demangling.rs:40:1
57+
|
58+
LL | #[rustc_symbol_name]
59+
| ^^^^^^^^^^^^^^^^^^^^
60+
61+
error: demangling(<c[464da6a86cb672f]::TupleByteBool<{(1u8, false)}>>)
62+
--> $DIR/const-generics-structural-demangling.rs:40:1
63+
|
64+
LL | #[rustc_symbol_name]
65+
| ^^^^^^^^^^^^^^^^^^^^
66+
67+
error: demangling-alt(<c::TupleByteBool<{(1, false)}>>)
68+
--> $DIR/const-generics-structural-demangling.rs:40:1
69+
|
70+
LL | #[rustc_symbol_name]
71+
| ^^^^^^^^^^^^^^^^^^^^
72+
73+
error: symbol-name(_RMs2_Csno73SFvQKx_1cINtB3_11OptionUsizeKVNtINtNtCs$HASH_4core6option6OptionjE4NoneUE)
74+
--> $DIR/const-generics-structural-demangling.rs:50:1
75+
|
76+
LL | #[rustc_symbol_name]
77+
| ^^^^^^^^^^^^^^^^^^^^
78+
79+
error: demangling(<c[464da6a86cb672f]::OptionUsize<{core[$HASH_HEX]::option::Option::<usize>::None}>>)
80+
--> $DIR/const-generics-structural-demangling.rs:50:1
81+
|
82+
LL | #[rustc_symbol_name]
83+
| ^^^^^^^^^^^^^^^^^^^^
84+
85+
error: demangling-alt(<c::OptionUsize<{core::option::Option::<usize>::None}>>)
86+
--> $DIR/const-generics-structural-demangling.rs:50:1
87+
|
88+
LL | #[rustc_symbol_name]
89+
| ^^^^^^^^^^^^^^^^^^^^
90+
91+
error: symbol-name(_RMs3_Csno73SFvQKx_1cINtB3_11OptionUsizeKVNtINtNtCs$HASH_4core6option6OptionjE4SomeTj0_EE)
92+
--> $DIR/const-generics-structural-demangling.rs:58:1
93+
|
94+
LL | #[rustc_symbol_name]
95+
| ^^^^^^^^^^^^^^^^^^^^
96+
97+
error: demangling(<c[464da6a86cb672f]::OptionUsize<{core[$HASH_HEX]::option::Option::<usize>::Some(0usize)}>>)
98+
--> $DIR/const-generics-structural-demangling.rs:58:1
99+
|
100+
LL | #[rustc_symbol_name]
101+
| ^^^^^^^^^^^^^^^^^^^^
102+
103+
error: demangling-alt(<c::OptionUsize<{core::option::Option::<usize>::Some(0)}>>)
104+
--> $DIR/const-generics-structural-demangling.rs:58:1
105+
|
106+
LL | #[rustc_symbol_name]
107+
| ^^^^^^^^^^^^^^^^^^^^
108+
109+
error: symbol-name(_RMs4_Csno73SFvQKx_1cINtB3_4Foo_KVNtB3_3FooS1sRe616263_2chc78_5sliceRAh1_h2_h3_EEE)
110+
--> $DIR/const-generics-structural-demangling.rs:72:1
111+
|
112+
LL | #[rustc_symbol_name]
113+
| ^^^^^^^^^^^^^^^^^^^^
114+
115+
error: demangling(<c[464da6a86cb672f]::Foo_<{c[464da6a86cb672f]::Foo { s: "abc", ch: 'x', slice: &[1u8, 2u8, 3u8] }}>>)
116+
--> $DIR/const-generics-structural-demangling.rs:72:1
117+
|
118+
LL | #[rustc_symbol_name]
119+
| ^^^^^^^^^^^^^^^^^^^^
120+
121+
error: demangling-alt(<c::Foo_<{c::Foo { s: "abc", ch: 'x', slice: &[1, 2, 3] }}>>)
122+
--> $DIR/const-generics-structural-demangling.rs:72:1
123+
|
124+
LL | #[rustc_symbol_name]
125+
| ^^^^^^^^^^^^^^^^^^^^
126+
127+
error: symbol-name(_RMs9_Csno73SFvQKx_1cINtB3_4Bar_KVNtB3_3BarS1xh7b_s_1xt1000_EE)
128+
--> $DIR/const-generics-structural-demangling.rs:88:5
129+
|
130+
LL | #[rustc_symbol_name]
131+
| ^^^^^^^^^^^^^^^^^^^^
132+
...
133+
LL | duplicate_field_name_test!(x);
134+
| ------------------------------ in this macro invocation
135+
|
136+
= note: this error originates in the macro `duplicate_field_name_test` (in Nightly builds, run with -Z macro-backtrace for more info)
137+
138+
error: demangling(<c[464da6a86cb672f]::Bar_<{c[464da6a86cb672f]::Bar { x: 123u8, x: 4096u16 }}>>)
139+
--> $DIR/const-generics-structural-demangling.rs:88:5
140+
|
141+
LL | #[rustc_symbol_name]
142+
| ^^^^^^^^^^^^^^^^^^^^
143+
...
144+
LL | duplicate_field_name_test!(x);
145+
| ------------------------------ in this macro invocation
146+
|
147+
= note: this error originates in the macro `duplicate_field_name_test` (in Nightly builds, run with -Z macro-backtrace for more info)
148+
149+
error: demangling-alt(<c::Bar_<{c::Bar { x: 123, x: 4096 }}>>)
150+
--> $DIR/const-generics-structural-demangling.rs:88:5
151+
|
152+
LL | #[rustc_symbol_name]
153+
| ^^^^^^^^^^^^^^^^^^^^
154+
...
155+
LL | duplicate_field_name_test!(x);
156+
| ------------------------------ in this macro invocation
157+
|
158+
= note: this error originates in the macro `duplicate_field_name_test` (in Nightly builds, run with -Z macro-backtrace for more info)
159+
160+
error: aborting due to 24 previous errors
161+

0 commit comments

Comments
 (0)