Skip to content

Commit d8af6de

Browse files
committed
Address review comments
1 parent f6caae5 commit d8af6de

File tree

5 files changed

+52
-0
lines changed

5 files changed

+52
-0
lines changed

compiler/rustc_expand/src/base.rs

+3
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ impl Annotatable {
141141
}
142142

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

src/test/ui/derives/derive-renamed.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// check-pass
2+
// edition:2018
3+
4+
use derive as my_derive;
5+
6+
#[my_derive(Debug)]
7+
struct S;
8+
9+
fn main() {
10+
println!("{:?}", S); // OK
11+
}

src/test/ui/proc-macro/attribute-after-derive-feature-gate.rs

+9
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,13 @@ struct S3 {
2525
field: [u8; #[identity_attr] 10], //~ ERROR macro attributes in `#[derive]` output are unstable
2626
}
2727

28+
#[derive(Empty)]
29+
struct S4 {
30+
field: [u8; {
31+
#[derive(Empty)] // OK, not gated
32+
struct Inner;
33+
10
34+
}]
35+
}
36+
2837
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Support for legacy derive helpers is limited and heuristic-based
2+
// (that's exactly the reason why they are deprecated).
3+
4+
// edition:2018
5+
// aux-build:test-macros.rs
6+
7+
#[macro_use]
8+
extern crate test_macros;
9+
10+
use derive as my_derive;
11+
12+
#[my_derive(Empty)]
13+
#[empty_helper] // OK
14+
struct S1;
15+
16+
// Legacy helper detection doesn't see through `derive` renaming.
17+
#[empty_helper] //~ ERROR cannot find attribute `empty_helper` in this scope
18+
#[my_derive(Empty)]
19+
struct S2;
20+
21+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: cannot find attribute `empty_helper` in this scope
2+
--> $DIR/derive-helper-legacy-limits.rs:17:3
3+
|
4+
LL | #[empty_helper]
5+
| ^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)