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 new file mode 100644 index 0000000000000..3dba700a7fa39 --- /dev/null +++ b/tests/ui/const-generics/dyn-trait-ill-typed.rs @@ -0,0 +1,15 @@ +//! Regression test for . +//@ compile-flags: -Znext-solver=globally +//@ 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 {} +} + +trait Tr {} + +fn main() {} 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 +