Skip to content

Commit 7d16363

Browse files
Rollup merge of rust-lang#152212 - Ozzy1423:three-attrs, r=JonathanBrouwer
Port some attributes to the attr parser Tracking issue: rust-lang#131229 r? @JonathanBrouwer
2 parents 61af199 + c6f4bcf commit 7d16363

8 files changed

Lines changed: 67 additions & 8 deletions

File tree

compiler/rustc_attr_parsing/src/attributes/test_attrs.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,41 @@ impl<S: Stage> SingleAttributeParser<S> for RustcAbiParser {
190190
Some(AttributeKind::RustcAbi { attr_span: cx.attr_span, kind })
191191
}
192192
}
193+
194+
pub(crate) struct RustcDelayedBugFromInsideQueryParser;
195+
196+
impl<S: Stage> NoArgsAttributeParser<S> for RustcDelayedBugFromInsideQueryParser {
197+
const PATH: &[Symbol] = &[sym::rustc_delayed_bug_from_inside_query];
198+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
199+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Fn)]);
200+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDelayedBugFromInsideQuery;
201+
}
202+
203+
pub(crate) struct RustcEvaluateWhereClausesParser;
204+
205+
impl<S: Stage> NoArgsAttributeParser<S> for RustcEvaluateWhereClausesParser {
206+
const PATH: &[Symbol] = &[sym::rustc_evaluate_where_clauses];
207+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
208+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
209+
Allow(Target::Fn),
210+
Allow(Target::Method(MethodKind::Inherent)),
211+
Allow(Target::Method(MethodKind::Trait { body: true })),
212+
Allow(Target::Method(MethodKind::TraitImpl)),
213+
Allow(Target::Method(MethodKind::Trait { body: false })),
214+
]);
215+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcEvaluateWhereClauses;
216+
}
217+
218+
pub(crate) struct RustcOutlivesParser;
219+
220+
impl<S: Stage> NoArgsAttributeParser<S> for RustcOutlivesParser {
221+
const PATH: &[Symbol] = &[sym::rustc_outlives];
222+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
223+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
224+
Allow(Target::Struct),
225+
Allow(Target::Enum),
226+
Allow(Target::Union),
227+
Allow(Target::TyAlias),
228+
]);
229+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcOutlives;
230+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,14 @@ attribute_parsers!(
254254
Single<WithoutArgs<RustcAllocatorZeroedParser>>,
255255
Single<WithoutArgs<RustcCoherenceIsCoreParser>>,
256256
Single<WithoutArgs<RustcDeallocatorParser>>,
257+
Single<WithoutArgs<RustcDelayedBugFromInsideQueryParser>>,
257258
Single<WithoutArgs<RustcDumpDefParentsParser>>,
258259
Single<WithoutArgs<RustcDumpItemBoundsParser>>,
259260
Single<WithoutArgs<RustcDumpPredicatesParser>>,
260261
Single<WithoutArgs<RustcDumpUserArgsParser>>,
261262
Single<WithoutArgs<RustcDumpVtableParser>>,
262263
Single<WithoutArgs<RustcEffectiveVisibilityParser>>,
264+
Single<WithoutArgs<RustcEvaluateWhereClausesParser>>,
263265
Single<WithoutArgs<RustcHasIncoherentInherentImplsParser>>,
264266
Single<WithoutArgs<RustcHiddenTypeOfOpaquesParser>>,
265267
Single<WithoutArgs<RustcIntrinsicConstStableIndirectParser>>,
@@ -273,6 +275,7 @@ attribute_parsers!(
273275
Single<WithoutArgs<RustcNonConstTraitMethodParser>>,
274276
Single<WithoutArgs<RustcNounwindParser>>,
275277
Single<WithoutArgs<RustcOffloadKernelParser>>,
278+
Single<WithoutArgs<RustcOutlivesParser>>,
276279
Single<WithoutArgs<RustcPassIndirectlyInNonRusticAbisParser>>,
277280
Single<WithoutArgs<RustcPreserveUbChecksParser>>,
278281
Single<WithoutArgs<RustcReallocatorParser>>,

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,9 @@ pub enum AttributeKind {
10811081
/// Represents `#[rustc_deallocator]`
10821082
RustcDeallocator,
10831083

1084+
/// Represents `#[rustc_delayed_bug_from_inside_query]`
1085+
RustcDelayedBugFromInsideQuery,
1086+
10841087
/// Represents `#[rustc_deny_explicit_impl]`.
10851088
RustcDenyExplicitImpl(Span),
10861089

@@ -1108,6 +1111,9 @@ pub enum AttributeKind {
11081111
/// Represents `#[rustc_effective_visibility]`.
11091112
RustcEffectiveVisibility,
11101113

1114+
/// Represents `#[rustc_evaluate_where_clauses]`
1115+
RustcEvaluateWhereClauses,
1116+
11111117
/// Represents `#[rustc_has_incoherent_inherent_impls]`
11121118
RustcHasIncoherentInherentImpls,
11131119

@@ -1183,6 +1189,9 @@ pub enum AttributeKind {
11831189
/// Represents `#[rustc_offload_kernel]`
11841190
RustcOffloadKernel,
11851191

1192+
/// Represents `#[rustc_outlives]`
1193+
RustcOutlives,
1194+
11861195
/// Represents `#[rustc_paren_sugar]`.
11871196
RustcParenSugar(Span),
11881197

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ impl AttributeKind {
105105
RustcConstStability { .. } => Yes,
106106
RustcConstStabilityIndirect => No,
107107
RustcDeallocator => No,
108+
RustcDelayedBugFromInsideQuery => No,
108109
RustcDenyExplicitImpl(..) => No,
109110
RustcDummy => No,
110111
RustcDumpDefParents => No,
@@ -114,6 +115,7 @@ impl AttributeKind {
114115
RustcDumpVtable(..) => No,
115116
RustcDynIncompatibleTrait(..) => No,
116117
RustcEffectiveVisibility => Yes,
118+
RustcEvaluateWhereClauses => Yes,
117119
RustcHasIncoherentInherentImpls => Yes,
118120
RustcHiddenTypeOfOpaques => No,
119121
RustcIfThisChanged(..) => No,
@@ -139,6 +141,7 @@ impl AttributeKind {
139141
RustcObjcSelector { .. } => No,
140142
RustcObjectLifetimeDefault => No,
141143
RustcOffloadKernel => Yes,
144+
RustcOutlives => No,
142145
RustcParenSugar(..) => No,
143146
RustcPassByValue(..) => Yes,
144147
RustcPassIndirectlyInNonRusticAbis(..) => No,

compiler/rustc_hir_analysis/src/outlives/dump.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
use rustc_hir::attrs::AttributeKind;
2+
use rustc_hir::find_attr;
13
use rustc_middle::bug;
24
use rustc_middle::ty::{self, TyCtxt};
35
use rustc_span::sym;
46

57
pub(crate) fn inferred_outlives(tcx: TyCtxt<'_>) {
68
for id in tcx.hir_free_items() {
7-
if !tcx.has_attr(id.owner_id, sym::rustc_outlives) {
9+
if !find_attr!(tcx.get_all_attrs(id.owner_id), AttributeKind::RustcOutlives) {
810
continue;
911
}
1012

compiler/rustc_hir_typeck/src/callee.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ use std::iter;
33
use rustc_abi::{CanonAbi, ExternAbi};
44
use rustc_ast::util::parser::ExprPrecedence;
55
use rustc_errors::{Applicability, Diag, ErrorGuaranteed, StashKey, inline_fluent};
6+
use rustc_hir::attrs::AttributeKind;
67
use rustc_hir::def::{self, CtorKind, Namespace, Res};
78
use rustc_hir::def_id::DefId;
8-
use rustc_hir::{self as hir, HirId, LangItem};
9+
use rustc_hir::{self as hir, HirId, LangItem, find_attr};
910
use rustc_hir_analysis::autoderef::Autoderef;
1011
use rustc_infer::infer::BoundRegionConversionTime;
1112
use rustc_infer::traits::{Obligation, ObligationCause, ObligationCauseCode};
@@ -526,7 +527,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
526527
// `#[rustc_evaluate_where_clauses]` trigger special output
527528
// to let us test the trait evaluation system.
528529
if self.has_rustc_attrs
529-
&& self.tcx.has_attr(def_id, sym::rustc_evaluate_where_clauses)
530+
&& find_attr!(
531+
self.tcx.get_all_attrs(def_id),
532+
AttributeKind::RustcEvaluateWhereClauses
533+
)
530534
{
531535
let predicates = self.tcx.predicates_of(def_id);
532536
let predicates = predicates.instantiate(self.tcx, args);

compiler/rustc_interface/src/passes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ use rustc_errors::timings::TimingSection;
1818
use rustc_expand::base::{ExtCtxt, LintStoreExpand};
1919
use rustc_feature::Features;
2020
use rustc_fs_util::try_canonicalize;
21-
use rustc_hir::Attribute;
2221
use rustc_hir::attrs::AttributeKind;
2322
use rustc_hir::def_id::{LOCAL_CRATE, StableCrateId, StableCrateIdMap};
2423
use rustc_hir::definitions::Definitions;
2524
use rustc_hir::limit::Limit;
25+
use rustc_hir::{Attribute, find_attr};
2626
use rustc_incremental::setup_dep_graph;
2727
use rustc_lint::{BufferedEarlyLint, EarlyCheckNode, LintStore, unerased_lint_store};
2828
use rustc_metadata::EncodedMetadata;
@@ -1227,7 +1227,7 @@ pub(crate) fn start_codegen<'tcx>(
12271227

12281228
// Hook for tests.
12291229
if let Some((def_id, _)) = tcx.entry_fn(())
1230-
&& tcx.has_attr(def_id, sym::rustc_delayed_bug_from_inside_query)
1230+
&& find_attr!(tcx.get_all_attrs(def_id), AttributeKind::RustcDelayedBugFromInsideQuery)
12311231
{
12321232
tcx.ensure_ok().trigger_delayed_bug(def_id);
12331233
}

compiler/rustc_passes/src/check_attr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
300300
| AttributeKind::RustcConfusables { .. }
301301
| AttributeKind::RustcConstStabilityIndirect
302302
| AttributeKind::RustcDeallocator
303+
| AttributeKind::RustcDelayedBugFromInsideQuery
303304
| AttributeKind::RustcDenyExplicitImpl(..)
304305
| AttributeKind::RustcDummy
305306
| AttributeKind::RustcDumpDefParents
@@ -309,6 +310,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
309310
| AttributeKind::RustcDumpVtable(..)
310311
| AttributeKind::RustcDynIncompatibleTrait(..)
311312
| AttributeKind::RustcEffectiveVisibility
313+
| AttributeKind::RustcEvaluateWhereClauses
312314
| AttributeKind::RustcHasIncoherentInherentImpls
313315
| AttributeKind::RustcHiddenTypeOfOpaques
314316
| AttributeKind::RustcIfThisChanged(..)
@@ -331,6 +333,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
331333
| AttributeKind::RustcObjcClass { .. }
332334
| AttributeKind::RustcObjcSelector { .. }
333335
| AttributeKind::RustcOffloadKernel
336+
| AttributeKind::RustcOutlives
334337
| AttributeKind::RustcParenSugar(..)
335338
| AttributeKind::RustcPassByValue (..)
336339
| AttributeKind::RustcPassIndirectlyInNonRusticAbis(..)
@@ -402,10 +405,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
402405
| sym::rustc_regions
403406
| sym::rustc_strict_coherence
404407
| sym::rustc_mir
405-
| sym::rustc_outlives
406408
| sym::rustc_symbol_name
407-
| sym::rustc_evaluate_where_clauses
408-
| sym::rustc_delayed_bug_from_inside_query
409409
| sym::rustc_def_path
410410
| sym::rustc_partition_reused
411411
| sym::rustc_partition_codegened

0 commit comments

Comments
 (0)