Add some more tests

This commit is contained in:
Vadim Petrochenkov 2019-10-05 16:59:52 +03:00
parent 808522894b
commit 8668c1a190
3 changed files with 78 additions and 13 deletions

View File

@ -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()
}

View File

@ -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 @@ struct S {
// 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: [] };
}

View File

@ -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`.