-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test that turbofish does not swim away in prelude collusion suggestion.
- Loading branch information
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/test/ui/rust-2021/future-prelude-collision-turbofish.fixed
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,28 @@ | ||
// See https://github.com/rust-lang/rust/issues/88442 | ||
// run-rustfix | ||
// edition:2018 | ||
// check-pass | ||
#![allow(unused)] | ||
#![warn(rust_2021_prelude_collisions)] | ||
|
||
trait AnnotatableTryInto { | ||
fn try_into<T>(self) -> Result<T, Self::Error> | ||
where Self: std::convert::TryInto<T> { | ||
std::convert::TryInto::try_into(self) | ||
} | ||
} | ||
|
||
impl<T> AnnotatableTryInto for T where T: From<u8> {} | ||
|
||
fn main() -> Result<(), &'static str> { | ||
let x: u64 = 1; | ||
AnnotatableTryInto::try_into::<usize>(x).or(Err("foo"))?.checked_sub(1); | ||
//~^ WARNING trait method `try_into` will become ambiguous in Rust 2021 | ||
//~| WARNING this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! | ||
|
||
AnnotatableTryInto::try_into::<usize>(x).or(Err("foo"))?; | ||
//~^ WARNING trait method `try_into` will become ambiguous in Rust 2021 | ||
//~| WARNING this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! | ||
|
||
Ok(()) | ||
} |
28 changes: 28 additions & 0 deletions
28
src/test/ui/rust-2021/future-prelude-collision-turbofish.rs
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,28 @@ | ||
// See https://github.com/rust-lang/rust/issues/88442 | ||
// run-rustfix | ||
// edition:2018 | ||
// check-pass | ||
#![allow(unused)] | ||
#![warn(rust_2021_prelude_collisions)] | ||
|
||
trait AnnotatableTryInto { | ||
fn try_into<T>(self) -> Result<T, Self::Error> | ||
where Self: std::convert::TryInto<T> { | ||
std::convert::TryInto::try_into(self) | ||
} | ||
} | ||
|
||
impl<T> AnnotatableTryInto for T where T: From<u8> {} | ||
|
||
fn main() -> Result<(), &'static str> { | ||
let x: u64 = 1; | ||
x.try_into::<usize>().or(Err("foo"))?.checked_sub(1); | ||
//~^ WARNING trait method `try_into` will become ambiguous in Rust 2021 | ||
//~| WARNING this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! | ||
|
||
x.try_into::<usize>().or(Err("foo"))?; | ||
//~^ WARNING trait method `try_into` will become ambiguous in Rust 2021 | ||
//~| WARNING this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! | ||
|
||
Ok(()) | ||
} |
25 changes: 25 additions & 0 deletions
25
src/test/ui/rust-2021/future-prelude-collision-turbofish.stderr
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,25 @@ | ||
warning: trait method `try_into` will become ambiguous in Rust 2021 | ||
--> $DIR/future-prelude-collision-turbofish.rs:19:5 | ||
| | ||
LL | x.try_into::<usize>().or(Err("foo"))?.checked_sub(1); | ||
| ^^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `AnnotatableTryInto::try_into::<usize>(x)` | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/future-prelude-collision-turbofish.rs:6:9 | ||
| | ||
LL | #![warn(rust_2021_prelude_collisions)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! | ||
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html> | ||
|
||
warning: trait method `try_into` will become ambiguous in Rust 2021 | ||
--> $DIR/future-prelude-collision-turbofish.rs:23:5 | ||
| | ||
LL | x.try_into::<usize>().or(Err("foo"))?; | ||
| ^^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `AnnotatableTryInto::try_into::<usize>(x)` | ||
| | ||
= warning: this is accepted in the current edition (Rust 2018) but is a hard error in Rust 2021! | ||
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html> | ||
|
||
warning: 2 warnings emitted | ||
|