diff options
| author | Jana Dönszelmann <jana@donsz.nl> | 2025-08-11 11:46:30 +0200 |
|---|---|---|
| committer | Jana Dönszelmann <jana@donsz.nl> | 2025-08-24 09:14:49 +0200 |
| commit | 4b35cde904c1015df42b2c63244c1db1ed51fff9 (patch) | |
| tree | 244f6f84dd796164a0d9e1be2ce8775f6f498352 /compiler/rustc_attr_parsing/src/interface.rs | |
| parent | 3bf61444616fc0b9de1e09031f40be0943823fc5 (diff) | |
| download | rust-4b35cde904c1015df42b2c63244c1db1ed51fff9.tar.gz rust-4b35cde904c1015df42b2c63244c1db1ed51fff9.zip | |
Support lints in early attribute parsing
Diffstat (limited to 'compiler/rustc_attr_parsing/src/interface.rs')
| -rw-r--r-- | compiler/rustc_attr_parsing/src/interface.rs | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/compiler/rustc_attr_parsing/src/interface.rs b/compiler/rustc_attr_parsing/src/interface.rs index b4222e41b71..60523c2877c 100644 --- a/compiler/rustc_attr_parsing/src/interface.rs +++ b/compiler/rustc_attr_parsing/src/interface.rs @@ -51,6 +51,27 @@ impl<'sess> AttributeParser<'sess, Early> { target_node_id: NodeId, features: Option<&'sess Features>, ) -> Option<Attribute> { + Self::parse_limited_should_emit( + sess, + attrs, + sym, + target_span, + target_node_id, + features, + ShouldEmit::Nothing, + ) + } + + /// Usually you want `parse_limited`, which defaults to no errors. + pub fn parse_limited_should_emit( + sess: &'sess Session, + attrs: &[ast::Attribute], + sym: Symbol, + target_span: Span, + target_node_id: NodeId, + features: Option<&'sess Features>, + should_emit: ShouldEmit, + ) -> Option<Attribute> { let mut parsed = Self::parse_limited_all( sess, attrs, @@ -59,7 +80,7 @@ impl<'sess> AttributeParser<'sess, Early> { target_span, target_node_id, features, - ShouldEmit::Nothing, + should_emit, ); assert!(parsed.len() <= 1); parsed.pop() @@ -84,9 +105,8 @@ impl<'sess> AttributeParser<'sess, Early> { target, OmitDoc::Skip, std::convert::identity, - |_lint| { - // FIXME: Can't emit lints here for now - // This branch can be hit when an attribute produces a warning during early parsing (such as attributes on macro calls) + |lint| { + crate::lints::emit_attribute_lint(&lint, sess); }, ) } @@ -121,8 +141,8 @@ impl<'sess> AttributeParser<'sess, Early> { cx: &mut parser, target_span, target_id: target_node_id, - emit_lint: &mut |_lint| { - panic!("can't emit lints here for now (nothing uses this atm)"); + emit_lint: &mut |lint| { + crate::lints::emit_attribute_lint(&lint, sess); }, }, attr_span: attr.span, |
