Skip to content

Commit 6fc3e63

Browse files
committed
add hacky closure to struct_tail_with_normalize in order to allow us to walk valtrees in lockstep with the type
1 parent f7eae4e commit 6fc3e63

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

compiler/rustc_middle/src/ty/sty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2273,7 +2273,7 @@ impl<'tcx> Ty<'tcx> {
22732273
tcx: TyCtxt<'tcx>,
22742274
normalize: impl FnMut(Ty<'tcx>) -> Ty<'tcx>,
22752275
) -> (Ty<'tcx>, bool) {
2276-
let tail = tcx.struct_tail_with_normalize(self, normalize);
2276+
let tail = tcx.struct_tail_with_normalize(self, normalize, || {});
22772277
match tail.kind() {
22782278
// Sized types
22792279
ty::Infer(ty::IntVar(_) | ty::FloatVar(_))

compiler/rustc_middle/src/ty/util.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl<'tcx> TyCtxt<'tcx> {
187187
/// if input `ty` is not a structure at all.
188188
pub fn struct_tail_without_normalization(self, ty: Ty<'tcx>) -> Ty<'tcx> {
189189
let tcx = self;
190-
tcx.struct_tail_with_normalize(ty, |ty| ty)
190+
tcx.struct_tail_with_normalize(ty, |ty| ty, || {})
191191
}
192192

193193
/// Returns the deeply last field of nested structures, or the same type if
@@ -203,7 +203,7 @@ impl<'tcx> TyCtxt<'tcx> {
203203
param_env: ty::ParamEnv<'tcx>,
204204
) -> Ty<'tcx> {
205205
let tcx = self;
206-
tcx.struct_tail_with_normalize(ty, |ty| tcx.normalize_erasing_regions(param_env, ty))
206+
tcx.struct_tail_with_normalize(ty, |ty| tcx.normalize_erasing_regions(param_env, ty), || {})
207207
}
208208

209209
/// Returns the deeply last field of nested structures, or the same type if
@@ -220,6 +220,10 @@ impl<'tcx> TyCtxt<'tcx> {
220220
self,
221221
mut ty: Ty<'tcx>,
222222
mut normalize: impl FnMut(Ty<'tcx>) -> Ty<'tcx>,
223+
// This is a hack that is currently used to allow us to walk a ValTree
224+
// in lockstep with the type in order to get the ValTree branch that
225+
// corresponds to an unsized field.
226+
mut f: impl FnMut() -> (),
223227
) -> Ty<'tcx> {
224228
let recursion_limit = self.recursion_limit();
225229
for iteration in 0.. {
@@ -235,12 +239,16 @@ impl<'tcx> TyCtxt<'tcx> {
235239
break;
236240
}
237241
match def.non_enum_variant().fields.last() {
238-
Some(f) => ty = f.ty(self, substs),
242+
Some(field) => {
243+
f();
244+
ty = field.ty(self, substs);
245+
}
239246
None => break,
240247
}
241248
}
242249

243250
ty::Tuple(tys) if let Some((&last_ty, _)) = tys.split_last() => {
251+
f();
244252
ty = last_ty;
245253
}
246254

compiler/rustc_trait_selection/src/traits/project.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -1519,18 +1519,22 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
15191519
// Any type with multiple potential metadata types is therefore not eligible.
15201520
let self_ty = selcx.infcx().shallow_resolve(obligation.predicate.self_ty());
15211521

1522-
let tail = selcx.tcx().struct_tail_with_normalize(self_ty, |ty| {
1523-
// We throw away any obligations we get from this, since we normalize
1524-
// and confirm these obligations once again during confirmation
1525-
normalize_with_depth(
1526-
selcx,
1527-
obligation.param_env,
1528-
obligation.cause.clone(),
1529-
obligation.recursion_depth + 1,
1530-
ty,
1531-
)
1532-
.value
1533-
});
1522+
let tail = selcx.tcx().struct_tail_with_normalize(
1523+
self_ty,
1524+
|ty| {
1525+
// We throw away any obligations we get from this, since we normalize
1526+
// and confirm these obligations once again during confirmation
1527+
normalize_with_depth(
1528+
selcx,
1529+
obligation.param_env,
1530+
obligation.cause.clone(),
1531+
obligation.recursion_depth + 1,
1532+
ty,
1533+
)
1534+
.value
1535+
},
1536+
|| {},
1537+
);
15341538

15351539
match tail.kind() {
15361540
ty::Bool

0 commit comments

Comments
 (0)