From 6354e85e8ff51effe520d358b0810b69f7ecc7cf Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Tue, 6 Oct 2020 11:17:29 -0400 Subject: [PATCH] Don't run `resolve_vars_if_possible` in `normalize_erasing_regions` NOTE: `needs_infer()` needs to come after ignoring generic parameters --- .../rustc_traits/src/normalize_erasing_regions.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_traits/src/normalize_erasing_regions.rs b/compiler/rustc_traits/src/normalize_erasing_regions.rs index 750a0922be4d1..4841e4286a994 100644 --- a/compiler/rustc_traits/src/normalize_erasing_regions.rs +++ b/compiler/rustc_traits/src/normalize_erasing_regions.rs @@ -2,7 +2,7 @@ use rustc_infer::infer::TyCtxtInferExt; use rustc_middle::traits::query::NoSolution; use rustc_middle::ty::query::Providers; use rustc_middle::ty::subst::GenericArg; -use rustc_middle::ty::{self, ParamEnvAnd, TyCtxt}; +use rustc_middle::ty::{self, ParamEnvAnd, TyCtxt, TypeFoldable}; use rustc_trait_selection::traits::query::normalize::AtExt; use rustc_trait_selection::traits::{Normalized, ObligationCause}; use std::sync::atomic::Ordering; @@ -31,8 +31,14 @@ fn normalize_generic_arg_after_erasing_regions<'tcx>( None, ); - let normalized_value = infcx.resolve_vars_if_possible(normalized_value); - infcx.tcx.erase_regions(normalized_value) + let resolved_value = infcx.resolve_vars_if_possible(normalized_value); + // It's unclear when `resolve_vars` would have an effect in a + // fresh `InferCtxt`. If this assert does trigger, it will give + // us a test case. + debug_assert_eq!(normalized_value, resolved_value); + let erased = infcx.tcx.erase_regions(resolved_value); + debug_assert!(!erased.needs_infer(), "{:?}", erased); + erased } Err(NoSolution) => bug!("could not fully normalize `{:?}`", value), }