@@ -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} ;
@@ -191,6 +191,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
191
191
let meta_sized_did = tcx. require_lang_item ( LangItem :: MetaSized , span) ;
192
192
let pointee_sized_did = tcx. require_lang_item ( LangItem :: PointeeSized , span) ;
193
193
194
+ // Skip adding any default bounds if `#![rustc_no_implicit_bounds]`
195
+ if tcx. has_attr ( CRATE_DEF_ID , sym:: rustc_no_implicit_bounds) {
196
+ return ;
197
+ }
198
+
194
199
// If adding sizedness bounds to a trait, then there are some relevant early exits
195
200
if let Some ( trait_did) = trait_did {
196
201
let trait_did = trait_did. to_def_id ( ) ;
@@ -408,7 +413,7 @@ 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 (
416
+ && ! self . do_not_provide_default_trait_bound (
412
417
trait_id,
413
418
hir_bounds,
414
419
self_ty_where_predicates,
@@ -418,14 +423,15 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
418
423
}
419
424
}
420
425
426
+ /// Returns `true` if default trait bound should not be added.
421
427
fn do_not_provide_default_trait_bound < ' a > (
422
428
& self ,
423
429
trait_def_id : DefId ,
424
430
hir_bounds : & ' a [ hir:: GenericBound < ' tcx > ] ,
425
431
self_ty_where_predicates : Option < ( LocalDefId , & ' tcx [ hir:: WherePredicate < ' tcx > ] ) > ,
426
432
) -> bool {
427
433
let collected = collect_bounds ( hir_bounds, self_ty_where_predicates, trait_def_id) ;
428
- ! collected. any ( )
434
+ self . tcx ( ) . has_attr ( CRATE_DEF_ID , sym :: rustc_no_implicit_bounds ) || collected. any ( )
429
435
}
430
436
431
437
/// Lower HIR bounds into `bounds` given the self type `param_ty` and the overarching late-bound vars if any.
0 commit comments