-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolve: Future proof derive helper attributes
- Loading branch information
1 parent
1b6be5a
commit 2b3e98f
Showing
6 changed files
with
117 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/test/ui-fulldeps/proc-macro/auxiliary/derive-helper-shadowing.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} |
10 changes: 10 additions & 0 deletions
10
src/test/ui-fulldeps/proc-macro/derive-helper-shadowing.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
21 changes: 21 additions & 0 deletions
21
src/test/ui-fulldeps/proc-macro/derive-helper-shadowing.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |