From 2dea8ec630eebabee46bc51b3ea14fe5e88834c1 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Tue, 22 Jan 2019 13:51:30 +0100 Subject: [PATCH 1/2] 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*)! --- src/librustc_typeck/check/method/probe.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 9a828ce0177..b849be52a92 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -506,15 +506,13 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { match self_ty.value.value.sty { ty::Dynamic(ref data, ..) => { if let Some(p) = data.principal() { - self.fcx.probe(|_| { - let InferOk { value: self_ty, obligations: _ } = - self.fcx.probe_instantiate_query_response( - self.span, &self.orig_steps_var_values, self_ty) - .unwrap_or_else(|_| { - span_bug!(self.span, "{:?} was applicable but now isn't?", self_ty) - }); - self.assemble_inherent_candidates_from_object(self_ty); - }); + let InferOk { value: instantiated_self_ty, obligations: _ } = + self.fcx.probe_instantiate_query_response( + self.span, &self.orig_steps_var_values, self_ty) + .unwrap_or_else(|_| { + span_bug!(self.span, "{:?} was applicable but now isn't?", self_ty) + }); + self.assemble_inherent_candidates_from_object(instantiated_self_ty); self.assemble_inherent_impl_candidates_for_type(p.def_id()); } } From 33c2ceb3a2b769fb3f2f6019b1071439f0dc6444 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Tue, 22 Jan 2019 14:49:18 +0100 Subject: [PATCH 2/2] unit test for issue 57673. --- .../issue-57673-ice-on-deref-of-boxed-trait.rs | 7 +++++++ .../issue-57673-ice-on-deref-of-boxed-trait.stderr | 14 ++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 src/test/ui/typeck/issue-57673-ice-on-deref-of-boxed-trait.rs create mode 100644 src/test/ui/typeck/issue-57673-ice-on-deref-of-boxed-trait.stderr diff --git a/src/test/ui/typeck/issue-57673-ice-on-deref-of-boxed-trait.rs b/src/test/ui/typeck/issue-57673-ice-on-deref-of-boxed-trait.rs new file mode 100644 index 00000000000..0a4e7da2bff --- /dev/null +++ b/src/test/ui/typeck/issue-57673-ice-on-deref-of-boxed-trait.rs @@ -0,0 +1,7 @@ +//extern crate has_assoc_type; + +//fn ice(x: Box>) { +fn ice(x: Box>) { + *x //~ ERROR mismatched types [E0308] +} +fn main() {} diff --git a/src/test/ui/typeck/issue-57673-ice-on-deref-of-boxed-trait.stderr b/src/test/ui/typeck/issue-57673-ice-on-deref-of-boxed-trait.stderr new file mode 100644 index 00000000000..bb63917fc08 --- /dev/null +++ b/src/test/ui/typeck/issue-57673-ice-on-deref-of-boxed-trait.stderr @@ -0,0 +1,14 @@ +error[E0308]: mismatched types + --> $DIR/issue-57673-ice-on-deref-of-boxed-trait.rs:5:5 + | +LL | fn ice(x: Box>) { + | - possibly return type missing here? +LL | *x //~ ERROR mismatched types [E0308] + | ^^ expected (), found trait std::iter::Iterator + | + = note: expected type `()` + found type `(dyn std::iter::Iterator + 'static)` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`.