makepad/libs/relax/compiler/tests/dyn_supertrait_projection.rs
Admin cd658a30ef makepad run / Relax: solver and typeck fixes
- async closure Output deduction, solver cycle step kinds from the goal source,
  object supertrait projections, impl candidate merging, trait supertrait
  well-formedness, E0282 for casts and method calls on diverging variables,
  the (..) tuple pattern

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 07:46:04 +02:00

21 lines
768 B
Rust

// A trait object whose principal's supertrait fixes an associated type (`Foo: Sup<A = u8>`,
// `Cb: Fn(i32) -> i32`) implements the supertrait: the object candidate's requirements see the
// fixed projections (rustc lowers them into the object type), so no solver cycle arises.
trait Sup { type A; fn get(&self) -> Self::A; }
trait Foo: Sup<A = u8> {}
struct S;
impl Sup for S { type A = u8; fn get(&self) -> u8 { 7 } }
impl Foo for S {}
fn needs_sup<T: Sup + ?Sized>(_: &T) -> bool { true }
trait Cb: Fn(i32) -> i32 {}
impl<T: Fn(i32) -> i32> Cb for T {}
fn call(f: Box<dyn Cb>) -> i32 { f(42) }
#[test]
fn supertrait_projections() {
let f: &dyn Foo = &S;
assert!(needs_sup(f));
assert_eq!(f.get(), 7);
assert_eq!(call(Box::new(|x| x + 1)), 43);
}