Skip to content

Commit d3094bb

Browse files
committed
show env normalization differences under two solvers
1 parent c880acd commit d3094bb

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

compiler/rustc_trait_selection/src/solve/normalize.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ where
217217
fn try_fold_const(&mut self, ct: ty::Const<'tcx>) -> Result<ty::Const<'tcx>, Self::Error> {
218218
let infcx = self.at.infcx;
219219
debug_assert_eq!(ct, infcx.shallow_resolve_const(ct));
220-
if !ct.has_aliases() {
220+
// FIXME: `generic_const_exprs` causes query cycle problem. Same as the old solver.
221+
if !ct.has_aliases() || infcx.tcx.features().generic_const_exprs() {
221222
return Ok(ct);
222223
}
223224

compiler/rustc_trait_selection/src/traits/mod.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ fn do_normalize_predicates<'tcx>(
257257
predicates: Vec<ty::Clause<'tcx>>,
258258
) -> Result<Vec<ty::Clause<'tcx>>, ErrorGuaranteed> {
259259
let span = cause.span;
260+
let original_predicates = predicates.clone();
260261

261262
// FIXME. We should really... do something with these region
262263
// obligations. But this call just continues the older
@@ -283,6 +284,38 @@ fn do_normalize_predicates<'tcx>(
283284

284285
debug!("do_normalize_predicates: normalized predicates = {:?}", predicates);
285286

287+
// The next solver returns nothing for values that contains type error.
288+
// And type error should cause failure later. So we skip the consistency check.
289+
if !tcx.next_trait_solver_globally() && !predicates.references_error() {
290+
let infcx = tcx
291+
.infer_ctxt()
292+
.with_next_trait_solver(true)
293+
.ignoring_regions()
294+
.build(TypingMode::non_body_analysis());
295+
for (orig_pred, pred_by_old) in original_predicates.into_iter().zip(&predicates) {
296+
let inconsistent_pred_by_next =
297+
match crate::solve::deeply_normalize::<_, ScrubbedTraitError<'tcx>>(
298+
infcx.at(&cause, elaborated_env),
299+
orig_pred,
300+
) {
301+
Ok(pred_by_next) => {
302+
if pred_by_next == *pred_by_old {
303+
continue;
304+
}
305+
Some(pred_by_next)
306+
}
307+
Err(_) => None,
308+
};
309+
tcx.dcx().span_err(
310+
span,
311+
format!(
312+
"inconsistency during normalizing env `{:#?}`, old={:#?}, next={:#?}",
313+
orig_pred, pred_by_old, inconsistent_pred_by_next
314+
),
315+
);
316+
}
317+
}
318+
286319
// We can use the `elaborated_env` here; the region code only
287320
// cares about declarations like `'a: 'b`.
288321
// FIXME: It's very weird that we ignore region obligations but apparently

0 commit comments

Comments
 (0)