@@ -122,8 +122,8 @@ fn collect_sizedness_bounds<'tcx>(
122122 ( CollectedSizednessBounds { sized, metasized, pointeesized } , unbounds)
123123}
124124
125- /// Add a trait bound for `did`.
126- fn add_trait_bound < ' tcx > (
125+ /// Add a trait predicate for `did`.
126+ fn add_trait_predicate < ' tcx > (
127127 tcx : TyCtxt < ' tcx > ,
128128 bounds : & mut Vec < ( ty:: Clause < ' tcx > , Span ) > ,
129129 self_ty : Ty < ' tcx > ,
@@ -136,6 +136,23 @@ fn add_trait_bound<'tcx>(
136136 bounds. insert ( 0 , ( trait_ref. upcast ( tcx) , span) ) ;
137137}
138138
139+ /// Add a host effect predicate for `did`.
140+ fn add_host_effect_predicate < ' tcx > (
141+ tcx : TyCtxt < ' tcx > ,
142+ bounds : & mut Vec < ( ty:: Clause < ' tcx > , Span ) > ,
143+ self_ty : Ty < ' tcx > ,
144+ did : DefId ,
145+ span : Span ,
146+ ) {
147+ let trait_ref = ty:: TraitRef :: new ( tcx, did, [ self_ty] ) ;
148+ let clause = ty:: ClauseKind :: HostEffect ( ty:: HostEffectPredicate {
149+ trait_ref,
150+ constness : ty:: BoundConstness :: Const ,
151+ } )
152+ . upcast ( tcx) ;
153+ bounds. insert ( 1 , ( clause, span) ) ;
154+ }
155+
139156/// Remove any bounds of `did`.
140157fn remove_lang_item_bound < ' tcx > ( bounds : & mut Vec < ( ty:: Clause < ' tcx > , Span ) > , did : DefId ) {
141158 let mut idx = None ;
@@ -171,8 +188,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
171188 remove_lang_item_bound ( bounds, pointeesized_did) ;
172189 }
173190
174- /// Adds a `MetaSized` bound to `bounds` (of a trait definition) if there are no other sizedness
175- /// bounds. Also removes `PointeeSized` params - see doc comment on
191+ /// Adds a `const MetaSized` bound to `bounds` (of a trait definition) if there are no other
192+ /// sizedness bounds. Also removes `PointeeSized` params - see doc comment on
176193 /// `adjust_sizedness_predicates`.
177194 pub ( crate ) fn adjust_sizedness_supertraits (
178195 & self ,
@@ -195,16 +212,18 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
195212
196213 let ( collected, _unbounds) = collect_sizedness_bounds ( tcx, hir_bounds, None , span) ;
197214 if !collected. any ( ) && trait_did != pointeesized_did {
198- // If there are no explicit sizedness bounds then add a default `MetaSized` supertrait.
199- add_trait_bound ( tcx, bounds, self_ty, metasized_did, span) ;
215+ // If there are no explicit sizedness bounds then add a default `const MetaSized`
216+ // supertrait.
217+ add_trait_predicate ( tcx, bounds, self_ty, metasized_did, span) ;
218+ add_host_effect_predicate ( tcx, bounds, self_ty, metasized_did, span) ;
200219 }
201220
202221 // See doc comment on `adjust_sizedness_predicates`.
203222 remove_lang_item_bound ( bounds, pointeesized_did) ;
204223 }
205224
206- /// Add a default `Sized` bound if there are no other sizedness bounds and rewrite `?Sized`
207- /// to `MetaSized`. Also removes `PointeeSized` params - see doc comment on
225+ /// Add a default `const Sized` bound if there are no other sizedness bounds and rewrite
226+ /// `?Sized` to `MetaSized`. Also removes `PointeeSized` params - see doc comment on
208227 /// `adjust_sizedness_predicates`.
209228 pub ( crate ) fn adjust_sizedness_params_and_assoc_types (
210229 & self ,
@@ -229,12 +248,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
229248 && !collected. metasized . any ( )
230249 && !collected. pointeesized . any ( )
231250 {
232- // `?Sized` is equivalent to `MetaSized` (but only add the bound if there aren't any
233- // other explicit ones)
234- add_trait_bound ( tcx, bounds, self_ty, metasized_did, span) ;
251+ // `?Sized` is equivalent to `const MetaSized` (but only add the bound if there aren't
252+ // any other explicit ones)
253+ add_trait_predicate ( tcx, bounds, self_ty, metasized_did, span) ;
254+ add_host_effect_predicate ( tcx, bounds, self_ty, metasized_did, span) ;
235255 } else if !collected. any ( ) {
236- // If there are no explicit sizedness bounds then add a default `Sized` bound.
237- add_trait_bound ( tcx, bounds, self_ty, sized_did, span) ;
256+ // If there are no explicit sizedness bounds then add a default `const Sized` bound.
257+ add_trait_predicate ( tcx, bounds, self_ty, sized_did, span) ;
258+ add_host_effect_predicate ( tcx, bounds, self_ty, sized_did, span) ;
238259 }
239260
240261 // See doc comment on `adjust_sizedness_predicates`.
0 commit comments