@@ -201,7 +201,7 @@ impl<'a> Parser<'a> {
201
201
// tokens by definition).
202
202
let needs_collection = matches ! ( force_collect, ForceCollect :: Yes )
203
203
// - Any of our outer attributes require tokens.
204
- || ! is_complete ( & attrs. attrs )
204
+ || needs_tokens ( & attrs. attrs )
205
205
// - Our target supports custom inner attributes (custom
206
206
// inner attribute invocation might require token capturing).
207
207
|| R :: SUPPORTS_CUSTOM_INNER_ATTRS
@@ -259,9 +259,9 @@ impl<'a> Parser<'a> {
259
259
// - Any of our outer *or* inner attributes require tokens.
260
260
// (`attr.attrs` was just outer attributes, but `ret.attrs()` is
261
261
// outer and inner attributes. So this check is more precise than
262
- // the earlier `is_complete() ` check, and we don't need to
262
+ // the earlier `needs_tokens ` check, and we don't need to
263
263
// check `R::SUPPORTS_CUSTOM_INNER_ATTRS`.)
264
- || ! is_complete ( ret. attrs ( ) )
264
+ || needs_tokens ( ret. attrs ( ) )
265
265
// - We are in `capture_cfg` mode and there are `#[cfg]` or
266
266
// `#[cfg_attr]` attributes. (During normal non-`capture_cfg`
267
267
// parsing, we don't need any special capturing for those
@@ -457,14 +457,16 @@ fn make_attr_token_stream(
457
457
AttrTokenStream :: new ( stack_top. inner )
458
458
}
459
459
460
- /// The attributes are complete if all attributes are either a doc comment or a
461
- /// builtin attribute other than `cfg_attr`.
462
- fn is_complete ( attrs : & [ ast:: Attribute ] ) -> bool {
463
- attrs. iter ( ) . all ( |attr| {
464
- attr. is_doc_comment ( )
465
- || attr. ident ( ) . is_some_and ( |ident| {
466
- ident. name != sym:: cfg_attr && rustc_feature:: is_builtin_attr_name ( ident. name )
467
- } )
460
+ /// Tokens are needed if:
461
+ /// - any non-single-segment attributes (other than doc comments) are present; or
462
+ /// - any `cfg_attr` attributes are present;
463
+ /// - any single-segment, non-builtin attributes are present.
464
+ fn needs_tokens ( attrs : & [ ast:: Attribute ] ) -> bool {
465
+ attrs. iter ( ) . any ( |attr| match attr. ident ( ) {
466
+ None => !attr. is_doc_comment ( ) ,
467
+ Some ( ident) => {
468
+ ident. name == sym:: cfg_attr || !rustc_feature:: is_builtin_attr_name ( ident. name )
469
+ }
468
470
} )
469
471
}
470
472
0 commit comments