Skip to content

Commit 93d0247

Browse files
committed
mGCA: add associated const type check in dyn arm
1 parent db3e99b commit 93d0247

4 files changed

Lines changed: 65 additions & 0 deletions

File tree

‎compiler/rustc_trait_selection/src/traits/wf.rs‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,32 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
951951
ty::Binder::dummy(ty::PredicateKind::DynCompatible(principal)),
952952
));
953953
}
954+
955+
for projection in data.projection_bounds() {
956+
let pred_binder = projection
957+
.with_self_ty(tcx, tcx.types.trait_object_dummy_self)
958+
.map_bound(|p| {
959+
p.term.as_const().map(|ct| {
960+
let assoc_const_ty = tcx
961+
.type_of(p.projection_term.def_id)
962+
.instantiate(tcx, p.projection_term.args);
963+
ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(
964+
ct,
965+
assoc_const_ty,
966+
))
967+
})
968+
})
969+
.transpose();
970+
if let Some(pred_binder) = pred_binder {
971+
self.out.push(traits::Obligation::with_depth(
972+
tcx,
973+
self.cause(ObligationCauseCode::WellFormed(None)),
974+
self.recursion_depth,
975+
self.param_env,
976+
pred_binder,
977+
));
978+
}
979+
}
954980
}
955981

956982
// Inference variables are the complicated case, since we don't
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ known-bug: unknown
2+
//@ check-pass
3+
4+
#![feature(min_generic_const_args)]
5+
#![expect(incomplete_features)]
6+
7+
trait Trait { #[type_const] const CT: bool; }
8+
9+
// FIXME: this should yield a type mismatch (`bool` v `i32`)
10+
fn f<const N: i32>(_: impl Trait<CT = { N }>) {}
11+
12+
fn main() {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ known-bug: unknown
2+
//@ check-pass
3+
4+
#![feature(min_generic_const_args)]
5+
#![expect(incomplete_features)]
6+
7+
trait Trait { #[type_const] const CT: bool; }
8+
9+
fn f<const N: i32>() {
10+
let _: dyn Trait<CT = { N }>; // FIXME: this should yield a type mismatch (`bool` v `i32`)
11+
}
12+
fn main() {}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//@ known-bug: unknown
2+
//@ check-pass
3+
4+
#![feature(min_generic_const_args)]
5+
#![expect(incomplete_features)]
6+
7+
trait Trait { #[type_const] const CT: bool; }
8+
9+
trait Bound { #[type_const] const N: u32; }
10+
impl Bound for () { #[type_const] const N: u32 = 0; }
11+
12+
fn f() { let _: dyn Trait<CT = { <() as Bound>::N }>; } // FIXME
13+
fn g(_: impl Trait<CT = { <() as Bound>::N }>) {} // FIXME
14+
15+
fn main() {}

0 commit comments

Comments
 (0)