-
Notifications
You must be signed in to change notification settings - Fork 12.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3dc47e2
commit 186c09a
Showing
3 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Test case where the method we want is an inherent method on a | ||
// dyn Trait. In that case, the fix is to insert `*` on the receiver. | ||
// | ||
// check-pass | ||
// run-rustfix | ||
// edition:2018 | ||
|
||
#![warn(future_prelude_collision)] | ||
|
||
trait TryIntoU32 { | ||
fn try_into(&self) -> Result<u32, ()>; | ||
} | ||
|
||
impl TryIntoU32 for u8 { | ||
// note: &self | ||
fn try_into(&self) -> Result<u32, ()> { | ||
Ok(22) | ||
} | ||
} | ||
|
||
mod inner { | ||
use super::get_dyn_trait; | ||
|
||
// note: this does nothing, but is copying from ffishim's problem of | ||
// having a struct of the same name as the trait in-scope, while *also* | ||
// implementing the trait for that struct but **without** importing the | ||
// trait itself into scope | ||
struct TryIntoU32; | ||
|
||
impl super::TryIntoU32 for TryIntoU32 { | ||
fn try_into(&self) -> Result<u32, ()> { | ||
Ok(0) | ||
} | ||
} | ||
|
||
// this is where the gross part happens. since `get_dyn_trait` returns | ||
// a Box<dyn Trait>, it can still call the method for `dyn Trait` without | ||
// `Trait` being in-scope. it might even be possible to make the trait itself | ||
// entirely unreference-able from the callsite? | ||
pub fn test() -> u32 { | ||
(&*get_dyn_trait()).try_into().unwrap() | ||
//~^ WARNING trait method `try_into` will become ambiguous | ||
//~| WARNING this was previously accepted | ||
} | ||
} | ||
|
||
fn get_dyn_trait() -> Box<dyn TryIntoU32> { | ||
Box::new(3u8) as Box<dyn TryIntoU32> | ||
} | ||
|
||
fn main() { | ||
dbg!(inner::test()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Test case where the method we want is an inherent method on a | ||
// dyn Trait. In that case, the fix is to insert `*` on the receiver. | ||
// | ||
// check-pass | ||
// run-rustfix | ||
// edition:2018 | ||
|
||
#![warn(future_prelude_collision)] | ||
|
||
trait TryIntoU32 { | ||
fn try_into(&self) -> Result<u32, ()>; | ||
} | ||
|
||
impl TryIntoU32 for u8 { | ||
// note: &self | ||
fn try_into(&self) -> Result<u32, ()> { | ||
Ok(22) | ||
} | ||
} | ||
|
||
mod inner { | ||
use super::get_dyn_trait; | ||
|
||
// note: this does nothing, but is copying from ffishim's problem of | ||
// having a struct of the same name as the trait in-scope, while *also* | ||
// implementing the trait for that struct but **without** importing the | ||
// trait itself into scope | ||
struct TryIntoU32; | ||
|
||
impl super::TryIntoU32 for TryIntoU32 { | ||
fn try_into(&self) -> Result<u32, ()> { | ||
Ok(0) | ||
} | ||
} | ||
|
||
// this is where the gross part happens. since `get_dyn_trait` returns | ||
// a Box<dyn Trait>, it can still call the method for `dyn Trait` without | ||
// `Trait` being in-scope. it might even be possible to make the trait itself | ||
// entirely unreference-able from the callsite? | ||
pub fn test() -> u32 { | ||
get_dyn_trait().try_into().unwrap() | ||
//~^ WARNING trait method `try_into` will become ambiguous | ||
//~| WARNING this was previously accepted | ||
} | ||
} | ||
|
||
fn get_dyn_trait() -> Box<dyn TryIntoU32> { | ||
Box::new(3u8) as Box<dyn TryIntoU32> | ||
} | ||
|
||
fn main() { | ||
dbg!(inner::test()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
warning: trait method `try_into` will become ambiguous in Rust 2021 | ||
--> $DIR/inherent-dyn-collision.rs:41:9 | ||
| | ||
LL | get_dyn_trait().try_into().unwrap() | ||
| ^^^^^^^^^^^^^^^ help: disambiguate the method call: `(&*get_dyn_trait())` | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/inherent-dyn-collision.rs:8:9 | ||
| | ||
LL | #![warn(future_prelude_collision)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition! | ||
= note: for more information, see issue #85684 <https://github.com/rust-lang/rust/issues/85684> | ||
|
||
warning: 1 warning emitted | ||
|