1 // Test case where the method we want is an inherent method on a
2 // dyn Trait. In that case, the fix is to insert `*` on the receiver.
8 #![warn(rust_2021_prelude_collisions)]
11 fn try_into(&self) -> Result<u32, ()>;
14 impl TryIntoU32 for u8 {
16 fn try_into(&self) -> Result<u32, ()> {
22 use super::get_dyn_trait;
24 // note: this does nothing, but is copying from ffishim's problem of
25 // having a struct of the same name as the trait in-scope, while *also*
26 // implementing the trait for that struct but **without** importing the
27 // trait itself into scope
30 impl super::TryIntoU32 for TryIntoU32 {
31 fn try_into(&self) -> Result<u32, ()> {
36 // this is where the gross part happens. since `get_dyn_trait` returns
37 // a Box<dyn Trait>, it can still call the method for `dyn Trait` without
38 // `Trait` being in-scope. it might even be possible to make the trait itself
39 // entirely unreference-able from the callsite?
40 pub fn test() -> u32 {
41 get_dyn_trait().try_into().unwrap()
42 //~^ WARNING trait method `try_into` will become ambiguous
43 //~| WARNING this is accepted in the current edition
47 fn get_dyn_trait() -> Box<dyn TryIntoU32> {
48 Box::new(3u8) as Box<dyn TryIntoU32>