@@ -122,8 +122,8 @@ fn collect_sizedness_bounds<'tcx>(
122
122
( CollectedSizednessBounds { sized, metasized, pointeesized } , unbounds)
123
123
}
124
124
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 > (
127
127
tcx : TyCtxt < ' tcx > ,
128
128
bounds : & mut Vec < ( ty:: Clause < ' tcx > , Span ) > ,
129
129
self_ty : Ty < ' tcx > ,
@@ -136,6 +136,23 @@ fn add_trait_bound<'tcx>(
136
136
bounds. insert ( 0 , ( trait_ref. upcast ( tcx) , span) ) ;
137
137
}
138
138
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
+
139
156
/// Remove any bounds of `did`.
140
157
fn remove_lang_item_bound < ' tcx > ( bounds : & mut Vec < ( ty:: Clause < ' tcx > , Span ) > , did : DefId ) {
141
158
let mut idx = None ;
@@ -171,8 +188,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
171
188
remove_lang_item_bound ( bounds, pointeesized_did) ;
172
189
}
173
190
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
176
193
/// `adjust_sizedness_predicates`.
177
194
pub ( crate ) fn adjust_sizedness_supertraits (
178
195
& self ,
@@ -195,16 +212,18 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
195
212
196
213
let ( collected, _unbounds) = collect_sizedness_bounds ( tcx, hir_bounds, None , span) ;
197
214
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) ;
200
219
}
201
220
202
221
// See doc comment on `adjust_sizedness_predicates`.
203
222
remove_lang_item_bound ( bounds, pointeesized_did) ;
204
223
}
205
224
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
208
227
/// `adjust_sizedness_predicates`.
209
228
pub ( crate ) fn adjust_sizedness_params_and_assoc_types (
210
229
& self ,
@@ -229,12 +248,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
229
248
&& !collected. metasized . any ( )
230
249
&& !collected. pointeesized . any ( )
231
250
{
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) ;
235
255
} 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) ;
238
259
}
239
260
240
261
// See doc comment on `adjust_sizedness_predicates`.
0 commit comments