diff options
| author | Jana Dönszelmann <jana@donsz.nl> | 2025-06-13 01:36:52 +0200 |
|---|---|---|
| committer | Jana Dönszelmann <jana@donsz.nl> | 2025-06-23 12:21:43 +0200 |
| commit | 82cbc3a35e23a804682922d1c04ac51a00b35137 (patch) | |
| tree | 4fd51ac4a699aff6a1d9bc414e833ae03d3b4473 /compiler/rustc_passes/src | |
| parent | 22be76b7e259f27bf3e55eb931f354cd8b69d55f (diff) | |
| download | rust-82cbc3a35e23a804682922d1c04ac51a00b35137.tar.gz rust-82cbc3a35e23a804682922d1c04ac51a00b35137.zip | |
rewrite #[naked] parser
Diffstat (limited to 'compiler/rustc_passes/src')
| -rw-r--r-- | compiler/rustc_passes/src/check_attr.rs | 14 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/liveness.rs | 3 |
2 files changed, 10 insertions, 7 deletions
diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index ad1a2a04273..1990b46adbb 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -160,6 +160,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> { Attribute::Parsed(AttributeKind::Align { align, span: repr_span }) => { self.check_align(span, target, *align, *repr_span) } + Attribute::Parsed(AttributeKind::Naked(attr_span)) => { + self.check_naked(hir_id, *attr_span, span, target, attrs) + } Attribute::Parsed( AttributeKind::BodyStability { .. } | AttributeKind::ConstStabilityIndirect @@ -217,7 +220,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> { [sym::rustc_std_internal_symbol, ..] => { self.check_rustc_std_internal_symbol(attr, span, target) } - [sym::naked, ..] => self.check_naked(hir_id, attr, span, target, attrs), [sym::rustc_no_implicit_autorefs, ..] => { self.check_applied_to_fn_or_method(hir_id, attr.span(), span, target) } @@ -623,7 +625,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { fn check_naked( &self, hir_id: HirId, - attr: &Attribute, + attr_span: Span, span: Span, target: Target, attrs: &[Attribute], @@ -659,7 +661,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> { sym::link_section, sym::linkage, sym::no_mangle, - sym::naked, sym::instruction_set, sym::repr, sym::align, @@ -703,13 +704,14 @@ impl<'tcx> CheckAttrVisitor<'tcx> { | AttributeKind::NoMangle(..) | AttributeKind::Cold(..) | AttributeKind::MustUse { .. }, + | AttributeKind::Naked(..), ) => { continue; } Attribute::Parsed(AttributeKind::Inline(.., span)) => { self.dcx().emit_err(errors::NakedFunctionIncompatibleAttribute { span: *span, - naked_span: attr.span(), + naked_span: attr_span, attr: sym::inline.to_string(), }); @@ -746,7 +748,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { self.dcx().emit_err(errors::NakedFunctionIncompatibleAttribute { span: other_attr.span(), - naked_span: attr.span(), + naked_span: attr_span, attr: other_attr_name, }); @@ -756,7 +758,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } _ => { self.dcx().emit_err(errors::AttrShouldBeAppliedToFn { - attr_span: attr.span(), + attr_span, defn_span: span, on_crate: hir_id == CRATE_HIR_ID, }); diff --git a/compiler/rustc_passes/src/liveness.rs b/compiler/rustc_passes/src/liveness.rs index 763d9fda804..125730377ef 100644 --- a/compiler/rustc_passes/src/liveness.rs +++ b/compiler/rustc_passes/src/liveness.rs @@ -85,6 +85,7 @@ use std::io; use std::io::prelude::*; use std::rc::Rc; +use rustc_attr_data_structures::{AttributeKind, find_attr}; use rustc_data_structures::fx::FxIndexMap; use rustc_hir as hir; use rustc_hir::def::*; @@ -145,7 +146,7 @@ fn check_liveness(tcx: TyCtxt<'_>, def_id: LocalDefId) { } // Don't run unused pass for #[naked] - if tcx.has_attr(def_id.to_def_id(), sym::naked) { + if find_attr!(tcx.get_all_attrs(def_id.to_def_id()), AttributeKind::Naked(..)) { return; } |
