Skip to content

Commit e28fa5a

Browse files
committed
Auto merge of #151374 - BoxyUwU:borrowck_cleanup_3, r=<try>
some more rustc_borrowck cleanups
2 parents 7981818 + bc4798f commit e28fa5a

13 files changed

Lines changed: 62 additions & 123 deletions

File tree

compiler/rustc_borrowck/src/type_check/canonical.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
343343
return;
344344
}
345345

346-
// FIXME: Ideally MIR types are normalized, but this is not always true.
347-
let mir_ty = self.normalize(mir_ty, Locations::All(span));
346+
// TODO: write a test that requires normalization. body locals arent necessarily normalized
347+
// in the old solver so this *should* be possible to hit. See `equate_inputs_and_outputs` for
348+
// a similar problem
348349

349350
let cause = ObligationCause::dummy_with_span(span);
350351
let param_env = self.infcx.param_env;
@@ -353,6 +354,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
353354
ConstraintCategory::Boring,
354355
type_op::custom::CustomTypeOp::new(
355356
|ocx| {
357+
// The `AscribeUserType` query would normally emit a wf
358+
// obligation for the unnormalized user_ty here. This is
359+
// where the "incorrectly skips the WF checks we normally do"
360+
// happens
356361
let user_ty = ocx.normalize(&cause, param_env, user_ty);
357362
ocx.eq(&cause, param_env, user_ty, mir_ty)?;
358363
Ok(())

compiler/rustc_borrowck/src/type_check/input_output.rs

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -173,38 +173,36 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
173173
);
174174
}
175175

176-
// Return types are a bit more complex. They may contain opaque `impl Trait` types.
176+
// Equate expected output ty with the type of the RETURN_PLACE in MIR
177177
let mir_output_ty = self.body.local_decls[RETURN_PLACE].ty;
178178
let output_span = self.body.local_decls[RETURN_PLACE].source_info.span;
179179
self.equate_normalized_input_or_output(normalized_output_ty, mir_output_ty, output_span);
180180
}
181181

182182
#[instrument(skip(self), level = "debug")]
183183
fn equate_normalized_input_or_output(&mut self, a: Ty<'tcx>, b: Ty<'tcx>, span: Span) {
184-
if let Err(_) =
185-
self.eq_types(a, b, Locations::All(span), ConstraintCategory::BoringNoLocation)
186-
{
187-
// FIXME(jackh726): This is a hack. It's somewhat like
188-
// `rustc_traits::normalize_after_erasing_regions`. Ideally, we'd
189-
// like to normalize *before* inserting into `local_decls`, but
190-
// doing so ends up causing some other trouble.
191-
let b = self.normalize(b, Locations::All(span));
192-
193-
// Note: if we have to introduce new placeholders during normalization above, then we
194-
// won't have added those universes to the universe info, which we would want in
195-
// `relate_tys`.
196-
if let Err(terr) =
197-
self.eq_types(a, b, Locations::All(span), ConstraintCategory::BoringNoLocation)
198-
{
199-
span_mirbug!(
200-
self,
201-
Location::START,
202-
"equate_normalized_input_or_output: `{:?}=={:?}` failed with `{:?}`",
203-
a,
204-
b,
205-
terr
206-
);
207-
}
208-
}
184+
let b = match self.infcx.tcx.next_trait_solver_globally() {
185+
true => b,
186+
// FIXME(jackh726, BoxyUwU): This is a hack. `body.local_decls` are not necessarily
187+
// normalized in the old solver due to not deeply normalizing in writeback. So we
188+
// must re-normalize here.
189+
//
190+
// However, in most cases normalizing is unnecessary so we only do so if it may be
191+
// necessary for type equality to hold. This leads to some (very minor) performance
192+
// wins.
193+
false => match self.eq_types(
194+
a,
195+
b,
196+
Locations::All(span),
197+
ConstraintCategory::BoringNoLocation,
198+
) {
199+
Ok(_) => return,
200+
Err(_) => self.normalize(b, Locations::All(span)),
201+
},
202+
};
203+
204+
debug!(?b);
205+
self.eq_types(a, b, Locations::All(span), ConstraintCategory::BoringNoLocation)
206+
.expect("equate_normalized_input_or_output unexpectedly failed");
209207
}
210208
}

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,19 @@ pub(crate) fn type_check<'tcx>(
123123
known_type_outlives_obligations,
124124
} = free_region_relations::create(infcx, universal_regions, &mut constraints);
125125

126-
let pre_obligations = infcx.take_registered_region_obligations();
127-
assert!(
128-
pre_obligations.is_empty(),
129-
"there should be no incoming region obligations = {pre_obligations:#?}",
130-
);
131-
let pre_assumptions = infcx.take_registered_region_assumptions();
132-
assert!(
133-
pre_assumptions.is_empty(),
134-
"there should be no incoming region assumptions = {pre_assumptions:#?}",
135-
);
126+
{
127+
// Scope these variables so it's clear they're not used later
128+
let pre_obligations = infcx.take_registered_region_obligations();
129+
assert!(
130+
pre_obligations.is_empty(),
131+
"there should be no incoming region obligations = {pre_obligations:#?}",
132+
);
133+
let pre_assumptions = infcx.take_registered_region_assumptions();
134+
assert!(
135+
pre_assumptions.is_empty(),
136+
"there should be no incoming region assumptions = {pre_assumptions:#?}",
137+
);
138+
}
136139

137140
debug!(?normalized_inputs_and_output);
138141

tests/ui/associated-types/normalization-generality-2.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
//@ build-pass
2+
//@ revisions: current next
3+
//@ ignore-compare-mode-next-solver (explicit revisions)
4+
//@[next] compile-flags: -Znext-solver
25

36
// Ensures that we don't regress on "implementation is not general enough" when
47
// normalizating under binders. Unlike `normalization-generality.rs`, this also produces

tests/ui/associated-types/normalization-generality.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
//@ build-pass
2+
//@ revisions: current next
3+
//@ ignore-compare-mode-next-solver (explicit revisions)
4+
//@[next] compile-flags: -Znext-solver
25

36
// Ensures that we don't regress on "implementation is not general enough" when
47
// normalizating under binders.

tests/ui/consts/missing_span_in_backtrace.rs

Lines changed: 0 additions & 26 deletions
This file was deleted.

tests/ui/consts/missing_span_in_backtrace.stderr

Lines changed: 0 additions & 20 deletions
This file was deleted.

tests/ui/error-emitter/trimmed_multiline_suggestion.rs

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/ui/error-emitter/trimmed_multiline_suggestion.stderr

Lines changed: 0 additions & 25 deletions
This file was deleted.

tests/ui/higher-ranked/trait-bounds/issue-88446.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
//@ check-pass
2+
//@ revisions: current next
3+
//@ ignore-compare-mode-next-solver (explicit revisions)
4+
//@[next] compile-flags: -Znext-solver
25

36
trait Yokeable<'a> {
47
type Output: 'a;

0 commit comments

Comments
 (0)