Skip to content

Commit 56108f6

Browse files
committed
Add future_prelude_collision to 2021 compat group
* Add to 2021 compatibility group * Set default to Allow
1 parent 3efa5b4 commit 56108f6

File tree

7 files changed

+71
-12
lines changed

7 files changed

+71
-12
lines changed

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3282,7 +3282,11 @@ declare_lint! {
32823282
///
32833283
/// [prelude changes]: https://blog.rust-lang.org/inside-rust/2021/03/04/planning-rust-2021.html#prelude-changes
32843284
pub FUTURE_PRELUDE_COLLISION,
3285-
Warn,
3285+
Allow,
32863286
"detects the usage of trait methods which are ambiguous with traits added to the \
32873287
prelude in future editions",
3288+
@future_incompatible = FutureIncompatibleInfo {
3289+
reference: "issue #85684 <https://github.com/rust-lang/rust/issues/85684>",
3290+
edition: Some(Edition::Edition2021),
3291+
};
32883292
}

src/test/ui/rust-2021/future-prelude-collision.fixed

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// run-rustfix
22
// edition:2018
33
// check-pass
4+
#![warn(future_prelude_collision)]
45

56
trait TryIntoU32 {
67
fn try_into(self) -> Result<u32, ()>;
@@ -52,36 +53,44 @@ fn main() {
5253
// test dot-call that will break in 2021 edition
5354
let _: u32 = TryIntoU32::try_into(3u8).unwrap();
5455
//~^ WARNING trait method `try_into` will become ambiguous in Rust 2021
56+
//~^^ WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
5557

5658
// test associated function call that will break in 2021 edition
5759
let _ = <u32 as TryFromU8>::try_from(3u8).unwrap();
5860
//~^ WARNING trait-associated function `try_from` will become ambiguous in Rust 2021
61+
//~^^ WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
5962

6063
// test reverse turbofish too
6164
let _ = <Vec<u8> as FromByteIterator>::from_iter(vec![1u8, 2, 3, 4, 5, 6].into_iter());
6265
//~^ WARNING trait-associated function `from_iter` will become ambiguous in Rust 2021
66+
//~^^ WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
6367

6468
// negative testing lint (this line should *not* emit a warning)
6569
let _: u32 = TryFromU8::try_from(3u8).unwrap();
6670

6771
// test type omission
6872
let _: u32 = <_ as TryFromU8>::try_from(3u8).unwrap();
6973
//~^ WARNING trait-associated function `try_from` will become ambiguous in Rust 2021
74+
//~^^ WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
7075

7176
// test autoderef
7277
let _: u32 = TryIntoU32::try_into(*(&3u8)).unwrap();
7378
//~^ WARNING trait method `try_into` will become ambiguous in Rust 2021
79+
//~^^ WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
7480

7581
// test autoref
7682
let _: u32 = TryIntoU32::try_into(&3.0).unwrap();
7783
//~^ WARNING trait method `try_into` will become ambiguous in Rust 2021
84+
//~^^ WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
7885

7986
let mut data = 3u16;
8087
let mut_ptr = std::ptr::addr_of_mut!(data);
8188
let _: u32 = TryIntoU32::try_into(mut_ptr as *const _).unwrap();
8289
//~^ WARNING trait method `try_into` will become ambiguous in Rust 2021
90+
//~^^ WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
8391

8492
type U32Alias = u32;
8593
let _ = <U32Alias as TryFromU8>::try_from(3u8).unwrap();
8694
//~^ WARNING trait-associated function `try_from` will become ambiguous in Rust 2021
95+
//~^^ WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
8796
}

src/test/ui/rust-2021/future-prelude-collision.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// run-rustfix
22
// edition:2018
33
// check-pass
4+
#![warn(future_prelude_collision)]
45

56
trait TryIntoU32 {
67
fn try_into(self) -> Result<u32, ()>;
@@ -52,36 +53,44 @@ fn main() {
5253
// test dot-call that will break in 2021 edition
5354
let _: u32 = 3u8.try_into().unwrap();
5455
//~^ WARNING trait method `try_into` will become ambiguous in Rust 2021
56+
//~^^ WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
5557

5658
// test associated function call that will break in 2021 edition
5759
let _ = u32::try_from(3u8).unwrap();
5860
//~^ WARNING trait-associated function `try_from` will become ambiguous in Rust 2021
61+
//~^^ WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
5962

6063
// test reverse turbofish too
6164
let _ = <Vec<u8>>::from_iter(vec![1u8, 2, 3, 4, 5, 6].into_iter());
6265
//~^ WARNING trait-associated function `from_iter` will become ambiguous in Rust 2021
66+
//~^^ WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
6367

6468
// negative testing lint (this line should *not* emit a warning)
6569
let _: u32 = TryFromU8::try_from(3u8).unwrap();
6670

6771
// test type omission
6872
let _: u32 = <_>::try_from(3u8).unwrap();
6973
//~^ WARNING trait-associated function `try_from` will become ambiguous in Rust 2021
74+
//~^^ WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
7075

7176
// test autoderef
7277
let _: u32 = (&3u8).try_into().unwrap();
7378
//~^ WARNING trait method `try_into` will become ambiguous in Rust 2021
79+
//~^^ WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
7480

7581
// test autoref
7682
let _: u32 = 3.0.try_into().unwrap();
7783
//~^ WARNING trait method `try_into` will become ambiguous in Rust 2021
84+
//~^^ WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
7885

7986
let mut data = 3u16;
8087
let mut_ptr = std::ptr::addr_of_mut!(data);
8188
let _: u32 = mut_ptr.try_into().unwrap();
8289
//~^ WARNING trait method `try_into` will become ambiguous in Rust 2021
90+
//~^^ WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
8391

8492
type U32Alias = u32;
8593
let _ = U32Alias::try_from(3u8).unwrap();
8694
//~^ WARNING trait-associated function `try_from` will become ambiguous in Rust 2021
95+
//~^^ WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
8796
}
Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,79 @@
11
warning: trait method `try_into` will become ambiguous in Rust 2021
2-
--> $DIR/future-prelude-collision.rs:53:18
2+
--> $DIR/future-prelude-collision.rs:54:18
33
|
44
LL | let _: u32 = 3u8.try_into().unwrap();
55
| ^^^^^^^^^^^^^^ help: disambiguate the associated function: `TryIntoU32::try_into(3u8)`
66
|
7-
= note: `#[warn(future_prelude_collision)]` on by default
7+
note: the lint level is defined here
8+
--> $DIR/future-prelude-collision.rs:4:9
9+
|
10+
LL | #![warn(future_prelude_collision)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^
12+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
13+
= note: for more information, see issue #85684 <https://github.com/rust-lang/rust/issues/85684>
814

915
warning: trait-associated function `try_from` will become ambiguous in Rust 2021
10-
--> $DIR/future-prelude-collision.rs:57:13
16+
--> $DIR/future-prelude-collision.rs:59:13
1117
|
1218
LL | let _ = u32::try_from(3u8).unwrap();
1319
| ^^^^^^^^^^^^^ help: disambiguate the associated function: `<u32 as TryFromU8>::try_from`
20+
|
21+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
22+
= note: for more information, see issue #85684 <https://github.com/rust-lang/rust/issues/85684>
1423

1524
warning: trait-associated function `from_iter` will become ambiguous in Rust 2021
16-
--> $DIR/future-prelude-collision.rs:61:13
25+
--> $DIR/future-prelude-collision.rs:64:13
1726
|
1827
LL | let _ = <Vec<u8>>::from_iter(vec![1u8, 2, 3, 4, 5, 6].into_iter());
1928
| ^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `<Vec<u8> as FromByteIterator>::from_iter`
29+
|
30+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
31+
= note: for more information, see issue #85684 <https://github.com/rust-lang/rust/issues/85684>
2032

2133
warning: trait-associated function `try_from` will become ambiguous in Rust 2021
22-
--> $DIR/future-prelude-collision.rs:68:18
34+
--> $DIR/future-prelude-collision.rs:72:18
2335
|
2436
LL | let _: u32 = <_>::try_from(3u8).unwrap();
2537
| ^^^^^^^^^^^^^ help: disambiguate the associated function: `<_ as TryFromU8>::try_from`
38+
|
39+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
40+
= note: for more information, see issue #85684 <https://github.com/rust-lang/rust/issues/85684>
2641

2742
warning: trait method `try_into` will become ambiguous in Rust 2021
28-
--> $DIR/future-prelude-collision.rs:72:18
43+
--> $DIR/future-prelude-collision.rs:77:18
2944
|
3045
LL | let _: u32 = (&3u8).try_into().unwrap();
3146
| ^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `TryIntoU32::try_into(*(&3u8))`
47+
|
48+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
49+
= note: for more information, see issue #85684 <https://github.com/rust-lang/rust/issues/85684>
3250

3351
warning: trait method `try_into` will become ambiguous in Rust 2021
34-
--> $DIR/future-prelude-collision.rs:76:18
52+
--> $DIR/future-prelude-collision.rs:82:18
3553
|
3654
LL | let _: u32 = 3.0.try_into().unwrap();
3755
| ^^^^^^^^^^^^^^ help: disambiguate the associated function: `TryIntoU32::try_into(&3.0)`
56+
|
57+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
58+
= note: for more information, see issue #85684 <https://github.com/rust-lang/rust/issues/85684>
3859

3960
warning: trait method `try_into` will become ambiguous in Rust 2021
40-
--> $DIR/future-prelude-collision.rs:81:18
61+
--> $DIR/future-prelude-collision.rs:88:18
4162
|
4263
LL | let _: u32 = mut_ptr.try_into().unwrap();
4364
| ^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `TryIntoU32::try_into(mut_ptr as *const _)`
65+
|
66+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
67+
= note: for more information, see issue #85684 <https://github.com/rust-lang/rust/issues/85684>
4468

4569
warning: trait-associated function `try_from` will become ambiguous in Rust 2021
46-
--> $DIR/future-prelude-collision.rs:85:13
70+
--> $DIR/future-prelude-collision.rs:93:13
4771
|
4872
LL | let _ = U32Alias::try_from(3u8).unwrap();
4973
| ^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `<U32Alias as TryFromU8>::try_from`
74+
|
75+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
76+
= note: for more information, see issue #85684 <https://github.com/rust-lang/rust/issues/85684>
5077

5178
warning: 8 warnings emitted
5279

src/test/ui/rust-2021/generic-type-collision.fixed

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// check-pass
22
// run-rustfix
33
// edition 2018
4+
#![warn(future_prelude_collision)]
45

56
trait MyTrait<A> {
67
fn from_iter(x: Option<A>);
@@ -13,4 +14,5 @@ impl<T> MyTrait<()> for Vec<T> {
1314
fn main() {
1415
<Vec<i32> as MyTrait<_>>::from_iter(None);
1516
//~^ WARNING trait-associated function `from_iter` will become ambiguous in Rust 2021
17+
//~^^ WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
1618
}

src/test/ui/rust-2021/generic-type-collision.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// check-pass
22
// run-rustfix
33
// edition 2018
4+
#![warn(future_prelude_collision)]
45

56
trait MyTrait<A> {
67
fn from_iter(x: Option<A>);
@@ -13,4 +14,5 @@ impl<T> MyTrait<()> for Vec<T> {
1314
fn main() {
1415
<Vec<i32>>::from_iter(None);
1516
//~^ WARNING trait-associated function `from_iter` will become ambiguous in Rust 2021
17+
//~^^ WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
1618
}
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
warning: trait-associated function `from_iter` will become ambiguous in Rust 2021
2-
--> $DIR/generic-type-collision.rs:14:5
2+
--> $DIR/generic-type-collision.rs:15:5
33
|
44
LL | <Vec<i32>>::from_iter(None);
55
| ^^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `<Vec<i32> as MyTrait<_>>::from_iter`
66
|
7-
= note: `#[warn(future_prelude_collision)]` on by default
7+
note: the lint level is defined here
8+
--> $DIR/generic-type-collision.rs:4:9
9+
|
10+
LL | #![warn(future_prelude_collision)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^
12+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition!
13+
= note: for more information, see issue #85684 <https://github.com/rust-lang/rust/issues/85684>
814

915
warning: 1 warning emitted
1016

0 commit comments

Comments
 (0)