Skip to content

Commit 07ee86a

Browse files
committed
Normalize only after failure
1 parent 8d7707f commit 07ee86a

File tree

1 file changed

+40
-36
lines changed

1 file changed

+40
-36
lines changed

compiler/rustc_mir/src/borrow_check/type_check/input_output.rs

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -82,33 +82,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
8282
let local = Local::new(argument_index + 1);
8383

8484
let mir_input_ty = body.local_decls[local].ty;
85-
// FIXME(jackh726): This is a hack. It's somewhat like
86-
// `rustc_traits::normalize_after_erasing_regions`. Ideally, we'd
87-
// like to normalize *before* inserting into `local_decls`, but I
88-
// couldn't figure out where the heck that was.
89-
let mir_input_ty = match self
90-
.infcx
91-
.at(&ObligationCause::dummy(), ty::ParamEnv::empty())
92-
.normalize(mir_input_ty)
93-
{
94-
Ok(n) => {
95-
debug!("equate_inputs_and_outputs: {:?}", n);
96-
if n.obligations.iter().all(|o| {
97-
matches!(
98-
o.predicate.kind().skip_binder(),
99-
ty::PredicateKind::RegionOutlives(_)
100-
)
101-
}) {
102-
n.value
103-
} else {
104-
mir_input_ty
105-
}
106-
}
107-
Err(_) => {
108-
debug!("equate_inputs_and_outputs: NoSolution");
109-
mir_input_ty
110-
}
111-
};
11285
let mir_input_span = body.local_decls[local].source_info.span;
11386
self.equate_normalized_input_or_output(
11487
normalized_input_ty,
@@ -191,17 +164,48 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
191164
fn equate_normalized_input_or_output(&mut self, a: Ty<'tcx>, b: Ty<'tcx>, span: Span) {
192165
debug!("equate_normalized_input_or_output(a={:?}, b={:?})", a, b);
193166

194-
if let Err(terr) =
167+
if let Err(_) =
195168
self.eq_types(a, b, Locations::All(span), ConstraintCategory::BoringNoLocation)
196169
{
197-
span_mirbug!(
198-
self,
199-
Location::START,
200-
"equate_normalized_input_or_output: `{:?}=={:?}` failed with `{:?}`",
201-
a,
202-
b,
203-
terr
204-
);
170+
// FIXME(jackh726): This is a hack. It's somewhat like
171+
// `rustc_traits::normalize_after_erasing_regions`. Ideally, we'd
172+
// like to normalize *before* inserting into `local_decls`, but I
173+
// couldn't figure out where the heck that was.
174+
let b = match self
175+
.infcx
176+
.at(&ObligationCause::dummy(), ty::ParamEnv::empty())
177+
.normalize(b)
178+
{
179+
Ok(n) => {
180+
debug!("equate_inputs_and_outputs: {:?}", n);
181+
if n.obligations.iter().all(|o| {
182+
matches!(
183+
o.predicate.kind().skip_binder(),
184+
ty::PredicateKind::RegionOutlives(_)
185+
)
186+
}) {
187+
n.value
188+
} else {
189+
b
190+
}
191+
}
192+
Err(_) => {
193+
debug!("equate_inputs_and_outputs: NoSolution");
194+
b
195+
}
196+
};
197+
if let Err(terr) =
198+
self.eq_types(a, b, Locations::All(span), ConstraintCategory::BoringNoLocation)
199+
{
200+
span_mirbug!(
201+
self,
202+
Location::START,
203+
"equate_normalized_input_or_output: `{:?}=={:?}` failed with `{:?}`",
204+
a,
205+
b,
206+
terr
207+
);
208+
}
205209
}
206210
}
207211
}

0 commit comments

Comments
 (0)