Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Feb 7, 2021
1 parent f6caae5 commit d8af6de
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ impl Annotatable {
}

crate fn into_tokens(self, sess: &ParseSess) -> TokenStream {
// Tokens of an attribute target may be invalidated by some outer `#[derive]` performing
// "full configuration" (attributes following derives on the same item should be the most
// common case), that's why synthesizing tokens is allowed.
nt_to_tokenstream(&self.into_nonterminal(), sess, CanSynthesizeMissingTokens::Yes)
}

Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/derives/derive-renamed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// check-pass
// edition:2018

use derive as my_derive;

#[my_derive(Debug)]
struct S;

fn main() {
println!("{:?}", S); // OK
}
9 changes: 9 additions & 0 deletions src/test/ui/proc-macro/attribute-after-derive-feature-gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,13 @@ struct S3 {
field: [u8; #[identity_attr] 10], //~ ERROR macro attributes in `#[derive]` output are unstable
}

#[derive(Empty)]
struct S4 {
field: [u8; {
#[derive(Empty)] // OK, not gated
struct Inner;
10
}]
}

fn main() {}
21 changes: 21 additions & 0 deletions src/test/ui/proc-macro/derive-helper-legacy-limits.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Support for legacy derive helpers is limited and heuristic-based
// (that's exactly the reason why they are deprecated).

// edition:2018
// aux-build:test-macros.rs

#[macro_use]
extern crate test_macros;

use derive as my_derive;

#[my_derive(Empty)]
#[empty_helper] // OK
struct S1;

// Legacy helper detection doesn't see through `derive` renaming.
#[empty_helper] //~ ERROR cannot find attribute `empty_helper` in this scope
#[my_derive(Empty)]
struct S2;

fn main() {}
8 changes: 8 additions & 0 deletions src/test/ui/proc-macro/derive-helper-legacy-limits.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: cannot find attribute `empty_helper` in this scope
--> $DIR/derive-helper-legacy-limits.rs:17:3
|
LL | #[empty_helper]
| ^^^^^^^^^^^^

error: aborting due to previous error

0 comments on commit d8af6de

Please sign in to comment.