Skip to content

Commit 8250eef

Browse files
committed
normalize_generic_arg_after in terms of try version
1 parent 1796de7 commit 8250eef

File tree

1 file changed

+11
-34
lines changed

1 file changed

+11
-34
lines changed

compiler/rustc_traits/src/normalize_erasing_regions.rs

+11-34
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,19 @@ crate fn provide(p: &mut Providers) {
1515
.perf_stats
1616
.normalize_generic_arg_after_erasing_regions
1717
.fetch_add(1, Ordering::Relaxed);
18-
normalize_after_erasing_regions(tcx, goal)
18+
19+
let (param_env, goal) = goal.into_parts();
20+
tcx.try_normalize_erasing_regions(param_env, goal).unwrap_or_else(|_| bug!(
21+
"Failed to normalize {:?}, maybe try to call `try_normalize_erasing_regions` instead",
22+
goal
23+
))
1924
},
2025
normalize_mir_const_after_erasing_regions: |tcx, goal| {
21-
normalize_after_erasing_regions(tcx, goal)
26+
let (param_env, goal) = goal.into_parts();
27+
tcx.try_normalize_erasing_regions(param_env, goal).unwrap_or_else(|_| bug!(
28+
"Failed to normalize {:?}, maybe try to call `try_normalize_erasing_regions` instead",
29+
goal
30+
))
2231
},
2332
try_normalize_generic_arg_after_erasing_regions: |tcx, goal| {
2433
debug!("try_normalize_generic_arg_after_erasing_regions(goal={:#?}", goal);
@@ -32,38 +41,6 @@ crate fn provide(p: &mut Providers) {
3241
};
3342
}
3443

35-
#[instrument(level = "debug", skip(tcx))]
36-
fn normalize_after_erasing_regions<'tcx, T: TypeFoldable<'tcx> + PartialEq + Copy>(
37-
tcx: TyCtxt<'tcx>,
38-
goal: ParamEnvAnd<'tcx, T>,
39-
) -> T {
40-
let ParamEnvAnd { param_env, value } = goal;
41-
tcx.infer_ctxt().enter(|infcx| {
42-
let cause = ObligationCause::dummy();
43-
match infcx.at(&cause, param_env).normalize(value) {
44-
Ok(Normalized { value: normalized_value, obligations: normalized_obligations }) => {
45-
// We don't care about the `obligations`; they are
46-
// always only region relations, and we are about to
47-
// erase those anyway:
48-
debug_assert_eq!(
49-
normalized_obligations.iter().find(|p| not_outlives_predicate(&p.predicate)),
50-
None,
51-
);
52-
53-
let resolved_value = infcx.resolve_vars_if_possible(normalized_value);
54-
// It's unclear when `resolve_vars` would have an effect in a
55-
// fresh `InferCtxt`. If this assert does trigger, it will give
56-
// us a test case.
57-
debug_assert_eq!(normalized_value, resolved_value);
58-
let erased = infcx.tcx.erase_regions(resolved_value);
59-
debug_assert!(!erased.needs_infer(), "{:?}", erased);
60-
erased
61-
}
62-
Err(NoSolution) => bug!("could not fully normalize `{:?}`", value),
63-
}
64-
})
65-
}
66-
6744
#[instrument(level = "debug", skip(tcx))]
6845
fn try_normalize_after_erasing_regions<'tcx, T: TypeFoldable<'tcx> + PartialEq + Copy>(
6946
tcx: TyCtxt<'tcx>,

0 commit comments

Comments
 (0)