Skip to content

Commit 4838fb8

Browse files
Rollup merge of rust-lang#152131 - Ozzy1423:attrs6, r=JonathanBrouwer
Port rustc_no_implicit_bounds attribute to parser. Tracking Issue: rust-lang#131229 r? @JonathanBrouwer
2 parents b3cbc75 + 2b22150 commit 4838fb8

File tree

6 files changed

+21
-5
lines changed

6 files changed

+21
-5
lines changed

compiler/rustc_attr_parsing/src/attributes/crate_level.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,12 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcPreserveUbChecksParser {
283283
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
284284
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcPreserveUbChecks;
285285
}
286+
287+
pub(crate) struct RustcNoImplicitBoundsParser;
288+
289+
impl<S: Stage> NoArgsAttributeParser<S> for RustcNoImplicitBoundsParser {
290+
const PATH: &[Symbol] = &[sym::rustc_no_implicit_bounds];
291+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
292+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
293+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcNoImplicitBounds;
294+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ attribute_parsers!(
282282
Single<WithoutArgs<RustcMainParser>>,
283283
Single<WithoutArgs<RustcNeverReturnsNullPointerParser>>,
284284
Single<WithoutArgs<RustcNoImplicitAutorefsParser>>,
285+
Single<WithoutArgs<RustcNoImplicitBoundsParser>>,
285286
Single<WithoutArgs<RustcNonConstTraitMethodParser>>,
286287
Single<WithoutArgs<RustcNounwindParser>>,
287288
Single<WithoutArgs<RustcOffloadKernelParser>>,

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,9 @@ pub enum AttributeKind {
11771177
/// Represents `#[rustc_no_implicit_autorefs]`
11781178
RustcNoImplicitAutorefs,
11791179

1180+
/// Represents `#[rustc_no_implicit_bounds]`
1181+
RustcNoImplicitBounds,
1182+
11801183
/// Represents `#[rustc_non_const_trait_method]`.
11811184
RustcNonConstTraitMethod,
11821185

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ impl AttributeKind {
137137
RustcMustImplementOneOf { .. } => No,
138138
RustcNeverReturnsNullPointer => Yes,
139139
RustcNoImplicitAutorefs => Yes,
140+
RustcNoImplicitBounds => No,
140141
RustcNonConstTraitMethod => No, // should be reported via other queries like `constness`
141142
RustcNounwind => No,
142143
RustcObjcClass { .. } => No,

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
44
use rustc_errors::codes::*;
55
use rustc_errors::struct_span_code_err;
66
use rustc_hir as hir;
7-
use rustc_hir::PolyTraitRef;
7+
use rustc_hir::attrs::AttributeKind;
88
use rustc_hir::def::{DefKind, Res};
99
use rustc_hir::def_id::{CRATE_DEF_ID, DefId};
10+
use rustc_hir::{PolyTraitRef, find_attr};
1011
use rustc_middle::bug;
1112
use rustc_middle::ty::{
1213
self as ty, IsSuggestable, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
1314
TypeVisitor, Upcast,
1415
};
15-
use rustc_span::{ErrorGuaranteed, Ident, Span, kw, sym};
16+
use rustc_span::{ErrorGuaranteed, Ident, Span, kw};
1617
use rustc_trait_selection::traits;
1718
use smallvec::SmallVec;
1819
use tracing::{debug, instrument};
@@ -170,7 +171,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
170171
let tcx = self.tcx();
171172

172173
// Skip adding any default bounds if `#![rustc_no_implicit_bounds]`
173-
if tcx.has_attr(CRATE_DEF_ID, sym::rustc_no_implicit_bounds) {
174+
if find_attr!(tcx.get_all_attrs(CRATE_DEF_ID), AttributeKind::RustcNoImplicitBounds) {
174175
return;
175176
}
176177

@@ -284,7 +285,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
284285
context: ImpliedBoundsContext<'tcx>,
285286
) -> bool {
286287
let collected = collect_bounds(hir_bounds, context, trait_def_id);
287-
!self.tcx().has_attr(CRATE_DEF_ID, sym::rustc_no_implicit_bounds) && !collected.any()
288+
!find_attr!(self.tcx().get_all_attrs(CRATE_DEF_ID), AttributeKind::RustcNoImplicitBounds)
289+
&& !collected.any()
288290
}
289291

290292
fn reject_duplicate_relaxed_bounds(&self, relaxed_bounds: SmallVec<[&PolyTraitRef<'_>; 1]>) {

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
330330
| AttributeKind::RustcMir(_)
331331
| AttributeKind::RustcNeverReturnsNullPointer
332332
| AttributeKind::RustcNoImplicitAutorefs
333+
| AttributeKind::RustcNoImplicitBounds
333334
| AttributeKind::RustcNonConstTraitMethod
334335
| AttributeKind::RustcNounwind
335336
| AttributeKind::RustcObjcClass { .. }
@@ -413,7 +414,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
413414
// crate-level attrs, are checked below
414415
| sym::feature
415416
| sym::register_tool
416-
| sym::rustc_no_implicit_bounds
417417
| sym::test_runner,
418418
..
419419
] => {}

0 commit comments

Comments
 (0)