diff options
| author | Stuart Cook <Zalathar@users.noreply.github.com> | 2025-05-04 13:21:09 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-04 13:21:09 +1000 |
| commit | 54821b9ed09bcda8656d880b5f06a16ec69be52f (patch) | |
| tree | 21f0edc869424d8abc492bfa7003d032a10df927 /compiler/rustc_parse/src | |
| parent | de30d1b17cce6bd1a18f8021b24404c567aea053 (diff) | |
| parent | f4e1ec111c016f1dbbedb2628a30e9ce20d8e5f1 (diff) | |
| download | rust-54821b9ed09bcda8656d880b5f06a16ec69be52f.tar.gz rust-54821b9ed09bcda8656d880b5f06a16ec69be52f.zip | |
Rollup merge of #140617 - Urgau:unsafe_attr-lint-allow, r=jieyouxu
Report the `unsafe_attr_outside_unsafe` lint at the closest node This PR have `AstValidation` track a linting node id and then uses it when reporting the `unsafe_attr_outside_unsafe` lint, so that instead of being bound at the crate-root, `#[allow]` of the lint works at any node. Fixes rust-lang/rust#140602 r? `@jieyouxu`
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/validate_attr.rs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/compiler/rustc_parse/src/validate_attr.rs b/compiler/rustc_parse/src/validate_attr.rs index 6a1c2af48ed..aa29b24fe91 100644 --- a/compiler/rustc_parse/src/validate_attr.rs +++ b/compiler/rustc_parse/src/validate_attr.rs @@ -3,7 +3,8 @@ use rustc_ast::token::Delimiter; use rustc_ast::tokenstream::DelimSpan; use rustc_ast::{ - self as ast, AttrArgs, Attribute, DelimArgs, MetaItem, MetaItemInner, MetaItemKind, Safety, + self as ast, AttrArgs, Attribute, DelimArgs, MetaItem, MetaItemInner, MetaItemKind, NodeId, + Safety, }; use rustc_errors::{Applicability, FatalError, PResult}; use rustc_feature::{AttributeSafety, AttributeTemplate, BUILTIN_ATTRIBUTE_MAP, BuiltinAttribute}; @@ -15,7 +16,7 @@ use rustc_span::{Span, Symbol, sym}; use crate::{errors, parse_in}; -pub fn check_attr(psess: &ParseSess, attr: &Attribute) { +pub fn check_attr(psess: &ParseSess, attr: &Attribute, id: NodeId) { if attr.is_doc_comment() || attr.has_name(sym::cfg_trace) || attr.has_name(sym::cfg_attr_trace) { return; @@ -26,7 +27,7 @@ pub fn check_attr(psess: &ParseSess, attr: &Attribute) { // All non-builtin attributes are considered safe let safety = attr_info.map(|x| x.safety).unwrap_or(AttributeSafety::Normal); - check_attribute_safety(psess, safety, attr); + check_attribute_safety(psess, safety, attr, id); // Check input tokens for built-in and key-value attributes. match attr_info { @@ -154,7 +155,12 @@ fn is_attr_template_compatible(template: &AttributeTemplate, meta: &ast::MetaIte } } -pub fn check_attribute_safety(psess: &ParseSess, safety: AttributeSafety, attr: &Attribute) { +pub fn check_attribute_safety( + psess: &ParseSess, + safety: AttributeSafety, + attr: &Attribute, + id: NodeId, +) { let attr_item = attr.get_normal_item(); if let AttributeSafety::Unsafe { unsafe_since } = safety { @@ -185,7 +191,7 @@ pub fn check_attribute_safety(psess: &ParseSess, safety: AttributeSafety, attr: psess.buffer_lint( UNSAFE_ATTR_OUTSIDE_UNSAFE, path_span, - ast::CRATE_NODE_ID, + id, BuiltinLintDiag::UnsafeAttrOutsideUnsafe { attribute_name_span: path_span, sugg_spans: (diag_span.shrink_to_lo(), diag_span.shrink_to_hi()), |
