]> git.lizzy.rs Git - rust.git/blob - src/test/ui/symbol-names/const-generics-structural-demangling.rs
Rollup merge of #105555 - krasimirgg:llvm-int-opt-2, r=cuviper
[rust.git] / src / test / ui / symbol-names / const-generics-structural-demangling.rs
1 // build-fail
2 // compile-flags: -C 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: "core\[[0-9a-f]+\]" -> "core[HASH]"
7 // normalize-stderr-test: "c\[[0-9a-f]+\]" -> "c[HASH]"
8
9 #![feature(adt_const_params, 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
16 //~| ERROR demangling
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
26 //~| ERROR demangling
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
34 //~| ERROR demangling
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
42 //~| ERROR demangling
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
52 //~| ERROR demangling
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
60 //~| ERROR demangling
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
74 //~| ERROR demangling
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
90     //~| ERROR demangling
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() {}