#![feature(trait_upcasting)] #![allow(incomplete_features)] trait Foo: Bar + Bar {} trait Bar { fn bar(&self) -> Option { None } } fn test_specific(x: &dyn Foo) { let _ = x as &dyn Bar; // OK } fn test_specific2(x: &dyn Foo) { let _ = x as &dyn Bar; // OK } fn test_specific3(x: &dyn Foo) { let _ = x as &dyn Bar; // Error //~^ ERROR non-primitive cast //~^^ ERROR the trait bound `&dyn Foo: Bar` is not satisfied } fn test_infer_arg(x: &dyn Foo) { let a = x as &dyn Bar<_>; // Ambiguous //~^ ERROR non-primitive cast //~^^ ERROR the trait bound `&dyn Foo: Bar<_>` is not satisfied let _ = a.bar(); } fn main() {}