@@ -11,7 +11,7 @@ use rustc_hir::intravisit::{self, Visitor};
1111use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
1212use rustc_middle:: ty:: { GenericPredicates , ImplTraitInTraitData , ToPredicate } ;
1313use rustc_span:: symbol:: Ident ;
14- use rustc_span:: { Span , DUMMY_SP } ;
14+ use rustc_span:: { sym , Span , DUMMY_SP } ;
1515
1616/// Returns a list of all type predicates (explicit and implicit) for the definition with
1717/// ID `def_id`. This includes all predicates returned by `predicates_defined_on`, plus
@@ -38,11 +38,38 @@ pub(super) fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredic
3838 // an obligation and instead be skipped. Otherwise we'd use
3939 // `tcx.def_span(def_id);`
4040 let span = rustc_span:: DUMMY_SP ;
41- result. predicates =
42- tcx. arena . alloc_from_iter ( result. predicates . iter ( ) . copied ( ) . chain ( std:: iter:: once ( (
43- ty:: TraitRef :: identity ( tcx, def_id) . to_predicate ( tcx) ,
41+ let non_const_bound = if tcx. features ( ) . effects && tcx. has_attr ( def_id, sym:: const_trait) {
42+ // when `Self` is a const trait, also add `Self: Trait<.., true>` as implied bound,
43+ // because only implementing `Self: Trait<.., false>` is currently not possible.
44+ Some ( (
45+ ty:: TraitRef :: new (
46+ tcx,
47+ def_id,
48+ ty:: GenericArgs :: for_item ( tcx, def_id, |param, _| {
49+ if param. is_host_effect ( ) {
50+ tcx. consts . true_ . into ( )
51+ } else {
52+ tcx. mk_param_from_def ( param)
53+ }
54+ } ) ,
55+ )
56+ . to_predicate ( tcx) ,
4457 span,
45- ) ) ) ) ;
58+ ) )
59+ } else {
60+ None
61+ } ;
62+ result. predicates = tcx. arena . alloc_from_iter (
63+ result
64+ . predicates
65+ . iter ( )
66+ . copied ( )
67+ . chain ( std:: iter:: once ( (
68+ ty:: TraitRef :: identity ( tcx, def_id) . to_predicate ( tcx) ,
69+ span,
70+ ) ) )
71+ . chain ( non_const_bound) ,
72+ ) ;
4673 }
4774 debug ! ( "predicates_of(def_id={:?}) = {:?}" , def_id, result) ;
4875 result
0 commit comments