rust/src/test/ui/proc-macro/inner-attrs.stdout

957 lines
34 KiB
Plaintext
Raw Normal View History

2021-02-28 19:51:44 +00:00
PRINT-ATTR_ARGS INPUT (DISPLAY): first
PRINT-ATTR_ARGS INPUT (DEBUG): TokenStream [
Ident {
ident: "first",
span: $DIR/inner-attrs.rs:16:25: 16:30 (#0),
2021-02-28 19:51:44 +00:00
},
]
PRINT-ATTR INPUT (DISPLAY): #[print_target_and_args(second)] fn foo()
{ #! [print_target_and_args(third)] #! [print_target_and_args(fourth)] }
2021-02-28 19:51:44 +00:00
PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
ch: '#',
spacing: Alone,
span: $DIR/inner-attrs.rs:17:1: 17:2 (#0),
2021-02-28 19:51:44 +00:00
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "print_target_and_args",
span: $DIR/inner-attrs.rs:17:3: 17:24 (#0),
2021-02-28 19:51:44 +00:00
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "second",
span: $DIR/inner-attrs.rs:17:25: 17:31 (#0),
2021-02-28 19:51:44 +00:00
},
],
span: $DIR/inner-attrs.rs:17:24: 17:32 (#0),
2021-02-28 19:51:44 +00:00
},
],
span: $DIR/inner-attrs.rs:17:2: 17:33 (#0),
2021-02-28 19:51:44 +00:00
},
Ident {
ident: "fn",
span: $DIR/inner-attrs.rs:18:1: 18:3 (#0),
2021-02-28 19:51:44 +00:00
},
Ident {
ident: "foo",
span: $DIR/inner-attrs.rs:18:4: 18:7 (#0),
2021-02-28 19:51:44 +00:00
},
Group {
delimiter: Parenthesis,
stream: TokenStream [],
span: $DIR/inner-attrs.rs:18:7: 18:9 (#0),
2021-02-28 19:51:44 +00:00
},
Group {
delimiter: Brace,
stream: TokenStream [
Punct {
ch: '#',
spacing: Joint,
span: $DIR/inner-attrs.rs:19:5: 19:6 (#0),
2021-02-28 19:51:44 +00:00
},
Punct {
ch: '!',
spacing: Alone,
span: $DIR/inner-attrs.rs:19:6: 19:7 (#0),
2021-02-28 19:51:44 +00:00
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "print_target_and_args",
span: $DIR/inner-attrs.rs:19:8: 19:29 (#0),
2021-02-28 19:51:44 +00:00
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "third",
span: $DIR/inner-attrs.rs:19:30: 19:35 (#0),
2021-02-28 19:51:44 +00:00
},
],
span: $DIR/inner-attrs.rs:19:29: 19:36 (#0),
2021-02-28 19:51:44 +00:00
},
],
span: $DIR/inner-attrs.rs:19:7: 19:37 (#0),
2021-02-28 19:51:44 +00:00
},
Punct {
ch: '#',
spacing: Joint,
span: $DIR/inner-attrs.rs:20:5: 20:6 (#0),
2021-02-28 19:51:44 +00:00
},
Punct {
ch: '!',
spacing: Alone,
span: $DIR/inner-attrs.rs:20:6: 20:7 (#0),
2021-02-28 19:51:44 +00:00
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "print_target_and_args",
span: $DIR/inner-attrs.rs:20:8: 20:29 (#0),
2021-02-28 19:51:44 +00:00
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "fourth",
span: $DIR/inner-attrs.rs:20:30: 20:36 (#0),
2021-02-28 19:51:44 +00:00
},
],
span: $DIR/inner-attrs.rs:20:29: 20:37 (#0),
2021-02-28 19:51:44 +00:00
},
],
span: $DIR/inner-attrs.rs:20:7: 20:38 (#0),
2021-02-28 19:51:44 +00:00
},
],
span: $DIR/inner-attrs.rs:18:10: 21:2 (#0),
2021-02-28 19:51:44 +00:00
},
]
PRINT-ATTR_ARGS INPUT (DISPLAY): second
PRINT-ATTR_ARGS INPUT (DEBUG): TokenStream [
Ident {
ident: "second",
span: $DIR/inner-attrs.rs:17:25: 17:31 (#0),
2021-02-28 19:51:44 +00:00
},
]
PRINT-ATTR INPUT (DISPLAY): fn foo()
{ #! [print_target_and_args(third)] #! [print_target_and_args(fourth)] }
2021-02-28 19:51:44 +00:00
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "fn",
span: $DIR/inner-attrs.rs:18:1: 18:3 (#0),
2021-02-28 19:51:44 +00:00
},
Ident {
ident: "foo",
span: $DIR/inner-attrs.rs:18:4: 18:7 (#0),
2021-02-28 19:51:44 +00:00
},
Group {
delimiter: Parenthesis,
stream: TokenStream [],
span: $DIR/inner-attrs.rs:18:7: 18:9 (#0),
2021-02-28 19:51:44 +00:00
},
Group {
delimiter: Brace,
stream: TokenStream [
Punct {
ch: '#',
spacing: Joint,
span: $DIR/inner-attrs.rs:19:5: 19:6 (#0),
2021-02-28 19:51:44 +00:00
},
Punct {
ch: '!',
spacing: Alone,
span: $DIR/inner-attrs.rs:19:6: 19:7 (#0),
2021-02-28 19:51:44 +00:00
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "print_target_and_args",
span: $DIR/inner-attrs.rs:19:8: 19:29 (#0),
2021-02-28 19:51:44 +00:00
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "third",
span: $DIR/inner-attrs.rs:19:30: 19:35 (#0),
2021-02-28 19:51:44 +00:00
},
],
span: $DIR/inner-attrs.rs:19:29: 19:36 (#0),
2021-02-28 19:51:44 +00:00
},
],
span: $DIR/inner-attrs.rs:19:7: 19:37 (#0),
2021-02-28 19:51:44 +00:00
},
Punct {
ch: '#',
spacing: Joint,
span: $DIR/inner-attrs.rs:20:5: 20:6 (#0),
2021-02-28 19:51:44 +00:00
},
Punct {
ch: '!',
spacing: Alone,
span: $DIR/inner-attrs.rs:20:6: 20:7 (#0),
2021-02-28 19:51:44 +00:00
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "print_target_and_args",
span: $DIR/inner-attrs.rs:20:8: 20:29 (#0),
2021-02-28 19:51:44 +00:00
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "fourth",
span: $DIR/inner-attrs.rs:20:30: 20:36 (#0),
2021-02-28 19:51:44 +00:00
},
],
span: $DIR/inner-attrs.rs:20:29: 20:37 (#0),
2021-02-28 19:51:44 +00:00
},
],
span: $DIR/inner-attrs.rs:20:7: 20:38 (#0),
2021-02-28 19:51:44 +00:00
},
],
span: $DIR/inner-attrs.rs:18:10: 21:2 (#0),
2021-02-28 19:51:44 +00:00
},
]
PRINT-ATTR_ARGS INPUT (DISPLAY): third
PRINT-ATTR_ARGS INPUT (DEBUG): TokenStream [
Ident {
ident: "third",
span: $DIR/inner-attrs.rs:19:30: 19:35 (#0),
2021-02-28 19:51:44 +00:00
},
]
PRINT-ATTR INPUT (DISPLAY): fn foo() { #! [print_target_and_args(fourth)] }
2021-02-28 19:51:44 +00:00
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "fn",
span: $DIR/inner-attrs.rs:18:1: 18:3 (#0),
2021-02-28 19:51:44 +00:00
},
Ident {
ident: "foo",
span: $DIR/inner-attrs.rs:18:4: 18:7 (#0),
2021-02-28 19:51:44 +00:00
},
Group {
delimiter: Parenthesis,
stream: TokenStream [],
span: $DIR/inner-attrs.rs:18:7: 18:9 (#0),
2021-02-28 19:51:44 +00:00
},
Group {
delimiter: Brace,
stream: TokenStream [
Punct {
ch: '#',
spacing: Joint,
span: $DIR/inner-attrs.rs:20:5: 20:6 (#0),
2021-02-28 19:51:44 +00:00
},
Punct {
ch: '!',
spacing: Alone,
span: $DIR/inner-attrs.rs:20:6: 20:7 (#0),
2021-02-28 19:51:44 +00:00
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "print_target_and_args",
span: $DIR/inner-attrs.rs:20:8: 20:29 (#0),
2021-02-28 19:51:44 +00:00
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "fourth",
span: $DIR/inner-attrs.rs:20:30: 20:36 (#0),
2021-02-28 19:51:44 +00:00
},
],
span: $DIR/inner-attrs.rs:20:29: 20:37 (#0),
2021-02-28 19:51:44 +00:00
},
],
span: $DIR/inner-attrs.rs:20:7: 20:38 (#0),
2021-02-28 19:51:44 +00:00
},
],
span: $DIR/inner-attrs.rs:18:10: 21:2 (#0),
2021-02-28 19:51:44 +00:00
},
]
PRINT-ATTR_ARGS INPUT (DISPLAY): fourth
PRINT-ATTR_ARGS INPUT (DEBUG): TokenStream [
Ident {
ident: "fourth",
span: $DIR/inner-attrs.rs:20:30: 20:36 (#0),
2021-02-28 19:51:44 +00:00
},
]
PRINT-ATTR INPUT (DISPLAY): fn foo() { }
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "fn",
span: $DIR/inner-attrs.rs:18:1: 18:3 (#0),
2021-02-28 19:51:44 +00:00
},
Ident {
ident: "foo",
span: $DIR/inner-attrs.rs:18:4: 18:7 (#0),
2021-02-28 19:51:44 +00:00
},
Group {
delimiter: Parenthesis,
stream: TokenStream [],
span: $DIR/inner-attrs.rs:18:7: 18:9 (#0),
2021-02-28 19:51:44 +00:00
},
Group {
delimiter: Brace,
stream: TokenStream [],
span: $DIR/inner-attrs.rs:18:10: 21:2 (#0),
2021-02-28 19:51:44 +00:00
},
]
PRINT-ATTR_ARGS INPUT (DISPLAY): mod_first
PRINT-ATTR_ARGS INPUT (DEBUG): TokenStream [
Ident {
ident: "mod_first",
span: $DIR/inner-attrs.rs:23:25: 23:34 (#0),
},
]
PRINT-ATTR INPUT (DISPLAY): #[print_target_and_args(mod_second)] mod inline_mod
{
#! [print_target_and_args(mod_third)] #!
[print_target_and_args(mod_fourth)]
}
PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
ch: '#',
spacing: Alone,
span: $DIR/inner-attrs.rs:24:1: 24:2 (#0),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "print_target_and_args",
span: $DIR/inner-attrs.rs:24:3: 24:24 (#0),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "mod_second",
span: $DIR/inner-attrs.rs:24:25: 24:35 (#0),
},
],
span: $DIR/inner-attrs.rs:24:24: 24:36 (#0),
},
],
span: $DIR/inner-attrs.rs:24:2: 24:37 (#0),
},
Ident {
ident: "mod",
span: $DIR/inner-attrs.rs:25:1: 25:4 (#0),
},
Ident {
ident: "inline_mod",
span: $DIR/inner-attrs.rs:25:5: 25:15 (#0),
},
Group {
delimiter: Brace,
stream: TokenStream [
Punct {
ch: '#',
spacing: Joint,
span: $DIR/inner-attrs.rs:26:5: 26:6 (#0),
},
Punct {
ch: '!',
spacing: Alone,
span: $DIR/inner-attrs.rs:26:6: 26:7 (#0),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "print_target_and_args",
span: $DIR/inner-attrs.rs:26:8: 26:29 (#0),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "mod_third",
span: $DIR/inner-attrs.rs:26:30: 26:39 (#0),
},
],
span: $DIR/inner-attrs.rs:26:29: 26:40 (#0),
},
],
span: $DIR/inner-attrs.rs:26:7: 26:41 (#0),
},
Punct {
ch: '#',
spacing: Joint,
span: $DIR/inner-attrs.rs:27:5: 27:6 (#0),
},
Punct {
ch: '!',
spacing: Alone,
span: $DIR/inner-attrs.rs:27:6: 27:7 (#0),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "print_target_and_args",
span: $DIR/inner-attrs.rs:27:8: 27:29 (#0),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "mod_fourth",
span: $DIR/inner-attrs.rs:27:30: 27:40 (#0),
},
],
span: $DIR/inner-attrs.rs:27:29: 27:41 (#0),
},
],
span: $DIR/inner-attrs.rs:27:7: 27:42 (#0),
},
],
span: $DIR/inner-attrs.rs:25:16: 28:2 (#0),
},
]
PRINT-ATTR_ARGS INPUT (DISPLAY): mod_second
PRINT-ATTR_ARGS INPUT (DEBUG): TokenStream [
Ident {
ident: "mod_second",
span: $DIR/inner-attrs.rs:24:25: 24:35 (#0),
},
]
PRINT-ATTR INPUT (DISPLAY): mod inline_mod
{
#! [print_target_and_args(mod_third)] #!
[print_target_and_args(mod_fourth)]
}
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "mod",
span: $DIR/inner-attrs.rs:25:1: 25:4 (#0),
},
Ident {
ident: "inline_mod",
span: $DIR/inner-attrs.rs:25:5: 25:15 (#0),
},
Group {
delimiter: Brace,
stream: TokenStream [
Punct {
ch: '#',
spacing: Joint,
span: $DIR/inner-attrs.rs:26:5: 26:6 (#0),
},
Punct {
ch: '!',
spacing: Alone,
span: $DIR/inner-attrs.rs:26:6: 26:7 (#0),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "print_target_and_args",
span: $DIR/inner-attrs.rs:26:8: 26:29 (#0),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "mod_third",
span: $DIR/inner-attrs.rs:26:30: 26:39 (#0),
},
],
span: $DIR/inner-attrs.rs:26:29: 26:40 (#0),
},
],
span: $DIR/inner-attrs.rs:26:7: 26:41 (#0),
},
Punct {
ch: '#',
spacing: Joint,
span: $DIR/inner-attrs.rs:27:5: 27:6 (#0),
},
Punct {
ch: '!',
spacing: Alone,
span: $DIR/inner-attrs.rs:27:6: 27:7 (#0),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "print_target_and_args",
span: $DIR/inner-attrs.rs:27:8: 27:29 (#0),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "mod_fourth",
span: $DIR/inner-attrs.rs:27:30: 27:40 (#0),
},
],
span: $DIR/inner-attrs.rs:27:29: 27:41 (#0),
},
],
span: $DIR/inner-attrs.rs:27:7: 27:42 (#0),
},
],
span: $DIR/inner-attrs.rs:25:16: 28:2 (#0),
},
]
PRINT-ATTR_ARGS INPUT (DISPLAY): mod_third
PRINT-ATTR_ARGS INPUT (DEBUG): TokenStream [
Ident {
ident: "mod_third",
span: $DIR/inner-attrs.rs:26:30: 26:39 (#0),
},
]
PRINT-ATTR INPUT (DISPLAY): mod inline_mod { #! [print_target_and_args(mod_fourth)] }
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "mod",
span: $DIR/inner-attrs.rs:25:1: 25:4 (#0),
},
Ident {
ident: "inline_mod",
span: $DIR/inner-attrs.rs:25:5: 25:15 (#0),
},
Group {
delimiter: Brace,
stream: TokenStream [
Punct {
ch: '#',
spacing: Joint,
span: $DIR/inner-attrs.rs:27:5: 27:6 (#0),
},
Punct {
ch: '!',
spacing: Alone,
span: $DIR/inner-attrs.rs:27:6: 27:7 (#0),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "print_target_and_args",
span: $DIR/inner-attrs.rs:27:8: 27:29 (#0),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "mod_fourth",
span: $DIR/inner-attrs.rs:27:30: 27:40 (#0),
},
],
span: $DIR/inner-attrs.rs:27:29: 27:41 (#0),
},
],
span: $DIR/inner-attrs.rs:27:7: 27:42 (#0),
},
],
span: $DIR/inner-attrs.rs:25:16: 28:2 (#0),
},
]
PRINT-ATTR_ARGS INPUT (DISPLAY): mod_fourth
PRINT-ATTR_ARGS INPUT (DEBUG): TokenStream [
Ident {
ident: "mod_fourth",
span: $DIR/inner-attrs.rs:27:30: 27:40 (#0),
},
]
PRINT-ATTR INPUT (DISPLAY): mod inline_mod { }
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "mod",
span: $DIR/inner-attrs.rs:25:1: 25:4 (#0),
},
Ident {
ident: "inline_mod",
span: $DIR/inner-attrs.rs:25:5: 25:15 (#0),
},
Group {
delimiter: Brace,
stream: TokenStream [],
span: $DIR/inner-attrs.rs:25:16: 28:2 (#0),
},
]
PRINT-DERIVE INPUT (DISPLAY): struct MyDerivePrint
{
field :
[u8 ; { match true { _ => { #! [rustc_dummy(third)] true } } ; 0 }]
}
PRINT-DERIVE INPUT (DEBUG): TokenStream [
Ident {
ident: "struct",
span: $DIR/inner-attrs.rs:35:1: 35:7 (#0),
},
Ident {
ident: "MyDerivePrint",
span: $DIR/inner-attrs.rs:35:8: 35:21 (#0),
},
Group {
delimiter: Brace,
stream: TokenStream [
Ident {
ident: "field",
span: $DIR/inner-attrs.rs:36:5: 36:10 (#0),
},
Punct {
ch: ':',
spacing: Alone,
span: $DIR/inner-attrs.rs:36:10: 36:11 (#0),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "u8",
span: $DIR/inner-attrs.rs:36:13: 36:15 (#0),
},
Punct {
ch: ';',
spacing: Alone,
span: $DIR/inner-attrs.rs:36:15: 36:16 (#0),
},
Group {
delimiter: Brace,
stream: TokenStream [
Ident {
ident: "match",
span: $DIR/inner-attrs.rs:37:9: 37:14 (#0),
},
Ident {
ident: "true",
span: $DIR/inner-attrs.rs:37:15: 37:19 (#0),
},
Group {
delimiter: Brace,
stream: TokenStream [
Ident {
ident: "_",
span: $DIR/inner-attrs.rs:38:13: 38:14 (#0),
},
Punct {
ch: '=',
spacing: Joint,
span: $DIR/inner-attrs.rs:38:15: 38:17 (#0),
},
Punct {
ch: '>',
spacing: Alone,
span: $DIR/inner-attrs.rs:38:15: 38:17 (#0),
},
Group {
delimiter: Brace,
stream: TokenStream [
Implement token-based handling of attributes during expansion This PR modifies the macro expansion infrastructure to handle attributes in a fully token-based manner. As a result: * Derives macros no longer lose spans when their input is modified by eager cfg-expansion. This is accomplished by performing eager cfg-expansion on the token stream that we pass to the derive proc-macro * Inner attributes now preserve spans in all cases, including when we have multiple inner attributes in a row. This is accomplished through the following changes: * New structs `AttrAnnotatedTokenStream` and `AttrAnnotatedTokenTree` are introduced. These are very similar to a normal `TokenTree`, but they also track the position of attributes and attribute targets within the stream. They are built when we collect tokens during parsing. An `AttrAnnotatedTokenStream` is converted to a regular `TokenStream` when we invoke a macro. * Token capturing and `LazyTokenStream` are modified to work with `AttrAnnotatedTokenStream`. A new `ReplaceRange` type is introduced, which is created during the parsing of a nested AST node to make the 'outer' AST node aware of the attributes and attribute target stored deeper in the token stream. * When we need to perform eager cfg-expansion (either due to `#[derive]` or `#[cfg_eval]`), we tokenize and reparse our target, capturing additional information about the locations of `#[cfg]` and `#[cfg_attr]` attributes at any depth within the target. This is a performance optimization, allowing us to perform less work in the typical case where captured tokens never have eager cfg-expansion run.
2020-11-28 23:33:17 +00:00
Punct {
ch: '#',
spacing: Alone,
span: $DIR/inner-attrs.rs:39:17: 39:18 (#0),
Implement token-based handling of attributes during expansion This PR modifies the macro expansion infrastructure to handle attributes in a fully token-based manner. As a result: * Derives macros no longer lose spans when their input is modified by eager cfg-expansion. This is accomplished by performing eager cfg-expansion on the token stream that we pass to the derive proc-macro * Inner attributes now preserve spans in all cases, including when we have multiple inner attributes in a row. This is accomplished through the following changes: * New structs `AttrAnnotatedTokenStream` and `AttrAnnotatedTokenTree` are introduced. These are very similar to a normal `TokenTree`, but they also track the position of attributes and attribute targets within the stream. They are built when we collect tokens during parsing. An `AttrAnnotatedTokenStream` is converted to a regular `TokenStream` when we invoke a macro. * Token capturing and `LazyTokenStream` are modified to work with `AttrAnnotatedTokenStream`. A new `ReplaceRange` type is introduced, which is created during the parsing of a nested AST node to make the 'outer' AST node aware of the attributes and attribute target stored deeper in the token stream. * When we need to perform eager cfg-expansion (either due to `#[derive]` or `#[cfg_eval]`), we tokenize and reparse our target, capturing additional information about the locations of `#[cfg]` and `#[cfg_attr]` attributes at any depth within the target. This is a performance optimization, allowing us to perform less work in the typical case where captured tokens never have eager cfg-expansion run.
2020-11-28 23:33:17 +00:00
},
Punct {
ch: '!',
spacing: Alone,
span: $DIR/inner-attrs.rs:39:18: 39:19 (#0),
Implement token-based handling of attributes during expansion This PR modifies the macro expansion infrastructure to handle attributes in a fully token-based manner. As a result: * Derives macros no longer lose spans when their input is modified by eager cfg-expansion. This is accomplished by performing eager cfg-expansion on the token stream that we pass to the derive proc-macro * Inner attributes now preserve spans in all cases, including when we have multiple inner attributes in a row. This is accomplished through the following changes: * New structs `AttrAnnotatedTokenStream` and `AttrAnnotatedTokenTree` are introduced. These are very similar to a normal `TokenTree`, but they also track the position of attributes and attribute targets within the stream. They are built when we collect tokens during parsing. An `AttrAnnotatedTokenStream` is converted to a regular `TokenStream` when we invoke a macro. * Token capturing and `LazyTokenStream` are modified to work with `AttrAnnotatedTokenStream`. A new `ReplaceRange` type is introduced, which is created during the parsing of a nested AST node to make the 'outer' AST node aware of the attributes and attribute target stored deeper in the token stream. * When we need to perform eager cfg-expansion (either due to `#[derive]` or `#[cfg_eval]`), we tokenize and reparse our target, capturing additional information about the locations of `#[cfg]` and `#[cfg_attr]` attributes at any depth within the target. This is a performance optimization, allowing us to perform less work in the typical case where captured tokens never have eager cfg-expansion run.
2020-11-28 23:33:17 +00:00
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "rustc_dummy",
span: $DIR/inner-attrs.rs:39:41: 39:52 (#0),
Implement token-based handling of attributes during expansion This PR modifies the macro expansion infrastructure to handle attributes in a fully token-based manner. As a result: * Derives macros no longer lose spans when their input is modified by eager cfg-expansion. This is accomplished by performing eager cfg-expansion on the token stream that we pass to the derive proc-macro * Inner attributes now preserve spans in all cases, including when we have multiple inner attributes in a row. This is accomplished through the following changes: * New structs `AttrAnnotatedTokenStream` and `AttrAnnotatedTokenTree` are introduced. These are very similar to a normal `TokenTree`, but they also track the position of attributes and attribute targets within the stream. They are built when we collect tokens during parsing. An `AttrAnnotatedTokenStream` is converted to a regular `TokenStream` when we invoke a macro. * Token capturing and `LazyTokenStream` are modified to work with `AttrAnnotatedTokenStream`. A new `ReplaceRange` type is introduced, which is created during the parsing of a nested AST node to make the 'outer' AST node aware of the attributes and attribute target stored deeper in the token stream. * When we need to perform eager cfg-expansion (either due to `#[derive]` or `#[cfg_eval]`), we tokenize and reparse our target, capturing additional information about the locations of `#[cfg]` and `#[cfg_attr]` attributes at any depth within the target. This is a performance optimization, allowing us to perform less work in the typical case where captured tokens never have eager cfg-expansion run.
2020-11-28 23:33:17 +00:00
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "third",
span: $DIR/inner-attrs.rs:39:53: 39:58 (#0),
Implement token-based handling of attributes during expansion This PR modifies the macro expansion infrastructure to handle attributes in a fully token-based manner. As a result: * Derives macros no longer lose spans when their input is modified by eager cfg-expansion. This is accomplished by performing eager cfg-expansion on the token stream that we pass to the derive proc-macro * Inner attributes now preserve spans in all cases, including when we have multiple inner attributes in a row. This is accomplished through the following changes: * New structs `AttrAnnotatedTokenStream` and `AttrAnnotatedTokenTree` are introduced. These are very similar to a normal `TokenTree`, but they also track the position of attributes and attribute targets within the stream. They are built when we collect tokens during parsing. An `AttrAnnotatedTokenStream` is converted to a regular `TokenStream` when we invoke a macro. * Token capturing and `LazyTokenStream` are modified to work with `AttrAnnotatedTokenStream`. A new `ReplaceRange` type is introduced, which is created during the parsing of a nested AST node to make the 'outer' AST node aware of the attributes and attribute target stored deeper in the token stream. * When we need to perform eager cfg-expansion (either due to `#[derive]` or `#[cfg_eval]`), we tokenize and reparse our target, capturing additional information about the locations of `#[cfg]` and `#[cfg_attr]` attributes at any depth within the target. This is a performance optimization, allowing us to perform less work in the typical case where captured tokens never have eager cfg-expansion run.
2020-11-28 23:33:17 +00:00
},
],
span: $DIR/inner-attrs.rs:39:52: 39:59 (#0),
Implement token-based handling of attributes during expansion This PR modifies the macro expansion infrastructure to handle attributes in a fully token-based manner. As a result: * Derives macros no longer lose spans when their input is modified by eager cfg-expansion. This is accomplished by performing eager cfg-expansion on the token stream that we pass to the derive proc-macro * Inner attributes now preserve spans in all cases, including when we have multiple inner attributes in a row. This is accomplished through the following changes: * New structs `AttrAnnotatedTokenStream` and `AttrAnnotatedTokenTree` are introduced. These are very similar to a normal `TokenTree`, but they also track the position of attributes and attribute targets within the stream. They are built when we collect tokens during parsing. An `AttrAnnotatedTokenStream` is converted to a regular `TokenStream` when we invoke a macro. * Token capturing and `LazyTokenStream` are modified to work with `AttrAnnotatedTokenStream`. A new `ReplaceRange` type is introduced, which is created during the parsing of a nested AST node to make the 'outer' AST node aware of the attributes and attribute target stored deeper in the token stream. * When we need to perform eager cfg-expansion (either due to `#[derive]` or `#[cfg_eval]`), we tokenize and reparse our target, capturing additional information about the locations of `#[cfg]` and `#[cfg_attr]` attributes at any depth within the target. This is a performance optimization, allowing us to perform less work in the typical case where captured tokens never have eager cfg-expansion run.
2020-11-28 23:33:17 +00:00
},
],
span: $DIR/inner-attrs.rs:39:17: 39:18 (#0),
Implement token-based handling of attributes during expansion This PR modifies the macro expansion infrastructure to handle attributes in a fully token-based manner. As a result: * Derives macros no longer lose spans when their input is modified by eager cfg-expansion. This is accomplished by performing eager cfg-expansion on the token stream that we pass to the derive proc-macro * Inner attributes now preserve spans in all cases, including when we have multiple inner attributes in a row. This is accomplished through the following changes: * New structs `AttrAnnotatedTokenStream` and `AttrAnnotatedTokenTree` are introduced. These are very similar to a normal `TokenTree`, but they also track the position of attributes and attribute targets within the stream. They are built when we collect tokens during parsing. An `AttrAnnotatedTokenStream` is converted to a regular `TokenStream` when we invoke a macro. * Token capturing and `LazyTokenStream` are modified to work with `AttrAnnotatedTokenStream`. A new `ReplaceRange` type is introduced, which is created during the parsing of a nested AST node to make the 'outer' AST node aware of the attributes and attribute target stored deeper in the token stream. * When we need to perform eager cfg-expansion (either due to `#[derive]` or `#[cfg_eval]`), we tokenize and reparse our target, capturing additional information about the locations of `#[cfg]` and `#[cfg_attr]` attributes at any depth within the target. This is a performance optimization, allowing us to perform less work in the typical case where captured tokens never have eager cfg-expansion run.
2020-11-28 23:33:17 +00:00
},
Ident {
ident: "true",
span: $DIR/inner-attrs.rs:40:17: 40:21 (#0),
},
],
span: $DIR/inner-attrs.rs:38:18: 41:14 (#0),
},
],
span: $DIR/inner-attrs.rs:37:20: 42:10 (#0),
},
Punct {
ch: ';',
spacing: Alone,
span: $DIR/inner-attrs.rs:42:10: 42:11 (#0),
},
Literal {
kind: Integer,
symbol: "0",
suffix: None,
span: $DIR/inner-attrs.rs:43:9: 43:10 (#0),
},
],
span: $DIR/inner-attrs.rs:36:17: 44:6 (#0),
},
],
span: $DIR/inner-attrs.rs:36:12: 44:7 (#0),
},
],
span: $DIR/inner-attrs.rs:35:22: 45:2 (#0),
},
]
PRINT-ATTR_ARGS INPUT (DISPLAY): tuple_attrs
PRINT-ATTR_ARGS INPUT (DEBUG): TokenStream [
Ident {
ident: "tuple_attrs",
span: $DIR/inner-attrs.rs:48:29: 48:40 (#0),
},
]
PRINT-ATTR INPUT (DISPLAY): (3, 4, { #! [cfg_attr(not(FALSE), rustc_dummy(innermost))] 5 }) ;
PRINT-ATTR INPUT (DEBUG): TokenStream [
Group {
delimiter: Parenthesis,
stream: TokenStream [
Literal {
kind: Integer,
symbol: "3",
suffix: None,
span: $DIR/inner-attrs.rs:49:9: 49:10 (#0),
},
Punct {
ch: ',',
spacing: Alone,
span: $DIR/inner-attrs.rs:49:10: 49:11 (#0),
},
Literal {
kind: Integer,
symbol: "4",
suffix: None,
span: $DIR/inner-attrs.rs:49:12: 49:13 (#0),
},
Punct {
ch: ',',
spacing: Alone,
span: $DIR/inner-attrs.rs:49:13: 49:14 (#0),
},
Group {
delimiter: Brace,
stream: TokenStream [
Punct {
ch: '#',
spacing: Joint,
span: $DIR/inner-attrs.rs:50:13: 50:14 (#0),
},
Punct {
ch: '!',
spacing: Alone,
span: $DIR/inner-attrs.rs:50:14: 50:15 (#0),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "cfg_attr",
span: $DIR/inner-attrs.rs:50:16: 50:24 (#0),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "not",
span: $DIR/inner-attrs.rs:50:25: 50:28 (#0),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "FALSE",
span: $DIR/inner-attrs.rs:50:29: 50:34 (#0),
},
],
span: $DIR/inner-attrs.rs:50:28: 50:35 (#0),
},
Punct {
ch: ',',
spacing: Alone,
span: $DIR/inner-attrs.rs:50:35: 50:36 (#0),
},
Ident {
ident: "rustc_dummy",
span: $DIR/inner-attrs.rs:50:37: 50:48 (#0),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "innermost",
span: $DIR/inner-attrs.rs:50:49: 50:58 (#0),
},
],
span: $DIR/inner-attrs.rs:50:48: 50:59 (#0),
},
],
span: $DIR/inner-attrs.rs:50:24: 50:60 (#0),
},
],
span: $DIR/inner-attrs.rs:50:15: 50:61 (#0),
},
Literal {
kind: Integer,
symbol: "5",
suffix: None,
span: $DIR/inner-attrs.rs:51:13: 51:14 (#0),
},
],
span: $DIR/inner-attrs.rs:49:15: 52:10 (#0),
},
],
span: $DIR/inner-attrs.rs:48:43: 53:6 (#0),
},
Punct {
ch: ';',
spacing: Alone,
span: $DIR/inner-attrs.rs:53:6: 53:7 (#0),
},
]
PRINT-ATTR_ARGS INPUT (DISPLAY): tuple_attrs
2021-02-28 19:51:44 +00:00
PRINT-ATTR_ARGS INPUT (DEBUG): TokenStream [
Ident {
ident: "tuple_attrs",
span: $DIR/inner-attrs.rs:55:29: 55:40 (#0),
2021-02-28 19:51:44 +00:00
},
]
PRINT-ATTR INPUT (DISPLAY): (3, 4, { #! [cfg_attr(not(FALSE), rustc_dummy(innermost))] 5 }) ;
2021-02-28 19:51:44 +00:00
PRINT-ATTR INPUT (DEBUG): TokenStream [
Group {
delimiter: Parenthesis,
stream: TokenStream [
Literal {
kind: Integer,
symbol: "3",
2021-02-28 19:51:44 +00:00
suffix: None,
span: $DIR/inner-attrs.rs:56:9: 56:10 (#0),
2021-02-28 19:51:44 +00:00
},
Punct {
ch: ',',
spacing: Alone,
span: $DIR/inner-attrs.rs:56:10: 56:11 (#0),
2021-02-28 19:51:44 +00:00
},
Literal {
kind: Integer,
symbol: "4",
2021-02-28 19:51:44 +00:00
suffix: None,
span: $DIR/inner-attrs.rs:56:12: 56:13 (#0),
2021-02-28 19:51:44 +00:00
},
Punct {
ch: ',',
2021-02-28 19:51:44 +00:00
spacing: Alone,
span: $DIR/inner-attrs.rs:56:13: 56:14 (#0),
2021-02-28 19:51:44 +00:00
},
Group {
delimiter: Brace,
stream: TokenStream [
Punct {
ch: '#',
spacing: Joint,
span: $DIR/inner-attrs.rs:57:13: 57:14 (#0),
},
Punct {
ch: '!',
spacing: Alone,
span: $DIR/inner-attrs.rs:57:14: 57:15 (#0),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "cfg_attr",
span: $DIR/inner-attrs.rs:57:16: 57:24 (#0),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "not",
span: $DIR/inner-attrs.rs:57:25: 57:28 (#0),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "FALSE",
span: $DIR/inner-attrs.rs:57:29: 57:34 (#0),
},
],
span: $DIR/inner-attrs.rs:57:28: 57:35 (#0),
},
Punct {
ch: ',',
spacing: Alone,
span: $DIR/inner-attrs.rs:57:35: 57:36 (#0),
},
Ident {
ident: "rustc_dummy",
span: $DIR/inner-attrs.rs:57:37: 57:48 (#0),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "innermost",
span: $DIR/inner-attrs.rs:57:49: 57:58 (#0),
},
],
span: $DIR/inner-attrs.rs:57:48: 57:59 (#0),
},
],
span: $DIR/inner-attrs.rs:57:24: 57:60 (#0),
},
],
span: $DIR/inner-attrs.rs:57:15: 57:61 (#0),
},
Literal {
kind: Integer,
symbol: "5",
suffix: None,
span: $DIR/inner-attrs.rs:58:13: 58:14 (#0),
},
],
span: $DIR/inner-attrs.rs:56:15: 59:10 (#0),
2021-02-28 19:51:44 +00:00
},
],
span: $DIR/inner-attrs.rs:55:43: 60:6 (#0),
2021-02-28 19:51:44 +00:00
},
Punct {
ch: ';',
spacing: Alone,
span: $DIR/inner-attrs.rs:60:6: 60:7 (#0),
2021-02-28 19:51:44 +00:00
},
]
PRINT-ATTR_ARGS INPUT (DISPLAY): tenth
PRINT-ATTR_ARGS INPUT (DEBUG): TokenStream [
Ident {
ident: "tenth",
span: $DIR/inner-attrs.rs:82:42: 82:47 (#0),
2021-02-28 19:51:44 +00:00
},
]
PRINT-ATTR INPUT (DISPLAY): fn weird_extern() { }
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "fn",
span: $DIR/inner-attrs.rs:81:5: 81:7 (#0),
2021-02-28 19:51:44 +00:00
},
Ident {
ident: "weird_extern",
span: $DIR/inner-attrs.rs:81:8: 81:20 (#0),
2021-02-28 19:51:44 +00:00
},
Group {
delimiter: Parenthesis,
stream: TokenStream [],
span: $DIR/inner-attrs.rs:81:20: 81:22 (#0),
2021-02-28 19:51:44 +00:00
},
Group {
delimiter: Brace,
stream: TokenStream [],
span: $DIR/inner-attrs.rs:81:23: 83:6 (#0),
2021-02-28 19:51:44 +00:00
},
]