rust/tests/ui/traits/new-solver/dyn-any-dont-prefer-impl.rs

18 lines
377 B
Rust
Raw Normal View History

// compile-flags: -Ztrait-solver=next
// check-pass
2023-08-10 05:56:53 -05:00
// Test that selection prefers the builtin trait object impl for `Any`
// instead of the user defined impl. Both impls apply to the trait
// object.
use std::any::Any;
fn needs_usize(_: &usize) {}
fn main() {
let x: &dyn Any = &1usize;
if let Some(x) = x.downcast_ref::<usize>() {
needs_usize(x);
}
}