Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions compiler/rustc_traits/src/normalize_erasing_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with this, but I'm not sure if this is what @lcnr meant -- I suspect they meant to move the resolve_vars_if_possible into the debug assert as well. I guess that I mildly prefer this in that I don't think it's generally meant to be an invariant that functions will return "fully resolved" types that don't contain inference variables.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the approach by @jyn514 is good as it doesn't even change the behavior, so it most definity can't break anything

I would keep it as is, even if it isn't what i originally intended

let erased = infcx.tcx.erase_regions(resolved_value);
debug_assert!(!erased.needs_infer(), "{:?}", erased);
erased
}
Err(NoSolution) => bug!("could not fully normalize `{:?}`", value),
}
Expand Down