From b4fcf1b1dc3d0533a7fa554482e99366f532056b Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Wed, 11 Aug 2021 01:13:31 +0300 Subject: [PATCH] tests: add v0 structural const value demangling test. --- .../const-generics-structural-demangling.rs | 96 +++++++++++ ...onst-generics-structural-demangling.stderr | 161 ++++++++++++++++++ 2 files changed, 257 insertions(+) create mode 100644 src/test/ui/symbol-names/const-generics-structural-demangling.rs create mode 100644 src/test/ui/symbol-names/const-generics-structural-demangling.stderr diff --git a/src/test/ui/symbol-names/const-generics-structural-demangling.rs b/src/test/ui/symbol-names/const-generics-structural-demangling.rs new file mode 100644 index 0000000000000..9da6a0f18e696 --- /dev/null +++ b/src/test/ui/symbol-names/const-generics-structural-demangling.rs @@ -0,0 +1,96 @@ +// build-fail +// compile-flags: -Z symbol-mangling-version=v0 --crate-name=c + +// NOTE(eddyb) we need `core` for `core::option::Option`, normalize away its +// disambiguator hash, which can/should change (including between stage{1,2}). +// normalize-stderr-test: "Cs[0-9a-zA-Z]+_4core" -> "Cs$$HASH_4core" +// normalize-stderr-test: "core\[[0-9a-f]+\]" -> "core[$$HASH_HEX]" + +#![feature(const_generics, decl_macro, rustc_attrs)] +#![allow(incomplete_features)] + +pub struct RefByte; + +#[rustc_symbol_name] +//~^ ERROR symbol-name(_RMCsno73SFvQKx_1cINtB0_7RefByteKRh7b_E) +//~| ERROR demangling(>) +//~| ERROR demangling-alt(>) +impl RefByte<{&123}> {} + +// FIXME(eddyb) this was supposed to be `RefMutZst` with `&mut []`, +// but that is currently not allowed in const generics. +pub struct RefZst; + +#[rustc_symbol_name] +//~^ ERROR symbol-name(_RMs_Csno73SFvQKx_1cINtB2_6RefZstKRAEE) +//~| ERROR demangling(>) +//~| ERROR demangling-alt(>) +impl RefZst<{&[]}> {} + +pub struct Array3Bytes; + +#[rustc_symbol_name] +//~^ ERROR symbol-name(_RMs0_Csno73SFvQKx_1cINtB3_11Array3BytesKAh1_h2_h3_EE) +//~| ERROR demangling(>) +//~| ERROR demangling-alt(>) +impl Array3Bytes<{[1, 2, 3]}> {} + +pub struct TupleByteBool; + +#[rustc_symbol_name] +//~^ ERROR symbol-name(_RMs1_Csno73SFvQKx_1cINtB3_13TupleByteBoolKTh1_b0_EE) +//~| ERROR demangling(>) +//~| ERROR demangling-alt(>) +impl TupleByteBool<{(1, false)}> {} + +pub struct OptionUsize>; + +// HACK(eddyb) the full mangling is only in `.stderr` because we can normalize +// the `core` disambiguator hash away there, but not here. +#[rustc_symbol_name] +//~^ ERROR symbol-name(_RMs2_Csno73SFvQKx_1cINtB3_11OptionUsizeKVNtINtNtCs +//~| ERROR demangling(::None}>>) +impl OptionUsize<{None}> {} + +// HACK(eddyb) the full mangling is only in `.stderr` because we can normalize +// the `core` disambiguator hash away there, but not here. +#[rustc_symbol_name] +//~^ ERROR symbol-name(_RMs3_Csno73SFvQKx_1cINtB3_11OptionUsizeKVNtINtNtCs +//~| ERROR demangling(::Some(0)}>>) +impl OptionUsize<{Some(0)}> {} + +#[derive(PartialEq, Eq)] +pub struct Foo { + s: &'static str, + ch: char, + slice: &'static [u8], +} +pub struct Foo_; + +#[rustc_symbol_name] +//~^ ERROR symbol-name(_RMs4_Csno73SFvQKx_1cINtB3_4Foo_KVNtB3_3FooS1sRe616263_2chc78_5sliceRAh1_h2_h3_EEE) +//~| ERROR demangling(>) +//~| ERROR demangling-alt(>) +impl Foo_<{Foo { s: "abc", ch: 'x', slice: &[1, 2, 3] }}> {} + +// NOTE(eddyb) this tests specifically the use of disambiguators in field names, +// using macros 2.0 hygiene to create a `struct` with conflicting field names. +macro duplicate_field_name_test($x:ident) { + #[derive(PartialEq, Eq)] + pub struct Bar { + $x: u8, + x: u16, + } + pub struct Bar_; + + #[rustc_symbol_name] + //~^ ERROR symbol-name(_RMs9_Csno73SFvQKx_1cINtB3_4Bar_KVNtB3_3BarS1xh7b_s_1xt1000_EE) + //~| ERROR demangling(>) + //~| ERROR demangling-alt(>) + impl Bar_<{Bar { $x: 123, x: 4096 }}> {} +} +duplicate_field_name_test!(x); + +fn main() {} diff --git a/src/test/ui/symbol-names/const-generics-structural-demangling.stderr b/src/test/ui/symbol-names/const-generics-structural-demangling.stderr new file mode 100644 index 0000000000000..b3c5bd2b89d30 --- /dev/null +++ b/src/test/ui/symbol-names/const-generics-structural-demangling.stderr @@ -0,0 +1,161 @@ +error: symbol-name(_RMCsno73SFvQKx_1cINtB0_7RefByteKRh7b_E) + --> $DIR/const-generics-structural-demangling.rs:14:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling(>) + --> $DIR/const-generics-structural-demangling.rs:14:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling-alt(>) + --> $DIR/const-generics-structural-demangling.rs:14:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: symbol-name(_RMs_Csno73SFvQKx_1cINtB2_6RefZstKRAEE) + --> $DIR/const-generics-structural-demangling.rs:24:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling(>) + --> $DIR/const-generics-structural-demangling.rs:24:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling-alt(>) + --> $DIR/const-generics-structural-demangling.rs:24:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: symbol-name(_RMs0_Csno73SFvQKx_1cINtB3_11Array3BytesKAh1_h2_h3_EE) + --> $DIR/const-generics-structural-demangling.rs:32:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling(>) + --> $DIR/const-generics-structural-demangling.rs:32:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling-alt(>) + --> $DIR/const-generics-structural-demangling.rs:32:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: symbol-name(_RMs1_Csno73SFvQKx_1cINtB3_13TupleByteBoolKTh1_b0_EE) + --> $DIR/const-generics-structural-demangling.rs:40:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling(>) + --> $DIR/const-generics-structural-demangling.rs:40:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling-alt(>) + --> $DIR/const-generics-structural-demangling.rs:40:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: symbol-name(_RMs2_Csno73SFvQKx_1cINtB3_11OptionUsizeKVNtINtNtCs$HASH_4core6option6OptionjE4NoneUE) + --> $DIR/const-generics-structural-demangling.rs:50:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling(::None}>>) + --> $DIR/const-generics-structural-demangling.rs:50:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling-alt(::None}>>) + --> $DIR/const-generics-structural-demangling.rs:50:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: symbol-name(_RMs3_Csno73SFvQKx_1cINtB3_11OptionUsizeKVNtINtNtCs$HASH_4core6option6OptionjE4SomeTj0_EE) + --> $DIR/const-generics-structural-demangling.rs:58:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling(::Some(0usize)}>>) + --> $DIR/const-generics-structural-demangling.rs:58:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling-alt(::Some(0)}>>) + --> $DIR/const-generics-structural-demangling.rs:58:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: symbol-name(_RMs4_Csno73SFvQKx_1cINtB3_4Foo_KVNtB3_3FooS1sRe616263_2chc78_5sliceRAh1_h2_h3_EEE) + --> $DIR/const-generics-structural-demangling.rs:72:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling(>) + --> $DIR/const-generics-structural-demangling.rs:72:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: demangling-alt(>) + --> $DIR/const-generics-structural-demangling.rs:72:1 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ + +error: symbol-name(_RMs9_Csno73SFvQKx_1cINtB3_4Bar_KVNtB3_3BarS1xh7b_s_1xt1000_EE) + --> $DIR/const-generics-structural-demangling.rs:88:5 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ +... +LL | duplicate_field_name_test!(x); + | ------------------------------ in this macro invocation + | + = note: this error originates in the macro `duplicate_field_name_test` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: demangling(>) + --> $DIR/const-generics-structural-demangling.rs:88:5 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ +... +LL | duplicate_field_name_test!(x); + | ------------------------------ in this macro invocation + | + = note: this error originates in the macro `duplicate_field_name_test` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: demangling-alt(>) + --> $DIR/const-generics-structural-demangling.rs:88:5 + | +LL | #[rustc_symbol_name] + | ^^^^^^^^^^^^^^^^^^^^ +... +LL | duplicate_field_name_test!(x); + | ------------------------------ in this macro invocation + | + = note: this error originates in the macro `duplicate_field_name_test` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 24 previous errors +