Skip to content

Commit 99efae3

Browse files
author
Lukas Markeffsky
committed
address nits
1 parent ee66acb commit 99efae3

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ rustc_queries! {
704704
}
705705

706706
query adt_sized_constraint(key: DefId) -> Option<ty::EarlyBinder<Ty<'tcx>>> {
707-
desc { |tcx| "computing `Sized` constraint for `{}`", tcx.def_path_str(key) }
707+
desc { |tcx| "computing the `Sized` constraint for `{}`", tcx.def_path_str(key) }
708708
}
709709

710710
query adt_dtorck_constraint(

compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,11 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_sized_trait<'tcx>(
168168
// "best effort" optimization and `sized_constraint` may return `Some`, even
169169
// if the ADT is sized for all possible args.
170170
ty::Adt(def, args) => {
171-
let sized_crit = def.sized_constraint(ecx.tcx());
172-
Ok(sized_crit.map_or_else(Vec::new, |ty| {
173-
vec![ty::Binder::dummy(ty.instantiate(ecx.tcx(), args))]
174-
}))
171+
if let Some(sized_crit) = def.sized_constraint(ecx.tcx()) {
172+
Ok(vec![ty::Binder::dummy(sized_crit.instantiate(ecx.tcx(), args))])
173+
} else {
174+
Ok(vec![])
175+
}
175176
}
176177
}
177178
}

compiler/rustc_trait_selection/src/traits/select/mod.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -2118,11 +2118,14 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
21182118
),
21192119

21202120
ty::Adt(def, args) => {
2121-
let sized_crit = def.sized_constraint(self.tcx());
2122-
// (*) binder moved here
2123-
Where(obligation.predicate.rebind(
2124-
sized_crit.map_or_else(Vec::new, |ty| vec![ty.instantiate(self.tcx(), args)]),
2125-
))
2121+
if let Some(sized_crit) = def.sized_constraint(self.tcx()) {
2122+
// (*) binder moved here
2123+
Where(
2124+
obligation.predicate.rebind(vec![sized_crit.instantiate(self.tcx(), args)]),
2125+
)
2126+
} else {
2127+
Where(ty::Binder::dummy(Vec::new()))
2128+
}
21262129
}
21272130

21282131
ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) => None,

compiler/rustc_ty_utils/src/ty.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,10 @@ fn sized_constraint_for_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Ty<'
3939
Tuple(tys) => tys.last().and_then(|&ty| sized_constraint_for_ty(tcx, ty)),
4040

4141
// recursive case
42-
Adt(adt, args) => {
43-
let intermediate = adt.sized_constraint(tcx);
44-
intermediate.and_then(|intermediate| {
45-
let ty = intermediate.instantiate(tcx, args);
46-
sized_constraint_for_ty(tcx, ty)
47-
})
48-
}
42+
Adt(adt, args) => adt.sized_constraint(tcx).and_then(|intermediate| {
43+
let ty = intermediate.instantiate(tcx, args);
44+
sized_constraint_for_ty(tcx, ty)
45+
}),
4946

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

0 commit comments

Comments
 (0)