diff options
| author | bors <bors@rust-lang.org> | 2023-06-27 21:31:47 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-06-27 21:31:47 +0000 |
| commit | 6b46c996e1d3a07dd73beb2873d74a8a0458d05f (patch) | |
| tree | 96becc824352371fe58dfb75ed7cf0ffc63ff256 /compiler/rustc_parse/src/parser | |
| parent | 5ea66686467d3ec5f8c81570e7f0f16ad8dd8cc3 (diff) | |
| parent | 4b1d0682a6ff9ced8a5a224c96dadd4ac5a500e0 (diff) | |
| download | rust-6b46c996e1d3a07dd73beb2873d74a8a0458d05f.tar.gz rust-6b46c996e1d3a07dd73beb2873d74a8a0458d05f.zip | |
Auto merge of #113105 - matthiaskrgr:rollup-rci0uym, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #112207 (Add trustzone and virtualization target features for aarch32.) - #112454 (Make compiletest aware of targets without dynamic linking) - #112628 (Allow comparing `Box`es with different allocators) - #112692 (Provide more context for `rustc +nightly -Zunstable-options` on stable) - #112972 (Make `UnwindAction::Continue` explicit in MIR dump) - #113020 (Add tests impl via obj unless denied) - #113084 (Simplify some conditions) - #113103 (Normalize types when applying uninhabited predicate.) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/attr.rs | 17 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/attr_wrapper.rs | 10 |
2 files changed, 12 insertions, 15 deletions
diff --git a/compiler/rustc_parse/src/parser/attr.rs b/compiler/rustc_parse/src/parser/attr.rs index e1db19557cf..ee0abba1c17 100644 --- a/compiler/rustc_parse/src/parser/attr.rs +++ b/compiler/rustc_parse/src/parser/attr.rs @@ -422,15 +422,12 @@ impl<'a> Parser<'a> { } } -pub fn maybe_needs_tokens(attrs: &[ast::Attribute]) -> bool { - // One of the attributes may either itself be a macro, - // or expand to macro attributes (`cfg_attr`). - attrs.iter().any(|attr| { - if attr.is_doc_comment() { - return false; - } - attr.ident().map_or(true, |ident| { - ident.name == sym::cfg_attr || !rustc_feature::is_builtin_attr_name(ident.name) - }) +/// The attributes are complete if all attributes are either a doc comment or a builtin attribute other than `cfg_attr` +pub fn is_complete(attrs: &[ast::Attribute]) -> bool { + attrs.iter().all(|attr| { + attr.is_doc_comment() + || attr.ident().is_some_and(|ident| { + ident.name != sym::cfg_attr && rustc_feature::is_builtin_attr_name(ident.name) + }) }) } diff --git a/compiler/rustc_parse/src/parser/attr_wrapper.rs b/compiler/rustc_parse/src/parser/attr_wrapper.rs index 1e6ac54964f..b579da098d8 100644 --- a/compiler/rustc_parse/src/parser/attr_wrapper.rs +++ b/compiler/rustc_parse/src/parser/attr_wrapper.rs @@ -61,8 +61,8 @@ impl AttrWrapper { self.attrs.is_empty() } - pub fn maybe_needs_tokens(&self) -> bool { - crate::parser::attr::maybe_needs_tokens(&self.attrs) + pub fn is_complete(&self) -> bool { + crate::parser::attr::is_complete(&self.attrs) } } @@ -201,7 +201,7 @@ impl<'a> Parser<'a> { // by definition if matches!(force_collect, ForceCollect::No) // None of our outer attributes can require tokens (e.g. a proc-macro) - && !attrs.maybe_needs_tokens() + && attrs.is_complete() // If our target supports custom inner attributes, then we cannot bail // out early, since we may need to capture tokens for a custom inner attribute // invocation. @@ -244,9 +244,9 @@ impl<'a> Parser<'a> { // Now that we've parsed an AST node, we have more information available. if matches!(force_collect, ForceCollect::No) // We now have inner attributes available, so this check is more precise - // than `attrs.maybe_needs_tokens()` at the start of the function. + // than `attrs.is_complete()` at the start of the function. // As a result, we don't need to check `R::SUPPORTS_CUSTOM_INNER_ATTRS` - && !crate::parser::attr::maybe_needs_tokens(ret.attrs()) + && crate::parser::attr::is_complete(ret.attrs()) // Subtle: We call `has_cfg_or_cfg_attr` with the attrs from `ret`. // This ensures that we consider inner attributes (e.g. `#![cfg]`), // which require us to have tokens available |
