Skip to content

Commit cf1a784

Browse files
committed
Port rustc_regions to the new attribute parser
1 parent 06cafcb commit cf1a784

6 files changed

Lines changed: 25 additions & 3 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,22 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcLintQueryInstabilityParser {
219219
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcLintQueryInstability;
220220
}
221221

222+
pub(crate) struct RustcRegionsParser;
223+
224+
impl<S: Stage> NoArgsAttributeParser<S> for RustcRegionsParser {
225+
const PATH: &[Symbol] = &[sym::rustc_regions];
226+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
227+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
228+
Allow(Target::Fn),
229+
Allow(Target::Method(MethodKind::Inherent)),
230+
Allow(Target::Method(MethodKind::Trait { body: false })),
231+
Allow(Target::Method(MethodKind::Trait { body: true })),
232+
Allow(Target::Method(MethodKind::TraitImpl)),
233+
]);
234+
235+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcRegions;
236+
}
237+
222238
pub(crate) struct RustcLintUntrackedQueryInformationParser;
223239

224240
impl<S: Stage> NoArgsAttributeParser<S> for RustcLintUntrackedQueryInformationParser {

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ attribute_parsers!(
276276
Single<WithoutArgs<RustcPassIndirectlyInNonRusticAbisParser>>,
277277
Single<WithoutArgs<RustcPreserveUbChecksParser>>,
278278
Single<WithoutArgs<RustcReallocatorParser>>,
279+
Single<WithoutArgs<RustcRegionsParser>>,
279280
Single<WithoutArgs<RustcShouldNotBeCalledOnConstItems>>,
280281
Single<WithoutArgs<RustcVarianceOfOpaquesParser>>,
281282
Single<WithoutArgs<RustcVarianceParser>>,

compiler/rustc_borrowck/src/nll.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use std::str::FromStr;
77

88
use polonius_engine::{Algorithm, AllFacts, Output};
99
use rustc_data_structures::frozen::Frozen;
10+
use rustc_hir::attrs::AttributeKind;
11+
use rustc_hir::find_attr;
1012
use rustc_index::IndexSlice;
1113
use rustc_middle::mir::pretty::PrettyPrintMirOptions;
1214
use rustc_middle::mir::{Body, MirDumper, PassWhere, Promoted};
@@ -15,7 +17,6 @@ use rustc_middle::ty::{self, TyCtxt};
1517
use rustc_mir_dataflow::move_paths::MoveData;
1618
use rustc_mir_dataflow::points::DenseLocationMap;
1719
use rustc_session::config::MirIncludeSpans;
18-
use rustc_span::sym;
1920
use tracing::{debug, instrument};
2021

2122
use crate::borrow_set::BorrowSet;
@@ -295,7 +296,7 @@ pub(super) fn dump_annotation<'tcx, 'infcx>(
295296
) {
296297
let tcx = infcx.tcx;
297298
let base_def_id = tcx.typeck_root_def_id(body.source.def_id());
298-
if !tcx.has_attr(base_def_id, sym::rustc_regions) {
299+
if !find_attr!(tcx.get_all_attrs(base_def_id), AttributeKind::RustcRegions) {
299300
return;
300301
}
301302

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,9 @@ pub enum AttributeKind {
11981198
/// Represents `#[rustc_reallocator]`
11991199
RustcReallocator,
12001200

1201+
/// Represents `#[rustc_regions]`
1202+
RustcRegions,
1203+
12011204
/// Represents `#[rustc_scalable_vector(N)]`
12021205
RustcScalableVector {
12031206
/// The base multiple of lanes that are in a scalable vector, if provided. `element_count`

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ impl AttributeKind {
144144
RustcPreserveUbChecks => No,
145145
RustcPubTransparent(..) => Yes,
146146
RustcReallocator => No,
147+
RustcRegions => No,
147148
RustcScalableVector { .. } => Yes,
148149
RustcShouldNotBeCalledOnConstItems(..) => Yes,
149150
RustcSimdMonomorphizeLaneLimit(..) => Yes, // Affects layout computation, which needs to work cross-crate

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
335335
| AttributeKind::RustcPassIndirectlyInNonRusticAbis(..)
336336
| AttributeKind::RustcPreserveUbChecks
337337
| AttributeKind::RustcReallocator
338+
| AttributeKind::RustcRegions
338339
| AttributeKind::RustcScalableVector { .. }
339340
| AttributeKind::RustcShouldNotBeCalledOnConstItems(..)
340341
| AttributeKind::RustcSimdMonomorphizeLaneLimit(..)
@@ -401,7 +402,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
401402
| sym::rustc_never_type_options
402403
| sym::rustc_autodiff
403404
| sym::rustc_capture_analysis
404-
| sym::rustc_regions
405405
| sym::rustc_strict_coherence
406406
| sym::rustc_mir
407407
| sym::rustc_outlives

0 commit comments

Comments
 (0)