Skip to content

Commit faf7381

Browse files
Rollup merge of #162475 - lsunsi:issue296, r=BoxyUwU
Fix unsoundness bug on next trait solver for dyn const generics placeholder This seem to fix the related test, which would compile on next trait solver and should not. It's related to the linked issue where it'd lead to a segmentation fault. Closes rust-lang/trait-system-refactor-initiative#296 r? @BoxyUwU
2 parents d8dd9f1 + 265ca10 commit faf7381

3 files changed

Lines changed: 33 additions & 1 deletion

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.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//! Regression test for <https://github.com/rust-lang/trait-system-refactor-initiative/issues/296>.
2+
//@ compile-flags: -Znext-solver=globally
3+
//@ check-fail
4+
5+
// CHECK PASS TO SHOW IT PASSES, BUT IT SHOULD NOT
6+
// THIS CODE SEGFAULTS, WITH REASON
7+
8+
//~v ERROR: the constant `M` is not of type `usize`
9+
fn foo<const M: u32>() -> Box<dyn Tr<M>> {
10+
loop {}
11+
}
12+
13+
trait Tr<const N: usize> {}
14+
15+
fn main() {}
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)