diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2021-08-05 06:41:08 -0700 |
|---|---|---|
| committer | Esteban Kuber <esteban@kuber.com.ar> | 2021-08-12 10:24:01 +0000 |
| commit | a0bf7d2cd3751de2b49ec66701aaa7cc41345c35 (patch) | |
| tree | 9f40bc7f52743239c1c2acc7de67af3a5e65fe4f /compiler | |
| parent | eb2226b1f174f3cc644275ef8663be6295a7f704 (diff) | |
| download | rust-a0bf7d2cd3751de2b49ec66701aaa7cc41345c35.tar.gz rust-a0bf7d2cd3751de2b49ec66701aaa7cc41345c35.zip | |
Avoid ICE caused by suggestion
When suggesting dereferencing something that can be iterable in a `for` loop, erase lifetimes and use a fresh `ty::ParamEnv` to avoid 'region constraints already solved' panic. Fix #87657.
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_mir/src/borrow_check/diagnostics/move_errors.rs | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/move_errors.rs b/compiler/rustc_mir/src/borrow_check/diagnostics/move_errors.rs index 2be23159bf5..66e06325fa9 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/move_errors.rs +++ b/compiler/rustc_mir/src/borrow_check/diagnostics/move_errors.rs @@ -1,4 +1,5 @@ use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_infer::infer::TyCtxtInferExt; use rustc_middle::mir::*; use rustc_middle::ty; use rustc_span::source_map::DesugaringKind; @@ -409,13 +410,17 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { ); } else if matches!(span.desugaring_kind(), Some(DesugaringKind::ForLoop(_))) { let suggest = match self.infcx.tcx.get_diagnostic_item(sym::IntoIterator) { - Some(def_id) => type_known_to_meet_bound_modulo_regions( - &self.infcx, - self.param_env, - self.infcx.tcx.mk_imm_ref(self.infcx.tcx.lifetimes.re_erased, ty), - def_id, - DUMMY_SP, - ), + Some(def_id) => self.infcx.tcx.infer_ctxt().enter(|infcx| { + type_known_to_meet_bound_modulo_regions( + &infcx, + self.param_env, + infcx + .tcx + .mk_imm_ref(infcx.tcx.lifetimes.re_erased, infcx.tcx.erase_regions(ty)), + def_id, + DUMMY_SP, + ) + }), _ => false, }; if suggest { |
