@@ -5,9 +5,9 @@ use rustc_infer::traits::{
55} ;
66use rustc_middle:: span_bug;
77use rustc_middle:: ty:: fast_reject:: DeepRejectCtxt ;
8- use rustc_middle:: ty:: { self , TypingMode } ;
8+ use rustc_middle:: ty:: { self , TypeVisitableExt , TypingMode } ;
99use rustc_type_ir:: elaborate:: elaborate;
10- use rustc_type_ir:: solve:: NoSolution ;
10+ use rustc_type_ir:: solve:: { NoSolution , Sizedness } ;
1111use thin_vec:: { ThinVec , thin_vec} ;
1212
1313use super :: SelectionContext ;
@@ -242,10 +242,45 @@ fn evaluate_host_effect_from_builtin_impls<'tcx>(
242242) -> Result < ThinVec < PredicateObligation < ' tcx > > , EvaluationFailure > {
243243 match selcx. tcx ( ) . as_lang_item ( obligation. predicate . def_id ( ) ) {
244244 Some ( LangItem :: Destruct ) => evaluate_host_effect_for_destruct_goal ( selcx, obligation) ,
245+ Some ( LangItem :: Sized ) => {
246+ evaluate_host_effect_for_sizedness_goal ( selcx, obligation, Sizedness :: Sized )
247+ }
248+ Some ( LangItem :: MetaSized ) => {
249+ evaluate_host_effect_for_sizedness_goal ( selcx, obligation, Sizedness :: MetaSized )
250+ }
251+ Some ( LangItem :: PointeeSized ) => {
252+ evaluate_host_effect_for_sizedness_goal ( selcx, obligation, Sizedness :: PointeeSized )
253+ }
245254 _ => Err ( EvaluationFailure :: NoSolution ) ,
246255 }
247256}
248257
258+ // NOTE: Keep this in sync with `const_conditions_for_sizedness` in the new solver.
259+ fn evaluate_host_effect_for_sizedness_goal < ' tcx > (
260+ selcx : & mut SelectionContext < ' _ , ' tcx > ,
261+ obligation : & HostEffectObligation < ' tcx > ,
262+ sizedness : Sizedness ,
263+ ) -> Result < ThinVec < PredicateObligation < ' tcx > > , EvaluationFailure > {
264+ let tcx = selcx. tcx ( ) ;
265+ let self_ty = obligation. predicate . self_ty ( ) ;
266+
267+ if !self_ty. has_non_const_sizedness ( ) && matches ! ( sizedness, Sizedness :: Sized ) {
268+ let metasized_def_id = tcx. require_lang_item ( LangItem :: MetaSized , None ) ;
269+ let metasized_trait_ref = ty:: TraitRef :: new ( tcx, metasized_def_id, [ self_ty] ) ;
270+ let metasized_obligation = obligation. with (
271+ tcx,
272+ ty:: Binder :: dummy ( metasized_trait_ref)
273+ . to_host_effect_clause ( tcx, obligation. predicate . constness ) ,
274+ ) ;
275+ Ok ( thin_vec ! [ metasized_obligation] )
276+ } else if !self_ty. has_non_const_sizedness ( ) {
277+ // `MetaSized` has no conditionally const supertrait
278+ Ok ( thin_vec ! [ ] )
279+ } else {
280+ Err ( EvaluationFailure :: NoSolution )
281+ }
282+ }
283+
249284// NOTE: Keep this in sync with `const_conditions_for_destruct` in the new solver.
250285fn evaluate_host_effect_for_destruct_goal < ' tcx > (
251286 selcx : & mut SelectionContext < ' _ , ' tcx > ,
0 commit comments