From 7ce50f87c0439e7352680fd76bdaa5ae02cfecfc Mon Sep 17 00:00:00 2001 From: Lucas Sunsi Abreu Date: Tue, 8 Sep 2026 07:05:59 -0300 Subject: [PATCH 1/2] Add test for soundness issue on new solver --- tests/ui/const-generics/dyn-trait-ill-typed.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 tests/ui/const-generics/dyn-trait-ill-typed.rs diff --git a/tests/ui/const-generics/dyn-trait-ill-typed.rs b/tests/ui/const-generics/dyn-trait-ill-typed.rs new file mode 100644 index 0000000000000..d6c1fdc29fb53 --- /dev/null +++ b/tests/ui/const-generics/dyn-trait-ill-typed.rs @@ -0,0 +1,14 @@ +//! Regression test for . +//@ compile-flags: -Znext-solver=globally +//@ check-pass + +// CHECK PASS TO SHOW IT PASSES, BUT IT SHOULD NOT +// THIS CODE SEGFAULTS, WITH REASON + +fn foo() -> Box> { + loop {} +} + +trait Tr {} + +fn main() {} From 265ca102b5ec5755a92bfa50c246df39a4943732 Mon Sep 17 00:00:00 2001 From: Lucas Sunsi Abreu Date: Mon, 7 Sep 2026 11:04:13 -0300 Subject: [PATCH 2/2] Make ConstKind Placeholder also check ConstArgHasType --- compiler/rustc_trait_selection/src/traits/wf.rs | 5 ++++- tests/ui/const-generics/dyn-trait-ill-typed.rs | 3 ++- tests/ui/const-generics/dyn-trait-ill-typed.stderr | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 tests/ui/const-generics/dyn-trait-ill-typed.stderr diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index 5fc9e57795b72..1de2318fe77f4 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -1003,7 +1003,10 @@ impl<'a, 'tcx> TypeVisitor> for WfPredicates<'a, 'tcx> { let kind = obligation.predicate.kind().skip_binder(); let keep = match kind { ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, _)) - if matches!(ct.kind(), ty::ConstKind::Param(..)) => + if matches!( + ct.kind(), + ty::ConstKind::Param(..) | ty::ConstKind::Placeholder(..) + ) => { // ConstArgHasType clauses are not higher kinded. Assert as // such so we can fix this up if that ever changes. diff --git a/tests/ui/const-generics/dyn-trait-ill-typed.rs b/tests/ui/const-generics/dyn-trait-ill-typed.rs index d6c1fdc29fb53..3dba700a7fa39 100644 --- a/tests/ui/const-generics/dyn-trait-ill-typed.rs +++ b/tests/ui/const-generics/dyn-trait-ill-typed.rs @@ -1,10 +1,11 @@ //! Regression test for . //@ compile-flags: -Znext-solver=globally -//@ check-pass +//@ check-fail // CHECK PASS TO SHOW IT PASSES, BUT IT SHOULD NOT // THIS CODE SEGFAULTS, WITH REASON +//~v ERROR: the constant `M` is not of type `usize` fn foo() -> Box> { loop {} } diff --git a/tests/ui/const-generics/dyn-trait-ill-typed.stderr b/tests/ui/const-generics/dyn-trait-ill-typed.stderr new file mode 100644 index 0000000000000..8917b53d4d826 --- /dev/null +++ b/tests/ui/const-generics/dyn-trait-ill-typed.stderr @@ -0,0 +1,14 @@ +error: the constant `M` is not of type `usize` + --> $DIR/dyn-trait-ill-typed.rs:9:27 + | +LL | fn foo() -> Box> { + | ^^^^^^^^^^^^^^ expected `usize`, found `u32` + | +note: required by a const generic parameter in `Tr` + --> $DIR/dyn-trait-ill-typed.rs:13:10 + | +LL | trait Tr {} + | ^^^^^^^^^^^^^^ required by this const generic parameter in `Tr` + +error: aborting due to 1 previous error +