From 4d5ce340cd643cbb775728cfd223a7a4b5281bae Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 31 May 2020 00:04:57 +0300 Subject: [PATCH 1/2] test-macros: Avoid always producing errors in `#[derive(Print)]` --- .../ui/proc-macro/auxiliary/test-macros.rs | 3 +- src/test/ui/proc-macro/dollar-crate.rs | 5 ++-- src/test/ui/proc-macro/dollar-crate.stderr | 30 ------------------- 3 files changed, 5 insertions(+), 33 deletions(-) delete mode 100644 src/test/ui/proc-macro/dollar-crate.stderr diff --git a/src/test/ui/proc-macro/auxiliary/test-macros.rs b/src/test/ui/proc-macro/auxiliary/test-macros.rs index 27efa44f98032..fb8016cd43896 100644 --- a/src/test/ui/proc-macro/auxiliary/test-macros.rs +++ b/src/test/ui/proc-macro/auxiliary/test-macros.rs @@ -108,5 +108,6 @@ pub fn print_attr(_: TokenStream, input: TokenStream) -> TokenStream { #[proc_macro_derive(Print, attributes(print_helper))] pub fn print_derive(input: TokenStream) -> TokenStream { - print_helper(input, "DERIVE") + print_helper(input, "DERIVE"); + TokenStream::new() } diff --git a/src/test/ui/proc-macro/dollar-crate.rs b/src/test/ui/proc-macro/dollar-crate.rs index aadd87ffaf203..5f2549376d1ba 100644 --- a/src/test/ui/proc-macro/dollar-crate.rs +++ b/src/test/ui/proc-macro/dollar-crate.rs @@ -1,3 +1,4 @@ +// check-pass // edition:2018 // aux-build:test-macros.rs // aux-build:dollar-crate-external.rs @@ -23,7 +24,7 @@ mod local { struct A($crate::S); #[derive(Print)] - struct D($crate::S); //~ ERROR the name `D` is defined multiple times + struct D($crate::S); }; } @@ -33,7 +34,7 @@ mod local { mod external { use crate::dollar_crate_external; - dollar_crate_external::external!(); //~ ERROR the name `D` is defined multiple times + dollar_crate_external::external!(); } fn main() {} diff --git a/src/test/ui/proc-macro/dollar-crate.stderr b/src/test/ui/proc-macro/dollar-crate.stderr deleted file mode 100644 index 465f242580dfb..0000000000000 --- a/src/test/ui/proc-macro/dollar-crate.stderr +++ /dev/null @@ -1,30 +0,0 @@ -error[E0428]: the name `D` is defined multiple times - --> $DIR/dollar-crate.rs:26:13 - | -LL | struct D($crate::S); - | ^^^^^^^^^^^^^^^^^^^^ - | | - | `D` redefined here - | previous definition of the type `D` here -... -LL | local!(); - | --------- in this macro invocation - | - = note: `D` must be defined only once in the type namespace of this module - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0428]: the name `D` is defined multiple times - --> $DIR/dollar-crate.rs:36:5 - | -LL | dollar_crate_external::external!(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | `D` redefined here - | previous definition of the type `D` here - | - = note: `D` must be defined only once in the type namespace of this module - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0428`. From 81e06dac84fe073016befc2e860310fcd87715d6 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 31 May 2020 00:20:06 +0300 Subject: [PATCH 2/2] Add a test for `$:ident` in proc macro input --- src/test/ui/proc-macro/input-interpolated.rs | 25 +++++++ .../ui/proc-macro/input-interpolated.stdout | 69 +++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 src/test/ui/proc-macro/input-interpolated.rs create mode 100644 src/test/ui/proc-macro/input-interpolated.stdout diff --git a/src/test/ui/proc-macro/input-interpolated.rs b/src/test/ui/proc-macro/input-interpolated.rs new file mode 100644 index 0000000000000..b57ce99b13841 --- /dev/null +++ b/src/test/ui/proc-macro/input-interpolated.rs @@ -0,0 +1,25 @@ +// Check what token streams proc macros see when interpolated tokens are passed to them as input. + +// check-pass +// aux-build:test-macros.rs + +#[macro_use] +extern crate test_macros; + +macro_rules! pass_ident { + ($i:ident) => { + fn f() { + print_bang!($i); + } + + #[print_attr] + const $i: u8 = 0; + + #[derive(Print)] + struct $i {} + }; +} + +pass_ident!(A); + +fn main() {} diff --git a/src/test/ui/proc-macro/input-interpolated.stdout b/src/test/ui/proc-macro/input-interpolated.stdout new file mode 100644 index 0000000000000..7529db3bd06f8 --- /dev/null +++ b/src/test/ui/proc-macro/input-interpolated.stdout @@ -0,0 +1,69 @@ +PRINT-BANG INPUT (DISPLAY): A +PRINT-BANG RE-COLLECTED (DISPLAY): A +PRINT-BANG INPUT (DEBUG): TokenStream [ + Group { + delimiter: None, + stream: TokenStream [ + Ident { + ident: "A", + span: #0 bytes(402..403), + }, + ], + span: #3 bytes(269..271), + }, +] +PRINT-ATTR INPUT (DISPLAY): const A: u8 = 0; +PRINT-ATTR RE-COLLECTED (DISPLAY): const A : u8 = 0 ; +PRINT-ATTR INPUT (DEBUG): TokenStream [ + Ident { + ident: "const", + span: #0 bytes(0..0), + }, + Ident { + ident: "A", + span: #0 bytes(0..0), + }, + Punct { + ch: ':', + spacing: Alone, + span: #0 bytes(0..0), + }, + Ident { + ident: "u8", + span: #0 bytes(0..0), + }, + Punct { + ch: '=', + spacing: Alone, + span: #0 bytes(0..0), + }, + Literal { + kind: Integer, + symbol: "0", + suffix: None, + span: #0 bytes(0..0), + }, + Punct { + ch: ';', + spacing: Alone, + span: #0 bytes(0..0), + }, +] +PRINT-DERIVE INPUT (DISPLAY): struct A { +} +PRINT-DERIVE RE-COLLECTED (DISPLAY): struct A { } +PRINT-DERIVE INPUT (DEBUG): TokenStream [ + Ident { + ident: "struct", + span: #0 bytes(0..0), + }, + Ident { + ident: "A", + span: #0 bytes(0..0), + }, + Group { + delimiter: Brace, + stream: TokenStream [], + span: #0 bytes(0..0), + }, +]