From 8668c1a19015148821c37255922f9a9b603dd148 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 5 Oct 2019 16:59:52 +0300 Subject: [PATCH] Add some more tests --- .../auxiliary/derive-helper-shadowing.rs | 15 ++++++ .../ui/proc-macro/derive-helper-shadowing.rs | 23 ++++++++ .../proc-macro/derive-helper-shadowing.stderr | 53 ++++++++++++++----- 3 files changed, 78 insertions(+), 13 deletions(-) create mode 100644 src/test/ui/proc-macro/auxiliary/derive-helper-shadowing.rs diff --git a/src/test/ui/proc-macro/auxiliary/derive-helper-shadowing.rs b/src/test/ui/proc-macro/auxiliary/derive-helper-shadowing.rs new file mode 100644 index 00000000000..41d3a184640 --- /dev/null +++ b/src/test/ui/proc-macro/auxiliary/derive-helper-shadowing.rs @@ -0,0 +1,15 @@ +// force-host +// no-prefer-dynamic + +#![crate_type = "proc-macro"] + +extern crate proc_macro; +use proc_macro::*; + +#[proc_macro_derive(GenHelperUse)] +pub fn derive_a(_: TokenStream) -> TokenStream { + " + #[empty_helper] + struct Uwu; + ".parse().unwrap() +} diff --git a/src/test/ui/proc-macro/derive-helper-shadowing.rs b/src/test/ui/proc-macro/derive-helper-shadowing.rs index fe324ae63cd..f0ca34db414 100644 --- a/src/test/ui/proc-macro/derive-helper-shadowing.rs +++ b/src/test/ui/proc-macro/derive-helper-shadowing.rs @@ -1,11 +1,21 @@ // edition:2018 // aux-build:test-macros.rs +// aux-build:derive-helper-shadowing.rs #[macro_use] extern crate test_macros; +#[macro_use] +extern crate derive_helper_shadowing; use test_macros::empty_attr as empty_helper; +macro_rules! gen_helper_use { + () => { + #[empty_helper] //~ ERROR cannot find attribute `empty_helper` in this scope + struct W; + } +} + #[empty_helper] //~ ERROR `empty_helper` is ambiguous #[derive(Empty)] struct S { @@ -20,12 +30,25 @@ mod inner { // OK, no ambiguity, the non-helper attribute is not in scope here, only the helper. #[empty_helper] struct V; + + gen_helper_use!(); + + #[derive(GenHelperUse)] //~ ERROR cannot find attribute `empty_helper` in this scope + struct Owo; + + use empty_helper as renamed; + #[renamed] //~ ERROR cannot use a derive helper attribute through an import + struct Wow; } 0 }] } +// OK, no ambiguity, only the non-helper attribute is in scope. +#[empty_helper] +struct Z; + fn main() { let s = S { field: [] }; } diff --git a/src/test/ui/proc-macro/derive-helper-shadowing.stderr b/src/test/ui/proc-macro/derive-helper-shadowing.stderr index 66ce34799da..9048830bee2 100644 --- a/src/test/ui/proc-macro/derive-helper-shadowing.stderr +++ b/src/test/ui/proc-macro/derive-helper-shadowing.stderr @@ -1,75 +1,102 @@ +error: cannot use a derive helper attribute through an import + --> $DIR/derive-helper-shadowing.rs:40:15 + | +LL | #[renamed] + | ^^^^^^^ + | +note: the derive helper attribute imported here + --> $DIR/derive-helper-shadowing.rs:39:17 + | +LL | use empty_helper as renamed; + | ^^^^^^^^^^^^^^^^^^^^^^^ + +error: cannot find attribute `empty_helper` in this scope + --> $DIR/derive-helper-shadowing.rs:36:22 + | +LL | #[derive(GenHelperUse)] + | ^^^^^^^^^^^^ + +error: cannot find attribute `empty_helper` in this scope + --> $DIR/derive-helper-shadowing.rs:14:11 + | +LL | #[empty_helper] + | ^^^^^^^^^^^^ +... +LL | gen_helper_use!(); + | ------------------ in this macro invocation + error[E0659]: `empty_helper` is ambiguous (name vs any other name during import resolution) - --> $DIR/derive-helper-shadowing.rs:14:13 + --> $DIR/derive-helper-shadowing.rs:24:13 | LL | use empty_helper; | ^^^^^^^^^^^^ ambiguous name | note: `empty_helper` could refer to the derive helper attribute defined here - --> $DIR/derive-helper-shadowing.rs:10:10 + --> $DIR/derive-helper-shadowing.rs:20:10 | LL | #[derive(Empty)] | ^^^^^ note: `empty_helper` could also refer to the attribute macro imported here - --> $DIR/derive-helper-shadowing.rs:7:5 + --> $DIR/derive-helper-shadowing.rs:10:5 | LL | use test_macros::empty_attr as empty_helper; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use `crate::empty_helper` to refer to this attribute macro unambiguously error[E0659]: `empty_helper` is ambiguous (derive helper attribute vs any other name) - --> $DIR/derive-helper-shadowing.rs:9:3 + --> $DIR/derive-helper-shadowing.rs:19:3 | LL | #[empty_helper] | ^^^^^^^^^^^^ ambiguous name | note: `empty_helper` could refer to the derive helper attribute defined here - --> $DIR/derive-helper-shadowing.rs:10:10 + --> $DIR/derive-helper-shadowing.rs:20:10 | LL | #[derive(Empty)] | ^^^^^ note: `empty_helper` could also refer to the attribute macro imported here - --> $DIR/derive-helper-shadowing.rs:7:5 + --> $DIR/derive-helper-shadowing.rs:10:5 | LL | use test_macros::empty_attr as empty_helper; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use `crate::empty_helper` to refer to this attribute macro unambiguously error[E0659]: `empty_helper` is ambiguous (derive helper attribute vs any other name) - --> $DIR/derive-helper-shadowing.rs:12:7 + --> $DIR/derive-helper-shadowing.rs:22:7 | LL | #[empty_helper] | ^^^^^^^^^^^^ ambiguous name | note: `empty_helper` could refer to the derive helper attribute defined here - --> $DIR/derive-helper-shadowing.rs:10:10 + --> $DIR/derive-helper-shadowing.rs:20:10 | LL | #[derive(Empty)] | ^^^^^ note: `empty_helper` could also refer to the attribute macro imported here - --> $DIR/derive-helper-shadowing.rs:7:5 + --> $DIR/derive-helper-shadowing.rs:10:5 | LL | use test_macros::empty_attr as empty_helper; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use `crate::empty_helper` to refer to this attribute macro unambiguously error[E0659]: `empty_helper` is ambiguous (derive helper attribute vs any other name) - --> $DIR/derive-helper-shadowing.rs:16:11 + --> $DIR/derive-helper-shadowing.rs:26:11 | LL | #[empty_helper] | ^^^^^^^^^^^^ ambiguous name | note: `empty_helper` could refer to the derive helper attribute defined here - --> $DIR/derive-helper-shadowing.rs:10:10 + --> $DIR/derive-helper-shadowing.rs:20:10 | LL | #[derive(Empty)] | ^^^^^ note: `empty_helper` could also refer to the attribute macro imported here - --> $DIR/derive-helper-shadowing.rs:7:5 + --> $DIR/derive-helper-shadowing.rs:10:5 | LL | use test_macros::empty_attr as empty_helper; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: use `crate::empty_helper` to refer to this attribute macro unambiguously -error: aborting due to 4 previous errors +error: aborting due to 7 previous errors For more information about this error, try `rustc --explain E0659`. -- 2.44.0