diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2021-07-17 17:10:03 +0300 | 
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2021-09-24 21:45:51 +0300 | 
| commit | c993984e4d543e23474b50217f04df3fa7a38dcc (patch) | |
| tree | 475b5463579f6091b68b9b04bb2a6754827c1af0 | |
| parent | f06f9bbd3a2b0a2781decd6163b14f71dd59bf7f (diff) | |
| download | rust-c993984e4d543e23474b50217f04df3fa7a38dcc.tar.gz rust-c993984e4d543e23474b50217f04df3fa7a38dcc.zip | |
builtin_macros: Make #[derive(A, B, ...)] cfg-eval its input only for `A, B, ...`
| -rw-r--r-- | compiler/rustc_builtin_macros/src/derive.rs | 4 | ||||
| -rw-r--r-- | src/test/ui/proc-macro/attribute-after-derive.stdout | 48 | 
2 files changed, 48 insertions, 4 deletions
| diff --git a/compiler/rustc_builtin_macros/src/derive.rs b/compiler/rustc_builtin_macros/src/derive.rs index e0389f448eb..824776b45e2 100644 --- a/compiler/rustc_builtin_macros/src/derive.rs +++ b/compiler/rustc_builtin_macros/src/derive.rs @@ -26,7 +26,7 @@ impl MultiItemModifier for Expander { return ExpandResult::Ready(vec![item]); } - let item = cfg_eval(ecx, item); + let configured_item = cfg_eval(ecx, item.clone()); let result = ecx.resolver.resolve_derives(ecx.current_expansion.id, ecx.force_mode, &|| { @@ -56,7 +56,7 @@ impl MultiItemModifier for Expander { report_path_args(sess, &meta); meta.path }) - .map(|path| (path, item.clone(), None)) + .map(|path| (path, configured_item.clone(), None)) .collect() }); diff --git a/src/test/ui/proc-macro/attribute-after-derive.stdout b/src/test/ui/proc-macro/attribute-after-derive.stdout index 4c48e41ff33..bc8b001db8f 100644 --- a/src/test/ui/proc-macro/attribute-after-derive.stdout +++ b/src/test/ui/proc-macro/attribute-after-derive.stdout @@ -130,7 +130,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [ span: $DIR/attribute-after-derive.rs:25:24: 28:2 (#0), }, ] -PRINT-ATTR INPUT (DISPLAY): struct DeriveAttribute { } +PRINT-ATTR INPUT (DISPLAY): struct DeriveAttribute { #[cfg(FALSE)] field : u8, } PRINT-ATTR INPUT (DEBUG): TokenStream [ Ident { ident: "struct", @@ -142,7 +142,51 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [ }, Group { delimiter: Brace, - stream: TokenStream [], + stream: TokenStream [ + Punct { + ch: '#', + spacing: Alone, + span: $DIR/attribute-after-derive.rs:26:5: 26:6 (#0), + }, + Group { + delimiter: Bracket, + stream: TokenStream [ + Ident { + ident: "cfg", + span: $DIR/attribute-after-derive.rs:26:7: 26:10 (#0), + }, + Group { + delimiter: Parenthesis, + stream: TokenStream [ + Ident { + ident: "FALSE", + span: $DIR/attribute-after-derive.rs:26:11: 26:16 (#0), + }, + ], + span: $DIR/attribute-after-derive.rs:26:10: 26:17 (#0), + }, + ], + span: $DIR/attribute-after-derive.rs:26:6: 26:18 (#0), + }, + Ident { + ident: "field", + span: $DIR/attribute-after-derive.rs:27:5: 27:10 (#0), + }, + Punct { + ch: ':', + spacing: Alone, + span: $DIR/attribute-after-derive.rs:27:10: 27:11 (#0), + }, + Ident { + ident: "u8", + span: $DIR/attribute-after-derive.rs:27:12: 27:14 (#0), + }, + Punct { + ch: ',', + spacing: Alone, + span: $DIR/attribute-after-derive.rs:27:14: 27:15 (#0), + }, + ], span: $DIR/attribute-after-derive.rs:25:24: 28:2 (#0), }, ] | 
