Skip to content

Commit 2dea8ec

Browse files
committed
Do not initiate nested probe within assemble_probe.
In particular, the table entries (associated with type-variables created during the probe) must persist as long as the candidates assembled during the probe. If you make a nested probe without creating a nested `ProbeContext`, the table entries are popped at the end of the nested probe, while the type-variables would leak out via the assembled candidates attached to `self` (the outer `ProbeContext`). This causes an ICE (*if you are lucky*)!
1 parent 38650b6 commit 2dea8ec

File tree

1 file changed

+7
-9
lines changed
  • src/librustc_typeck/check/method

1 file changed

+7
-9
lines changed

src/librustc_typeck/check/method/probe.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -506,15 +506,13 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
506506
match self_ty.value.value.sty {
507507
ty::Dynamic(ref data, ..) => {
508508
if let Some(p) = data.principal() {
509-
self.fcx.probe(|_| {
510-
let InferOk { value: self_ty, obligations: _ } =
511-
self.fcx.probe_instantiate_query_response(
512-
self.span, &self.orig_steps_var_values, self_ty)
513-
.unwrap_or_else(|_| {
514-
span_bug!(self.span, "{:?} was applicable but now isn't?", self_ty)
515-
});
516-
self.assemble_inherent_candidates_from_object(self_ty);
517-
});
509+
let InferOk { value: instantiated_self_ty, obligations: _ } =
510+
self.fcx.probe_instantiate_query_response(
511+
self.span, &self.orig_steps_var_values, self_ty)
512+
.unwrap_or_else(|_| {
513+
span_bug!(self.span, "{:?} was applicable but now isn't?", self_ty)
514+
});
515+
self.assemble_inherent_candidates_from_object(instantiated_self_ty);
518516
self.assemble_inherent_impl_candidates_for_type(p.def_id());
519517
}
520518
}

0 commit comments

Comments
 (0)