@@ -5,14 +5,14 @@ use rustc_errors::codes::*;
5
5
use rustc_errors::struct_span_code_err;
6
6
use rustc_hir as hir;
7
7
use rustc_hir::def::{DefKind, Res};
8
- use rustc_hir::def_id::{DefId, LocalDefId};
8
+ use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LocalDefId};
9
9
use rustc_hir::{AmbigArg, LangItem, PolyTraitRef};
10
10
use rustc_middle::bug;
11
11
use rustc_middle::ty::{
12
12
self as ty, IsSuggestable, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
13
13
TypeVisitor, Upcast,
14
14
};
15
- use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol, kw};
15
+ use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol, kw, sym };
16
16
use rustc_trait_selection::traits;
17
17
use smallvec::SmallVec;
18
18
use tracing::{debug, instrument};
@@ -188,6 +188,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
188
188
) {
189
189
let tcx = self.tcx();
190
190
191
+ // Skip adding any default bounds if `#![rustc_no_implicit_bounds]`
192
+ if tcx.has_attr(CRATE_DEF_ID, sym::rustc_no_implicit_bounds) {
193
+ return;
194
+ }
195
+
191
196
let meta_sized_did = tcx.require_lang_item(LangItem::MetaSized, span);
192
197
let pointee_sized_did = tcx.require_lang_item(LangItem::PointeeSized, span);
193
198
@@ -408,24 +413,21 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
408
413
let tcx = self.tcx();
409
414
let trait_id = tcx.lang_items().get(trait_);
410
415
if let Some(trait_id) = trait_id
411
- && self.do_not_provide_default_trait_bound(
412
- trait_id,
413
- hir_bounds,
414
- self_ty_where_predicates,
415
- )
416
+ && self.should_add_default_traits(trait_id, hir_bounds, self_ty_where_predicates)
416
417
{
417
418
add_trait_bound(tcx, bounds, self_ty, trait_id, span);
418
419
}
419
420
}
420
421
421
- fn do_not_provide_default_trait_bound<'a>(
422
+ /// Returns `true` if default trait bound should be added.
423
+ fn should_add_default_traits<'a>(
422
424
&self,
423
425
trait_def_id: DefId,
424
426
hir_bounds: &'a [hir::GenericBound<'tcx>],
425
427
self_ty_where_predicates: Option<(LocalDefId, &'tcx [hir::WherePredicate<'tcx>])>,
426
428
) -> bool {
427
429
let collected = collect_bounds(hir_bounds, self_ty_where_predicates, trait_def_id);
428
- !collected.any()
430
+ !self.tcx().has_attr(CRATE_DEF_ID, sym::rustc_no_implicit_bounds) && ! collected.any()
429
431
}
430
432
431
433
/// Lower HIR bounds into `bounds` given the self type `param_ty` and the overarching late-bound vars if any.
0 commit comments