mGCA: add associated const type check in dyn arm

This commit is contained in:
zedddie 2026-02-05 18:54:59 +01:00
parent 381e9ef09e
commit b6b6dc0b82
No known key found for this signature in database
GPG key ID: B352C3C2894405A7
4 changed files with 67 additions and 0 deletions

View file

@ -951,6 +951,34 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
ty::Binder::dummy(ty::PredicateKind::DynCompatible(principal)),
));
}
if !t.has_escaping_bound_vars() {
for projection in data.projection_bounds() {
let pred_binder = projection
.with_self_ty(tcx, t)
.map_bound(|p| {
p.term.as_const().map(|ct| {
let assoc_const_ty = tcx
.type_of(p.projection_term.def_id)
.instantiate(tcx, p.projection_term.args);
ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(
ct,
assoc_const_ty,
))
})
})
.transpose();
if let Some(pred_binder) = pred_binder {
self.out.push(traits::Obligation::with_depth(
tcx,
self.cause(ObligationCauseCode::WellFormed(None)),
self.recursion_depth,
self.param_env,
pred_binder,
));
}
}
}
}
// Inference variables are the complicated case, since we don't

View file

@ -0,0 +1,12 @@
//@ known-bug: unknown
//@ check-pass
#![feature(min_generic_const_args)]
#![expect(incomplete_features)]
trait Trait { #[type_const] const CT: bool; }
// FIXME: this should yield a type mismatch (`bool` v `i32`)
fn f<const N: i32>(_: impl Trait<CT = { N }>) {}
fn main() {}

View file

@ -0,0 +1,12 @@
//@ known-bug: unknown
//@ check-pass
#![feature(min_generic_const_args)]
#![expect(incomplete_features)]
trait Trait { #[type_const] const CT: bool; }
fn f<const N: i32>() {
let _: dyn Trait<CT = { N }>; // FIXME: this should yield a type mismatch (`bool` v `i32`)
}
fn main() {}

View file

@ -0,0 +1,15 @@
//@ known-bug: unknown
//@ check-pass
#![feature(min_generic_const_args)]
#![expect(incomplete_features)]
trait Trait { #[type_const] const CT: bool; }
trait Bound { #[type_const] const N: u32; }
impl Bound for () { #[type_const] const N: u32 = 0; }
fn f() { let _: dyn Trait<CT = { <() as Bound>::N }>; } // FIXME
fn g(_: impl Trait<CT = { <() as Bound>::N }>) {} // FIXME
fn main() {}