Skip to content

Commit 9e21300

Browse files
authored
Rollup merge of rust-lang#152009 - Ozzy1423:attrs4, r=JonathanBrouwer
Port rustc_preserve_ub_checks to attr parser Tracking issue: rust-lang#131229 Port rustc_preserve_ub_checks to attr parser r? @JonathanBrouwer
2 parents cbebacd + f599313 commit 9e21300

7 files changed

Lines changed: 38 additions & 23 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/crate_level.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,3 +274,12 @@ impl<S: Stage> NoArgsAttributeParser<S> for NoBuiltinsParser {
274274
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
275275
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NoBuiltins;
276276
}
277+
278+
pub(crate) struct RustcPreserveUbChecksParser;
279+
280+
impl<S: Stage> NoArgsAttributeParser<S> for RustcPreserveUbChecksParser {
281+
const PATH: &[Symbol] = &[sym::rustc_preserve_ub_checks];
282+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
283+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
284+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcPreserveUbChecks;
285+
}

compiler/rustc_attr_parsing/src/attributes/rustc_dump.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,36 @@ use crate::attributes::{NoArgsAttributeParser, OnDuplicate};
77
use crate::context::Stage;
88
use crate::target_checking::AllowedTargets;
99

10-
pub(crate) struct RustcDumpUserArgs;
10+
pub(crate) struct RustcDumpUserArgsParser;
1111

12-
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpUserArgs {
12+
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpUserArgsParser {
1313
const PATH: &[Symbol] = &[sym::rustc_dump_user_args];
1414
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
1515
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Fn)]);
1616
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDumpUserArgs;
1717
}
1818

19-
pub(crate) struct RustcDumpDefParents;
19+
pub(crate) struct RustcDumpDefParentsParser;
2020

21-
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpDefParents {
21+
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpDefParentsParser {
2222
const PATH: &[Symbol] = &[sym::rustc_dump_def_parents];
2323
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
2424
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Fn)]);
2525
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDumpDefParents;
2626
}
2727

28-
pub(crate) struct RustcDumpItemBounds;
28+
pub(crate) struct RustcDumpItemBoundsParser;
2929

30-
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpItemBounds {
30+
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpItemBoundsParser {
3131
const PATH: &[Symbol] = &[sym::rustc_dump_item_bounds];
3232
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
3333
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::AssocTy)]);
3434
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDumpItemBounds;
3535
}
3636

37-
pub(crate) struct RustcDumpPredicates;
37+
pub(crate) struct RustcDumpPredicatesParser;
3838

39-
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpPredicates {
39+
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpPredicatesParser {
4040
const PATH: &[Symbol] = &[sym::rustc_dump_predicates];
4141
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
4242
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
@@ -49,9 +49,9 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpPredicates {
4949
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDumpPredicates;
5050
}
5151

52-
pub(crate) struct RustcDumpVtable;
52+
pub(crate) struct RustcDumpVtableParser;
5353

54-
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpVtable {
54+
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpVtableParser {
5555
const PATH: &[Symbol] = &[sym::rustc_dump_vtable];
5656
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
5757
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ use crate::attributes::crate_level::{
3232
CrateNameParser, CrateTypeParser, MoveSizeLimitParser, NeedsPanicRuntimeParser,
3333
NoBuiltinsParser, NoCoreParser, NoMainParser, NoStdParser, PanicRuntimeParser,
3434
PatternComplexityLimitParser, ProfilerRuntimeParser, RecursionLimitParser,
35-
RustcCoherenceIsCoreParser, TypeLengthLimitParser, WindowsSubsystemParser,
35+
RustcCoherenceIsCoreParser, RustcPreserveUbChecksParser, TypeLengthLimitParser,
36+
WindowsSubsystemParser,
3637
};
3738
use crate::attributes::debugger::DebuggerViualizerParser;
3839
use crate::attributes::deprecation::DeprecationParser;
@@ -72,8 +73,8 @@ use crate::attributes::rustc_allocator::{
7273
RustcDeallocatorParser, RustcReallocatorParser,
7374
};
7475
use crate::attributes::rustc_dump::{
75-
RustcDumpDefParents, RustcDumpItemBounds, RustcDumpPredicates, RustcDumpUserArgs,
76-
RustcDumpVtable,
76+
RustcDumpDefParentsParser, RustcDumpItemBoundsParser, RustcDumpPredicatesParser,
77+
RustcDumpUserArgsParser, RustcDumpVtableParser,
7778
};
7879
use crate::attributes::rustc_internal::{
7980
RustcHasIncoherentInherentImplsParser, RustcLayoutParser, RustcLayoutScalarValidRangeEndParser,
@@ -294,11 +295,11 @@ attribute_parsers!(
294295
Single<WithoutArgs<RustcAllocatorZeroedParser>>,
295296
Single<WithoutArgs<RustcCoherenceIsCoreParser>>,
296297
Single<WithoutArgs<RustcDeallocatorParser>>,
297-
Single<WithoutArgs<RustcDumpDefParents>>,
298-
Single<WithoutArgs<RustcDumpItemBounds>>,
299-
Single<WithoutArgs<RustcDumpPredicates>>,
300-
Single<WithoutArgs<RustcDumpUserArgs>>,
301-
Single<WithoutArgs<RustcDumpVtable>>,
298+
Single<WithoutArgs<RustcDumpDefParentsParser>>,
299+
Single<WithoutArgs<RustcDumpItemBoundsParser>>,
300+
Single<WithoutArgs<RustcDumpPredicatesParser>>,
301+
Single<WithoutArgs<RustcDumpUserArgsParser>>,
302+
Single<WithoutArgs<RustcDumpVtableParser>>,
302303
Single<WithoutArgs<RustcHasIncoherentInherentImplsParser>>,
303304
Single<WithoutArgs<RustcLintOptTyParser>>,
304305
Single<WithoutArgs<RustcLintQueryInstabilityParser>>,
@@ -310,6 +311,7 @@ attribute_parsers!(
310311
Single<WithoutArgs<RustcNounwindParser>>,
311312
Single<WithoutArgs<RustcOffloadKernelParser>>,
312313
Single<WithoutArgs<RustcPassIndirectlyInNonRusticAbisParser>>,
314+
Single<WithoutArgs<RustcPreserveUbChecksParser>>,
313315
Single<WithoutArgs<RustcReallocatorParser>>,
314316
Single<WithoutArgs<RustcShouldNotBeCalledOnConstItems>>,
315317
Single<WithoutArgs<RustcVarianceOfOpaquesParser>>,

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,9 @@ pub enum AttributeKind {
11231123
/// Represents `#[rustc_pass_indirectly_in_non_rustic_abis]`
11241124
RustcPassIndirectlyInNonRusticAbis(Span),
11251125

1126+
/// Represents `#[rustc_preserve_ub_checks]`
1127+
RustcPreserveUbChecks,
1128+
11261129
/// Represents `#[rustc_pub_transparent]` (used by the `repr_transparent_external_private_fields` lint).
11271130
RustcPubTransparent(Span),
11281131

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ impl AttributeKind {
133133
RustcParenSugar(..) => No,
134134
RustcPassByValue(..) => Yes,
135135
RustcPassIndirectlyInNonRusticAbis(..) => No,
136+
RustcPreserveUbChecks => No,
136137
RustcPubTransparent(..) => Yes,
137138
RustcReallocator => No,
138139
RustcScalableVector { .. } => Yes,

compiler/rustc_mir_transform/src/instsimplify.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Performs various peephole optimizations.
22
33
use rustc_abi::ExternAbi;
4-
use rustc_ast::attr;
5-
use rustc_hir::LangItem;
4+
use rustc_hir::attrs::AttributeKind;
5+
use rustc_hir::{LangItem, find_attr};
66
use rustc_middle::bug;
77
use rustc_middle::mir::visit::MutVisitor;
88
use rustc_middle::mir::*;
@@ -31,7 +31,7 @@ impl<'tcx> crate::MirPass<'tcx> for InstSimplify {
3131

3232
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
3333
let preserve_ub_checks =
34-
attr::contains_name(tcx.hir_krate_attrs(), sym::rustc_preserve_ub_checks);
34+
find_attr!(tcx.hir_krate_attrs(), AttributeKind::RustcPreserveUbChecks);
3535
if !preserve_ub_checks {
3636
SimplifyUbCheck { tcx }.visit_body(body);
3737
}

compiler/rustc_passes/src/check_attr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
318318
| AttributeKind::RustcParenSugar(..)
319319
| AttributeKind::RustcPassByValue (..)
320320
| AttributeKind::RustcPassIndirectlyInNonRusticAbis(..)
321+
| AttributeKind::RustcPreserveUbChecks
321322
| AttributeKind::RustcReallocator
322323
| AttributeKind::RustcScalableVector { .. }
323324
| AttributeKind::RustcShouldNotBeCalledOnConstItems(..)
@@ -406,8 +407,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
406407
| sym::register_tool
407408
| sym::rustc_no_implicit_bounds
408409
| sym::test_runner
409-
| sym::reexport_test_harness_main
410-
| sym::rustc_preserve_ub_checks,
410+
| sym::reexport_test_harness_main,
411411
..
412412
] => {}
413413
[name, rest@..] => {

0 commit comments

Comments
 (0)