Skip to content

Commit 6606fd9

Browse files
authored
Rollup merge of #141332 - compiler-errors:no-fold-const, r=lcnr
Do not eagerly fold consts in `normalize_param_env_or_error` if new solver Fixes rust-lang/trait-system-refactor-initiative#213 Given: ``` trait Trait: Deref<Target = [u8; { 1 + 1 }]> {} ``` when elaborating param env for `Trait`, we have `Self: Trait`, `Self: Deref<Target = [u8; {anon const}]>`. Before this PR, we would fold the anon consts away *before* elaborating. However, we end up getting another *un-folded* copy of the anon const from elaborating `Self: Trait`. This leads to normalization ambiguity. r? lcnr
2 parents 1461ca3 + 44a2af3 commit 6606fd9

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

compiler/rustc_trait_selection/src/traits/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ pub fn normalize_param_env_or_error<'tcx>(
340340
let mut predicates: Vec<_> = util::elaborate(
341341
tcx,
342342
unnormalized_env.caller_bounds().into_iter().map(|predicate| {
343-
if tcx.features().generic_const_exprs() {
343+
if tcx.features().generic_const_exprs() || tcx.next_trait_solver_globally() {
344344
return predicate;
345345
}
346346

@@ -405,8 +405,6 @@ pub fn normalize_param_env_or_error<'tcx>(
405405
// compatibility. Eventually when lazy norm is implemented this can just be removed.
406406
// We do not normalize types here as there is no backwards compatibility requirement
407407
// for us to do so.
408-
//
409-
// FIXME(-Znext-solver): remove this hack since we have deferred projection equality
410408
predicate.fold_with(&mut ConstNormalizer(tcx))
411409
}),
412410
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//@ check-pass
2+
//@ compile-flags: -Znext-solver
3+
4+
// Regression test for <https://github.com/rust-lang/trait-system-refactor-initiative/issues/213>.
5+
6+
use std::ops::Deref;
7+
8+
trait Trait: Deref<Target = [u8; { 1 + 1 }]> {}
9+
10+
fn main() {}

0 commit comments

Comments
 (0)