Skip to content

Commit e631b1e

Browse files
committed
Invert the sense of is_complete and rename it as needs_tokens.
I have always found `is_complete` an unhelpful name. The new name (and inverted sense) fits in better with the conditions at its call sites.
1 parent 3d363c3 commit e631b1e

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

compiler/rustc_parse/src/parser/attr_wrapper.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ impl<'a> Parser<'a> {
201201
// tokens by definition).
202202
let needs_collection = matches!(force_collect, ForceCollect::Yes)
203203
// - Any of our outer attributes require tokens.
204-
|| !is_complete(&attrs.attrs)
204+
|| needs_tokens(&attrs.attrs)
205205
// - Our target supports custom inner attributes (custom
206206
// inner attribute invocation might require token capturing).
207207
|| R::SUPPORTS_CUSTOM_INNER_ATTRS
@@ -259,9 +259,9 @@ impl<'a> Parser<'a> {
259259
// - Any of our outer *or* inner attributes require tokens.
260260
// (`attr.attrs` was just outer attributes, but `ret.attrs()` is
261261
// 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
263263
// check `R::SUPPORTS_CUSTOM_INNER_ATTRS`.)
264-
|| !is_complete(ret.attrs())
264+
|| needs_tokens(ret.attrs())
265265
// - We are in `capture_cfg` mode and there are `#[cfg]` or
266266
// `#[cfg_attr]` attributes. (During normal non-`capture_cfg`
267267
// parsing, we don't need any special capturing for those
@@ -457,14 +457,16 @@ fn make_attr_token_stream(
457457
AttrTokenStream::new(stack_top.inner)
458458
}
459459

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+
}
468470
})
469471
}
470472

0 commit comments

Comments
 (0)