Skip to content

Commit 265ca10

Browse files
committed
Make ConstKind Placeholder also check ConstArgHasType
1 parent 7ce50f8 commit 265ca10

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

compiler/rustc_trait_selection/src/traits/wf.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,10 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
10031003
let kind = obligation.predicate.kind().skip_binder();
10041004
let keep = match kind {
10051005
ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, _))
1006-
if matches!(ct.kind(), ty::ConstKind::Param(..)) =>
1006+
if matches!(
1007+
ct.kind(),
1008+
ty::ConstKind::Param(..) | ty::ConstKind::Placeholder(..)
1009+
) =>
10071010
{
10081011
// ConstArgHasType clauses are not higher kinded. Assert as
10091012
// such so we can fix this up if that ever changes.

tests/ui/const-generics/dyn-trait-ill-typed.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
//! Regression test for <https://github.com/rust-lang/trait-system-refactor-initiative/issues/296>.
22
//@ compile-flags: -Znext-solver=globally
3-
//@ check-pass
3+
//@ check-fail
44

55
// CHECK PASS TO SHOW IT PASSES, BUT IT SHOULD NOT
66
// THIS CODE SEGFAULTS, WITH REASON
77

8+
//~v ERROR: the constant `M` is not of type `usize`
89
fn foo<const M: u32>() -> Box<dyn Tr<M>> {
910
loop {}
1011
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: the constant `M` is not of type `usize`
2+
--> $DIR/dyn-trait-ill-typed.rs:9:27
3+
|
4+
LL | fn foo<const M: u32>() -> Box<dyn Tr<M>> {
5+
| ^^^^^^^^^^^^^^ expected `usize`, found `u32`
6+
|
7+
note: required by a const generic parameter in `Tr`
8+
--> $DIR/dyn-trait-ill-typed.rs:13:10
9+
|
10+
LL | trait Tr<const N: usize> {}
11+
| ^^^^^^^^^^^^^^ required by this const generic parameter in `Tr`
12+
13+
error: aborting due to 1 previous error
14+

0 commit comments

Comments
 (0)