Fix future_prelude_collision for object calls and use as _

This commit is contained in:
jam1garner 2021-06-19 18:42:24 -04:00
parent 9bee7f0d0e
commit b18704dd58
7 changed files with 311 additions and 57 deletions

View file

@ -0,0 +1,59 @@
// run-rustfix
// edition:2018
// check-pass
#![warn(future_prelude_collision)]
#![allow(dead_code)]
#![allow(unused_imports)]
mod m {
pub trait TryIntoU32 {
fn try_into(self) -> Result<u32, ()>;
}
impl TryIntoU32 for u8 {
fn try_into(self) -> Result<u32, ()> {
Ok(self as u32)
}
}
pub trait AnotherTrick {}
}
mod a {
use crate::m::TryIntoU32;
fn main() {
// In this case, we can just use `TryIntoU32`
let _: u32 = TryIntoU32::try_into(3u8).unwrap();
//~^ WARNING trait method `try_into` will become ambiguous in Rust 2021
//~^^ WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
}
}
mod b {
use crate::m::AnotherTrick as TryIntoU32;
use crate::m::TryIntoU32 as _;
fn main() {
// In this case, a `TryIntoU32::try_into` rewrite will not work, and we need to use
// the path `crate::m::TryIntoU32` (with which it was imported).
let _: u32 = crate::m::TryIntoU32::try_into(3u8).unwrap();
//~^ WARNING trait method `try_into` will become ambiguous in Rust 2021
//~^^ WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
}
}
mod c {
use super::m::TryIntoU32 as _;
use crate::m::AnotherTrick as TryIntoU32;
fn main() {
// In this case, a `TryIntoU32::try_into` rewrite will not work, and we need to use
// the path `super::m::TryIntoU32` (with which it was imported).
let _: u32 = super::m::TryIntoU32::try_into(3u8).unwrap();
//~^ WARNING trait method `try_into` will become ambiguous in Rust 2021
//~^^ WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
}
}
fn main() {}

View file

@ -3,6 +3,7 @@
// check-pass
#![warn(future_prelude_collision)]
#![allow(dead_code)]
#![allow(unused_imports)]
mod m {
pub trait TryIntoU32 {
@ -24,6 +25,8 @@ mod a {
fn main() {
// In this case, we can just use `TryIntoU32`
let _: u32 = 3u8.try_into().unwrap();
//~^ WARNING trait method `try_into` will become ambiguous in Rust 2021
//~^^ WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
}
}
@ -35,6 +38,8 @@ mod b {
// In this case, a `TryIntoU32::try_into` rewrite will not work, and we need to use
// the path `crate::m::TryIntoU32` (with which it was imported).
let _: u32 = 3u8.try_into().unwrap();
//~^ WARNING trait method `try_into` will become ambiguous in Rust 2021
//~^^ WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
}
}
@ -46,6 +51,8 @@ mod c {
// In this case, a `TryIntoU32::try_into` rewrite will not work, and we need to use
// the path `super::m::TryIntoU32` (with which it was imported).
let _: u32 = 3u8.try_into().unwrap();
//~^ WARNING trait method `try_into` will become ambiguous in Rust 2021
//~^^ WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
}
}

View file

@ -0,0 +1,34 @@
warning: trait method `try_into` will become ambiguous in Rust 2021
--> $DIR/future-prelude-collision-imported.rs:27:22
|
LL | let _: u32 = 3u8.try_into().unwrap();
| ^^^^^^^^^^^^^^ help: disambiguate the associated function: `TryIntoU32::try_into(3u8)`
|
note: the lint level is defined here
--> $DIR/future-prelude-collision-imported.rs:4: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: trait method `try_into` will become ambiguous in Rust 2021
--> $DIR/future-prelude-collision-imported.rs:40:22
|
LL | let _: u32 = 3u8.try_into().unwrap();
| ^^^^^^^^^^^^^^ help: disambiguate the associated function: `crate::m::TryIntoU32::try_into(3u8)`
|
= 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: trait method `try_into` will become ambiguous in Rust 2021
--> $DIR/future-prelude-collision-imported.rs:53:22
|
LL | let _: u32 = 3u8.try_into().unwrap();
| ^^^^^^^^^^^^^^ help: disambiguate the associated function: `super::m::TryIntoU32::try_into(3u8)`
|
= 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: 3 warnings emitted

View file

@ -0,0 +1,33 @@
// run-rustfix
// edition:2018
#![warn(future_prelude_collision)]
#![allow(dead_code)]
#![allow(unused_imports)]
mod m {
pub trait TryIntoU32 {
fn try_into(self) -> Result<u32, ()>;
}
impl TryIntoU32 for u8 {
fn try_into(self) -> Result<u32, ()> {
Ok(self as u32)
}
}
pub trait AnotherTrick {}
}
mod d {
use crate::m::AnotherTrick as TryIntoU32;
use crate::m::*;
fn main() {
// Here, `TryIntoU32` is imported but shadowed, but in that case we don't permit its methods
// to be available.
let _: u32 = 3u8.try_into().unwrap();
//~^ ERROR no method named `try_into` found for type `u8` in the current scope
}
}
fn main() {}

View file

@ -1,8 +1,8 @@
// run-rustfix
// edition:2018
// check-pass
#![warn(future_prelude_collision)]
#![allow(dead_code)]
#![allow(unused_imports)]
mod m {
pub trait TryIntoU32 {
@ -26,7 +26,7 @@ mod d {
// Here, `TryIntoU32` is imported but shadowed, but in that case we don't permit its methods
// to be available.
let _: u32 = 3u8.try_into().unwrap();
//~^ ERROR no method name `try_into` found
//~^ ERROR no method named `try_into` found for type `u8` in the current scope
}
}

View file

@ -0,0 +1,40 @@
error[E0599]: no method named `try_into` found for type `u8` in the current scope
--> $DIR/future-prelude-collision-shadow.rs:28:26
|
LL | let _: u32 = 3u8.try_into().unwrap();
| ^^^^^^^^ method not found in `u8`
|
::: $SRC_DIR/core/src/convert/mod.rs:LL:COL
|
LL | fn try_into(self) -> Result<T, Self::Error>;
| --------
| |
| the method is available for `Box<u8>` here
| the method is available for `Pin<u8>` here
| the method is available for `Arc<u8>` here
| the method is available for `Rc<u8>` here
|
= help: items from traits can only be used if the trait is in scope
= note: the following traits are implemented but not in scope; perhaps add a `use` for one of them:
candidate #1: `use crate::m::TryIntoU32;`
candidate #2: `use std::convert::TryInto;`
help: consider wrapping the receiver expression with the appropriate type
|
LL | let _: u32 = Box::new(3u8).try_into().unwrap();
| ^^^^^^^^^ ^
help: consider wrapping the receiver expression with the appropriate type
|
LL | let _: u32 = Pin::new(3u8).try_into().unwrap();
| ^^^^^^^^^ ^
help: consider wrapping the receiver expression with the appropriate type
|
LL | let _: u32 = Arc::new(3u8).try_into().unwrap();
| ^^^^^^^^^ ^
help: consider wrapping the receiver expression with the appropriate type
|
LL | let _: u32 = Rc::new(3u8).try_into().unwrap();
| ^^^^^^^^ ^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0599`.