Skip to content

Commit 8bea6ea

Browse files
committed
Port rustc_no_implicit_bounds attribute to parser.
1 parent c6936c3 commit 8bea6ea

6 files changed

Lines changed: 19 additions & 4 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
@@ -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
@@ -281,6 +281,7 @@ attribute_parsers!(
281281
Single<WithoutArgs<RustcMainParser>>,
282282
Single<WithoutArgs<RustcNeverReturnsNullPointerParser>>,
283283
Single<WithoutArgs<RustcNoImplicitAutorefsParser>>,
284+
Single<WithoutArgs<RustcNoImplicitBoundsParser>>,
284285
Single<WithoutArgs<RustcNonConstTraitMethodParser>>,
285286
Single<WithoutArgs<RustcNounwindParser>>,
286287
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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_middle::ty::{
1212
self as ty, IsSuggestable, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
1313
TypeVisitor, Upcast,
1414
};
15-
use rustc_span::{ErrorGuaranteed, Ident, Span, kw, sym};
15+
use rustc_span::{ErrorGuaranteed, Ident, Span, kw};
1616
use rustc_trait_selection::traits;
1717
use smallvec::SmallVec;
1818
use tracing::{debug, instrument};
@@ -170,7 +170,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
170170
let tcx = self.tcx();
171171

172172
// Skip adding any default bounds if `#![rustc_no_implicit_bounds]`
173-
if tcx.has_attr(CRATE_DEF_ID, sym::rustc_no_implicit_bounds) {
173+
if find_attr!(tcx.get_all_attrs(CRATE_DEF_ID), AttributeKind::RustcNoImplicitBounds) {
174174
return;
175175
}
176176

@@ -284,7 +284,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
284284
context: ImpliedBoundsContext<'tcx>,
285285
) -> bool {
286286
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()
287+
!find_attr!(self.tcx().get_all_attrs(CRATE_DEF_ID), AttributeKind::RustcNoImplicitBounds)
288+
&& !collected.any()
288289
}
289290

290291
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)