resolve: Future proof derive helper attributes

This commit is contained in:
Vadim Petrochenkov 2018-09-13 05:11:13 +03:00
parent 1b6be5a1ca
commit 2b3e98f4e3
6 changed files with 117 additions and 38 deletions

View file

@ -0,0 +1,16 @@
// no-prefer-dynamic
#![crate_type = "proc-macro"]
extern crate proc_macro;
use proc_macro::*;
#[proc_macro_attribute]
pub fn my_attr(_: TokenStream, input: TokenStream) -> TokenStream {
input
}
#[proc_macro_derive(MyTrait, attributes(my_attr))]
pub fn derive(input: TokenStream) -> TokenStream {
TokenStream::new()
}

View file

@ -0,0 +1,12 @@
// no-prefer-dynamic
#![crate_type = "proc-macro"]
extern crate proc_macro;
use proc_macro::*;
#[proc_macro_derive(MyTrait, attributes(my_attr))]
pub fn foo(_: TokenStream) -> TokenStream {
TokenStream::new()
}

View file

@ -0,0 +1,10 @@
// aux-build:derive-helper-shadowing.rs
extern crate derive_helper_shadowing;
use derive_helper_shadowing::*;
#[derive(MyTrait)]
#[my_attr] //~ ERROR `my_attr` is ambiguous
struct S;
fn main() {}

View file

@ -0,0 +1,21 @@
error[E0659]: `my_attr` is ambiguous
--> $DIR/derive-helper-shadowing.rs:7:3
|
LL | #[my_attr] //~ ERROR `my_attr` is ambiguous
| ^^^^^^^ ambiguous name
|
note: `my_attr` could refer to the name imported here
--> $DIR/derive-helper-shadowing.rs:4:5
|
LL | use derive_helper_shadowing::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
note: `my_attr` could also refer to the name defined here
--> $DIR/derive-helper-shadowing.rs:6:10
|
LL | #[derive(MyTrait)]
| ^^^^^^^
= note: consider adding an explicit import of `my_attr` to disambiguate
error: aborting due to previous error
For more information about this error, try `rustc --explain E0659`.

View file

@ -0,0 +1,22 @@
// compile-pass
// aux-build:issue-53481.rs
#[macro_use]
extern crate issue_53481;
mod m1 {
use m2::MyTrait;
#[derive(MyTrait)]
struct A {}
}
mod m2 {
pub type MyTrait = u8;
#[derive(MyTrait)]
#[my_attr]
struct B {}
}
fn main() {}