Skip to content

Commit 5dfe98d

Browse files
Improve should_emit & add parse_limited_all
1 parent 3c8afb5 commit 5dfe98d

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -762,14 +762,31 @@ impl<'sess> AttributeParser<'sess, Early> {
762762
target_node_id: NodeId,
763763
features: Option<&'sess Features>,
764764
) -> Option<Attribute> {
765-
let mut p = Self {
766-
features,
767-
tools: Vec::new(),
768-
parse_only: Some(sym),
765+
let mut parsed = Self::parse_limited_all(
769766
sess,
770-
stage: Early { emit_errors: ShouldEmit::Nothing },
771-
};
772-
let mut parsed = p.parse_attribute_list(
767+
attrs,
768+
Some(sym),
769+
target_span,
770+
target_node_id,
771+
features,
772+
ShouldEmit::Nothing,
773+
);
774+
assert!(parsed.len() <= 1);
775+
parsed.pop()
776+
}
777+
778+
pub fn parse_limited_all(
779+
sess: &'sess Session,
780+
attrs: &[ast::Attribute],
781+
parse_only: Option<Symbol>,
782+
target_span: Span,
783+
target_node_id: NodeId,
784+
features: Option<&'sess Features>,
785+
emit_errors: ShouldEmit,
786+
) -> Vec<Attribute> {
787+
let mut p =
788+
Self { features, tools: Vec::new(), parse_only, sess, stage: Early { emit_errors } };
789+
p.parse_attribute_list(
773790
attrs,
774791
target_span,
775792
target_node_id,
@@ -779,10 +796,7 @@ impl<'sess> AttributeParser<'sess, Early> {
779796
|_lint| {
780797
panic!("can't emit lints here for now (nothing uses this atm)");
781798
},
782-
);
783-
assert!(parsed.len() <= 1);
784-
785-
parsed.pop()
799+
)
786800
}
787801

788802
pub fn parse_single<T>(

0 commit comments

Comments
 (0)