Port #[rustc_inherit_overflow_checks] to the new attribute parsers

This commit is contained in:
Jonathan Brouwer
2026-02-22 22:02:20 +01:00
parent 1500f0f47f
commit 34d6161056
6 changed files with 22 additions and 5 deletions
@@ -175,6 +175,20 @@ fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<Attrib
}
}
pub(crate) struct RustcInheritOverflowChecksParser;
impl<S: Stage> NoArgsAttributeParser<S> for RustcInheritOverflowChecksParser {
const PATH: &[Symbol] = &[sym::rustc_inherit_overflow_checks];
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
Allow(Target::Fn),
Allow(Target::Method(MethodKind::Inherent)),
Allow(Target::Method(MethodKind::TraitImpl)),
Allow(Target::Closure),
]);
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcInheritOverflowChecks;
}
pub(crate) struct RustcLintOptDenyFieldAccessParser;
impl<S: Stage> SingleAttributeParser<S> for RustcLintOptDenyFieldAccessParser {
@@ -286,6 +286,7 @@ mod late {
Single<WithoutArgs<RustcEvaluateWhereClausesParser>>,
Single<WithoutArgs<RustcHasIncoherentInherentImplsParser>>,
Single<WithoutArgs<RustcHiddenTypeOfOpaquesParser>>,
Single<WithoutArgs<RustcInheritOverflowChecksParser>>,
Single<WithoutArgs<RustcInsignificantDtorParser>>,
Single<WithoutArgs<RustcIntrinsicConstStableIndirectParser>>,
Single<WithoutArgs<RustcIntrinsicParser>>,
@@ -1274,6 +1274,9 @@ pub enum AttributeKind {
/// Represents `#[rustc_if_this_changed]`
RustcIfThisChanged(Span, Option<Symbol>),
/// Represents `#[rustc_inherit_overflow_checks]`
RustcInheritOverflowChecks,
/// Represents `#[rustc_insignificant_dtor]`
RustcInsignificantDtor,
@@ -130,6 +130,7 @@ pub fn encode_cross_crate(&self) -> EncodeCrossCrate {
RustcHasIncoherentInherentImpls => Yes,
RustcHiddenTypeOfOpaques => No,
RustcIfThisChanged(..) => No,
RustcInheritOverflowChecks => No,
RustcInsignificantDtor => Yes,
RustcIntrinsic => Yes,
RustcIntrinsicConstStableIndirect => No,
+2 -4
View File
@@ -24,7 +24,6 @@
use rustc_abi::{ExternAbi, FieldIdx};
use rustc_apfloat::Float;
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
use rustc_ast::attr;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sorted_map::SortedIndexMultiMap;
use rustc_errors::ErrorGuaranteed;
@@ -41,7 +40,7 @@
use rustc_middle::ty::{self, ScalarInt, Ty, TyCtxt, TypeVisitableExt, TypingMode};
use rustc_middle::{bug, span_bug};
use rustc_session::lint;
use rustc_span::{Span, Symbol, sym};
use rustc_span::{Span, Symbol};
use crate::builder::expr::as_place::PlaceBuilder;
use crate::builder::scope::{DropKind, LintLevel};
@@ -751,11 +750,10 @@ fn new(
coroutine: Option<Box<CoroutineInfo<'tcx>>>,
) -> Builder<'a, 'tcx> {
let tcx = infcx.tcx;
let attrs = tcx.hir_attrs(hir_id);
// Some functions always have overflow checks enabled,
// however, they may not get codegen'd, depending on
// the settings for the crate they are codegened in.
let mut check_overflow = attr::contains_name(attrs, sym::rustc_inherit_overflow_checks);
let mut check_overflow = find_attr!(tcx.hir_attrs(hir_id), RustcInheritOverflowChecks);
// Respect -C overflow-checks.
check_overflow |= tcx.sess.overflow_checks();
// Constants always need overflow checks.
+1 -1
View File
@@ -325,6 +325,7 @@ fn check_attributes(
| AttributeKind::RustcHasIncoherentInherentImpls
| AttributeKind::RustcHiddenTypeOfOpaques
| AttributeKind::RustcIfThisChanged(..)
| AttributeKind::RustcInheritOverflowChecks
| AttributeKind::RustcInsignificantDtor
| AttributeKind::RustcIntrinsic
| AttributeKind::RustcIntrinsicConstStableIndirect
@@ -404,7 +405,6 @@ fn check_attributes(
| sym::rustc_on_unimplemented
| sym::rustc_layout
| sym::rustc_autodiff
| sym::rustc_inherit_overflow_checks
// crate-level attrs, are checked below
| sym::feature
| sym::register_tool,