Skip to content

Commit ef8d529

Browse files
authored
Rollup merge of rust-lang#152989 - JonathanBrouwer:rustc_inherit_overflow_checks, r=jdonszelmann
Port `#[rustc_inherit_overflow_checks]` to the new attribute parsers For rust-lang#131229 (comment) r? @jdonszelmann
2 parents 66173bb + 34d6161 commit ef8d529

6 files changed

Lines changed: 22 additions & 5 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,20 @@ impl<S: Stage> SingleAttributeParser<S> for RustcLegacyConstGenericsParser {
175175
}
176176
}
177177

178+
pub(crate) struct RustcInheritOverflowChecksParser;
179+
180+
impl<S: Stage> NoArgsAttributeParser<S> for RustcInheritOverflowChecksParser {
181+
const PATH: &[Symbol] = &[sym::rustc_inherit_overflow_checks];
182+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
183+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
184+
Allow(Target::Fn),
185+
Allow(Target::Method(MethodKind::Inherent)),
186+
Allow(Target::Method(MethodKind::TraitImpl)),
187+
Allow(Target::Closure),
188+
]);
189+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcInheritOverflowChecks;
190+
}
191+
178192
pub(crate) struct RustcLintOptDenyFieldAccessParser;
179193

180194
impl<S: Stage> SingleAttributeParser<S> for RustcLintOptDenyFieldAccessParser {

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ attribute_parsers!(
287287
Single<WithoutArgs<RustcEvaluateWhereClausesParser>>,
288288
Single<WithoutArgs<RustcHasIncoherentInherentImplsParser>>,
289289
Single<WithoutArgs<RustcHiddenTypeOfOpaquesParser>>,
290+
Single<WithoutArgs<RustcInheritOverflowChecksParser>>,
290291
Single<WithoutArgs<RustcInsignificantDtorParser>>,
291292
Single<WithoutArgs<RustcIntrinsicConstStableIndirectParser>>,
292293
Single<WithoutArgs<RustcIntrinsicParser>>,

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,9 @@ pub enum AttributeKind {
12771277
/// Represents `#[rustc_if_this_changed]`
12781278
RustcIfThisChanged(Span, Option<Symbol>),
12791279

1280+
/// Represents `#[rustc_inherit_overflow_checks]`
1281+
RustcInheritOverflowChecks,
1282+
12801283
/// Represents `#[rustc_insignificant_dtor]`
12811284
RustcInsignificantDtor,
12821285

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ impl AttributeKind {
131131
RustcHasIncoherentInherentImpls => Yes,
132132
RustcHiddenTypeOfOpaques => No,
133133
RustcIfThisChanged(..) => No,
134+
RustcInheritOverflowChecks => No,
134135
RustcInsignificantDtor => Yes,
135136
RustcIntrinsic => Yes,
136137
RustcIntrinsicConstStableIndirect => No,

compiler/rustc_mir_build/src/builder/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use itertools::Itertools;
2424
use rustc_abi::{ExternAbi, FieldIdx};
2525
use rustc_apfloat::Float;
2626
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
27-
use rustc_ast::attr;
2827
use rustc_data_structures::fx::FxHashMap;
2928
use rustc_data_structures::sorted_map::SortedIndexMultiMap;
3029
use rustc_errors::ErrorGuaranteed;
@@ -41,7 +40,7 @@ use rustc_middle::thir::{self, ExprId, LocalVarId, Param, ParamId, PatKind, Thir
4140
use rustc_middle::ty::{self, ScalarInt, Ty, TyCtxt, TypeVisitableExt, TypingMode};
4241
use rustc_middle::{bug, span_bug};
4342
use rustc_session::lint;
44-
use rustc_span::{Span, Symbol, sym};
43+
use rustc_span::{Span, Symbol};
4544

4645
use crate::builder::expr::as_place::PlaceBuilder;
4746
use crate::builder::scope::{DropKind, LintLevel};
@@ -751,11 +750,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
751750
coroutine: Option<Box<CoroutineInfo<'tcx>>>,
752751
) -> Builder<'a, 'tcx> {
753752
let tcx = infcx.tcx;
754-
let attrs = tcx.hir_attrs(hir_id);
755753
// Some functions always have overflow checks enabled,
756754
// however, they may not get codegen'd, depending on
757755
// the settings for the crate they are codegened in.
758-
let mut check_overflow = attr::contains_name(attrs, sym::rustc_inherit_overflow_checks);
756+
let mut check_overflow = find_attr!(tcx.hir_attrs(hir_id), RustcInheritOverflowChecks);
759757
// Respect -C overflow-checks.
760758
check_overflow |= tcx.sess.overflow_checks();
761759
// Constants always need overflow checks.

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
326326
| AttributeKind::RustcHasIncoherentInherentImpls
327327
| AttributeKind::RustcHiddenTypeOfOpaques
328328
| AttributeKind::RustcIfThisChanged(..)
329+
| AttributeKind::RustcInheritOverflowChecks
329330
| AttributeKind::RustcInsignificantDtor
330331
| AttributeKind::RustcIntrinsic
331332
| AttributeKind::RustcIntrinsicConstStableIndirect
@@ -405,7 +406,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
405406
| sym::rustc_on_unimplemented
406407
| sym::rustc_layout
407408
| sym::rustc_autodiff
408-
| sym::rustc_inherit_overflow_checks
409409
// crate-level attrs, are checked below
410410
| sym::feature,
411411
..

0 commit comments

Comments
 (0)