clean up ADT sized constraint computation

This commit is contained in:
Lukas Markeffsky
2024-03-13 23:33:45 +01:00
parent 0e7e1bfdbc
commit 8ad94111ad
8 changed files with 90 additions and 92 deletions

View File

@@ -703,8 +703,8 @@ rustc_queries! {
separate_provide_extern
}
query adt_sized_constraint(key: DefId) -> ty::EarlyBinder<&'tcx ty::List<Ty<'tcx>>> {
desc { |tcx| "computing `Sized` constraints for `{}`", tcx.def_path_str(key) }
query adt_sized_constraint(key: DefId) -> Option<ty::EarlyBinder<Ty<'tcx>>> {
desc { |tcx| "computing `Sized` constraint for `{}`", tcx.def_path_str(key) }
}
query adt_dtorck_constraint(

View File

@@ -590,10 +590,10 @@ impl<'tcx> AdtDef<'tcx> {
tcx.adt_destructor(self.did())
}
/// Returns a list of types such that `Self: Sized` if and only if that
/// type is `Sized`, or `ty::Error` if this type has a recursive layout.
pub fn sized_constraint(self, tcx: TyCtxt<'tcx>) -> ty::EarlyBinder<&'tcx ty::List<Ty<'tcx>>> {
tcx.adt_sized_constraint(self.did())
/// Returns a type such that `Self: Sized` if and only if that type is `Sized`,
/// or `None` if the type is always sized.
pub fn sized_constraint(self, tcx: TyCtxt<'tcx>) -> Option<ty::EarlyBinder<Ty<'tcx>>> {
if self.is_struct() { tcx.adt_sized_constraint(self.did()) } else { None }
}
}

View File

@@ -2490,7 +2490,7 @@ impl<'tcx> Ty<'tcx> {
ty::Tuple(tys) => tys.iter().all(|ty| ty.is_trivially_sized(tcx)),
ty::Adt(def, _args) => def.sized_constraint(tcx).skip_binder().is_empty(),
ty::Adt(def, _args) => def.sized_constraint(tcx).is_none(),
ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) | ty::Bound(..) => false,