From a64e2687164b94c4c9957d8a7dc6ab2622ce4d60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Tue, 4 Nov 2025 14:13:30 +0000 Subject: [PATCH 1/3] deeply normalize where-clauses in wfcheck --- compiler/rustc_hir_analysis/src/check/wfcheck.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index f3d6398b20853..fcfb4374892df 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1500,7 +1500,8 @@ pub(super) fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, def_id: assert_eq!(predicates.predicates.len(), predicates.spans.len()); let wf_obligations = predicates.into_iter().flat_map(|(p, sp)| { - let p = wfcx.normalize(sp, None, p); + // FIXME: we should be checking for well-formedness pre-normalization. + let p = wfcx.deeply_normalize(sp, None, p); traits::wf::clause_obligations(infcx, wfcx.param_env, wfcx.body_def_id, p, sp) }); let obligations: Vec<_> = wf_obligations.chain(default_obligations).collect(); From c0ad8ae5dbfc17948bf95518b1c29023a8ad3627 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Tue, 4 Nov 2025 14:16:12 +0000 Subject: [PATCH 2/3] bless expectations to see diagnostics impact --- .../ui/const-generics/issues/issue-88119.stderr | 17 +++++++++++++++-- .../normalizes-to-is-not-productive.stderr | 7 ------- .../normalize/normalize-param-env-2.stderr | 8 +++++++- .../normalize/normalize-param-env-4.next.stderr | 8 +++++++- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/tests/ui/const-generics/issues/issue-88119.stderr b/tests/ui/const-generics/issues/issue-88119.stderr index 0aabf48011dcd..4e9a3c3700176 100644 --- a/tests/ui/const-generics/issues/issue-88119.stderr +++ b/tests/ui/const-generics/issues/issue-88119.stderr @@ -6,6 +6,12 @@ LL | #![feature(const_trait_impl, generic_const_exprs)] | = help: remove one of these features +error[E0284]: type annotations needed: cannot normalize `<&T as ConstName>::{constant#0}` + --> $DIR/issue-88119.rs:21:5 + | +LL | [(); name_len::()]:, + | ^^^^^^^^^^^^^^^^^^^^^ cannot normalize `<&T as ConstName>::{constant#0}` + error[E0275]: overflow evaluating the requirement `&T: [const] ConstName` --> $DIR/issue-88119.rs:19:49 | @@ -42,6 +48,12 @@ note: required by a bound in `<&T as ConstName>` LL | [(); name_len::()]:, | ^^^^^^^^^^^^^^^^^^^^^ required by this bound in `<&T as ConstName>` +error[E0284]: type annotations needed: cannot normalize `<&mut T as ConstName>::{constant#0}` + --> $DIR/issue-88119.rs:28:5 + | +LL | [(); name_len::()]:, + | ^^^^^^^^^^^^^^^^^^^^^ cannot normalize `<&mut T as ConstName>::{constant#0}` + error[E0275]: overflow evaluating the requirement `&mut T: [const] ConstName` --> $DIR/issue-88119.rs:26:49 | @@ -90,6 +102,7 @@ error[E0275]: overflow evaluating the requirement `&mut &u8: ConstName` LL | pub const ICE_2: &'static [u8] = <&mut &u8 as ConstName>::NAME_BYTES; | ^^^^^^^^ -error: aborting due to 11 previous errors +error: aborting due to 13 previous errors -For more information about this error, try `rustc --explain E0275`. +Some errors have detailed explanations: E0275, E0284. +For more information about an error, try `rustc --explain E0275`. diff --git a/tests/ui/traits/next-solver/cycles/normalizes-to-is-not-productive.stderr b/tests/ui/traits/next-solver/cycles/normalizes-to-is-not-productive.stderr index f679b94a92377..20b1bd557beef 100644 --- a/tests/ui/traits/next-solver/cycles/normalizes-to-is-not-productive.stderr +++ b/tests/ui/traits/next-solver/cycles/normalizes-to-is-not-productive.stderr @@ -21,13 +21,6 @@ LL | impl Trait for T { | ----- ^^^^^^^^ ^ | | | unsatisfied trait bound introduced here -note: required by a bound in `Bound` - --> $DIR/normalizes-to-is-not-productive.rs:8:1 - | -LL | / trait Bound { -LL | | fn method(); -LL | | } - | |_^ required by this bound in `Bound` error[E0277]: the trait bound `Foo: Bound` is not satisfied --> $DIR/normalizes-to-is-not-productive.rs:47:19 diff --git a/tests/ui/traits/next-solver/normalize/normalize-param-env-2.stderr b/tests/ui/traits/next-solver/normalize/normalize-param-env-2.stderr index d179c80596238..1a9a2e69869d7 100644 --- a/tests/ui/traits/next-solver/normalize/normalize-param-env-2.stderr +++ b/tests/ui/traits/next-solver/normalize/normalize-param-env-2.stderr @@ -13,6 +13,12 @@ LL | trait A { LL | fn f() | ^ this trait's associated function doesn't have the requirement `<() as A>::Assoc: A` +error[E0275]: overflow evaluating the requirement `<() as A>::Assoc == _` + --> $DIR/normalize-param-env-2.rs:24:22 + | +LL | Self::Assoc: A, + | ^^^^ + error[E0275]: overflow evaluating the requirement `<() as A>::Assoc: A` --> $DIR/normalize-param-env-2.rs:24:22 | @@ -46,6 +52,6 @@ LL | where LL | Self::Assoc: A, | ^^^^ required by this bound in `A::f` -error: aborting due to 5 previous errors +error: aborting due to 6 previous errors For more information about this error, try `rustc --explain E0275`. diff --git a/tests/ui/traits/next-solver/normalize/normalize-param-env-4.next.stderr b/tests/ui/traits/next-solver/normalize/normalize-param-env-4.next.stderr index f5fd9ce9864ce..43a707609df5b 100644 --- a/tests/ui/traits/next-solver/normalize/normalize-param-env-4.next.stderr +++ b/tests/ui/traits/next-solver/normalize/normalize-param-env-4.next.stderr @@ -1,9 +1,15 @@ +error[E0275]: overflow evaluating the requirement `::Assoc == _` + --> $DIR/normalize-param-env-4.rs:19:26 + | +LL | ::Assoc: Trait, + | ^^^^^ + error[E0275]: overflow evaluating the requirement `::Assoc: Trait` --> $DIR/normalize-param-env-4.rs:19:26 | LL | ::Assoc: Trait, | ^^^^^ -error: aborting due to 1 previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0275`. From 53c5a46a665636f056bc05431c9e863b5e6758e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Tue, 4 Nov 2025 14:35:00 +0000 Subject: [PATCH 3/3] add new solver test for wfcheck deep normalization This difference with the old solver was encountered in a crater run, in `modcholesky`. --- .../normalize/normalize-wc-for-wfcheck.rs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/ui/traits/next-solver/normalize/normalize-wc-for-wfcheck.rs diff --git a/tests/ui/traits/next-solver/normalize/normalize-wc-for-wfcheck.rs b/tests/ui/traits/next-solver/normalize/normalize-wc-for-wfcheck.rs new file mode 100644 index 0000000000000..4cd2a12628a1d --- /dev/null +++ b/tests/ui/traits/next-solver/normalize/normalize-wc-for-wfcheck.rs @@ -0,0 +1,24 @@ +// Wfcheck normalizes where-clauses when checking for WF, so this test passes with the old solver, +// even though it probably shouldn't due to `repro` missing a `T: 'a` bound. For now, until wfcheck +// checks clauses pre-normalization, the new solver matches the old solver. + +// This test is extracted from a new solver crater run error encountered in `modcholesky`. + +//@ check-pass +//@ compile-flags: -Znext-solver + +pub struct View(A); +pub trait Data { + type Elem; +} +impl<'a, A> Data for View<&'a A> { + type Elem = A; +} + +pub fn repro<'a, T>() +where + as Data>::Elem: Sized, +{ +} + +fn main() {}