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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

18 lines
371 B
Rust
Raw Normal View History

2023-12-14 12:11:28 +00:00
//@ compile-flags: -Znext-solver
2024-05-21 19:30:47 +00:00
//@ run-pass
2023-08-10 10:56:53 +00: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);
}
}