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), }, ]