address nits

This commit is contained in:
Lukas Markeffsky 2024-03-18 22:28:29 +01:00
parent ee66acbea8
commit 99efae342e
4 changed files with 18 additions and 17 deletions

View file

@ -704,7 +704,7 @@ rustc_queries! {
} }
query adt_sized_constraint(key: DefId) -> Option<ty::EarlyBinder<Ty<'tcx>>> { query adt_sized_constraint(key: DefId) -> Option<ty::EarlyBinder<Ty<'tcx>>> {
desc { |tcx| "computing `Sized` constraint for `{}`", tcx.def_path_str(key) } desc { |tcx| "computing the `Sized` constraint for `{}`", tcx.def_path_str(key) }
} }
query adt_dtorck_constraint( query adt_dtorck_constraint(

View file

@ -168,10 +168,11 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_sized_trait<'tcx>(
// "best effort" optimization and `sized_constraint` may return `Some`, even // "best effort" optimization and `sized_constraint` may return `Some`, even
// if the ADT is sized for all possible args. // if the ADT is sized for all possible args.
ty::Adt(def, args) => { ty::Adt(def, args) => {
let sized_crit = def.sized_constraint(ecx.tcx()); if let Some(sized_crit) = def.sized_constraint(ecx.tcx()) {
Ok(sized_crit.map_or_else(Vec::new, |ty| { Ok(vec![ty::Binder::dummy(sized_crit.instantiate(ecx.tcx(), args))])
vec![ty::Binder::dummy(ty.instantiate(ecx.tcx(), args))] } else {
})) Ok(vec![])
}
} }
} }
} }

View file

@ -2118,11 +2118,14 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
), ),
ty::Adt(def, args) => { ty::Adt(def, args) => {
let sized_crit = def.sized_constraint(self.tcx()); if let Some(sized_crit) = def.sized_constraint(self.tcx()) {
// (*) binder moved here // (*) binder moved here
Where(obligation.predicate.rebind( Where(
sized_crit.map_or_else(Vec::new, |ty| vec![ty.instantiate(self.tcx(), args)]), obligation.predicate.rebind(vec![sized_crit.instantiate(self.tcx(), args)]),
)) )
} else {
Where(ty::Binder::dummy(Vec::new()))
}
} }
ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) => None, ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) => None,

View file

@ -39,13 +39,10 @@ fn sized_constraint_for_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Ty<'
Tuple(tys) => tys.last().and_then(|&ty| sized_constraint_for_ty(tcx, ty)), Tuple(tys) => tys.last().and_then(|&ty| sized_constraint_for_ty(tcx, ty)),
// recursive case // recursive case
Adt(adt, args) => { Adt(adt, args) => adt.sized_constraint(tcx).and_then(|intermediate| {
let intermediate = adt.sized_constraint(tcx); let ty = intermediate.instantiate(tcx, args);
intermediate.and_then(|intermediate| { sized_constraint_for_ty(tcx, ty)
let ty = intermediate.instantiate(tcx, args); }),
sized_constraint_for_ty(tcx, ty)
})
}
// these can be sized or unsized // these can be sized or unsized
Param(..) | Alias(..) | Error(_) => Some(ty), Param(..) | Alias(..) | Error(_) => Some(ty),