Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean up Sized checking #122493

Merged
merged 5 commits into from
Mar 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
address nits
  • Loading branch information
Lukas Markeffsky committed Mar 18, 2024
commit 99efae342e8581d12f9017affba2a229a2cfa152
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
@@ -704,7 +704,7 @@ rustc_queries! {
}

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(
Original file line number Diff line number Diff line change
@@ -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
// if the ADT is sized for all possible args.
ty::Adt(def, args) => {
let sized_crit = def.sized_constraint(ecx.tcx());
Ok(sized_crit.map_or_else(Vec::new, |ty| {
vec![ty::Binder::dummy(ty.instantiate(ecx.tcx(), args))]
}))
if let Some(sized_crit) = def.sized_constraint(ecx.tcx()) {
Ok(vec![ty::Binder::dummy(sized_crit.instantiate(ecx.tcx(), args))])
} else {
Ok(vec![])
}
}
}
}
13 changes: 8 additions & 5 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
@@ -2118,11 +2118,14 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
),

ty::Adt(def, args) => {
let sized_crit = def.sized_constraint(self.tcx());
// (*) binder moved here
Where(obligation.predicate.rebind(
sized_crit.map_or_else(Vec::new, |ty| vec![ty.instantiate(self.tcx(), args)]),
))
if let Some(sized_crit) = def.sized_constraint(self.tcx()) {
// (*) binder moved here
Where(
obligation.predicate.rebind(vec![sized_crit.instantiate(self.tcx(), args)]),
)
} else {
Where(ty::Binder::dummy(Vec::new()))
}
}

ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) => None,
11 changes: 4 additions & 7 deletions compiler/rustc_ty_utils/src/ty.rs
Original file line number Diff line number Diff line change
@@ -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)),

// recursive case
Adt(adt, args) => {
let intermediate = adt.sized_constraint(tcx);
intermediate.and_then(|intermediate| {
let ty = intermediate.instantiate(tcx, args);
sized_constraint_for_ty(tcx, ty)
})
}
Adt(adt, args) => adt.sized_constraint(tcx).and_then(|intermediate| {
let ty = intermediate.instantiate(tcx, args);
sized_constraint_for_ty(tcx, ty)
}),

// these can be sized or unsized
Param(..) | Alias(..) | Error(_) => Some(ty),
Loading