-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add migration lint for 2024 prelude additions #125889
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
17 changes: 17 additions & 0 deletions
17
tests/ui/rust-2024/prelude-migration/future-poll-already-future.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,17 @@ | ||
//@ revisions: e2021 e2024 | ||
//@[e2021] edition: 2021 | ||
//@[e2024] edition: 2024 | ||
//@[e2024] compile-flags: -Zunstable-options | ||
//@ check-pass | ||
|
||
#![deny(rust_2024_prelude_collisions)] | ||
|
||
use std::future::Future; | ||
|
||
fn main() { | ||
core::pin::pin!(async {}).poll(&mut context()); | ||
} | ||
|
||
fn context() -> core::task::Context<'static> { | ||
loop {} | ||
} |
21 changes: 21 additions & 0 deletions
21
tests/ui/rust-2024/prelude-migration/future-poll-async-block.e2021.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,21 @@ | ||
//@ revisions: e2021 e2024 | ||
//@[e2021] edition: 2021 | ||
//@[e2021] run-rustfix | ||
//@[e2024] edition: 2024 | ||
//@[e2024] compile-flags: -Zunstable-options | ||
//@[e2024] check-pass | ||
|
||
#![deny(rust_2024_prelude_collisions)] | ||
trait Meow { | ||
fn poll(&self, _ctx: &mut core::task::Context<'_>) {} | ||
} | ||
impl<T> Meow for T {} | ||
fn main() { | ||
Meow::poll(&core::pin::pin!(async {}), &mut context()); | ||
//[e2021]~^ ERROR trait method `poll` will become ambiguous in Rust 2024 | ||
//[e2021]~| WARN this is accepted in the current edition (Rust 2021) but is a hard error in Rust 2024! | ||
} | ||
|
||
fn context() -> core::task::Context<'static> { | ||
loop {} | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/ui/rust-2024/prelude-migration/future-poll-async-block.e2021.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,16 @@ | ||
error: trait method `poll` will become ambiguous in Rust 2024 | ||
--> $DIR/future-poll-async-block.rs:14:5 | ||
| | ||
LL | core::pin::pin!(async {}).poll(&mut context()); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `Meow::poll(&core::pin::pin!(async {}), &mut context())` | ||
| | ||
= warning: this is accepted in the current edition (Rust 2021) but is a hard error in Rust 2024! | ||
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/prelude.html> | ||
note: the lint level is defined here | ||
--> $DIR/future-poll-async-block.rs:8:9 | ||
| | ||
LL | #![deny(rust_2024_prelude_collisions)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
21 changes: 21 additions & 0 deletions
21
tests/ui/rust-2024/prelude-migration/future-poll-async-block.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,21 @@ | ||
//@ revisions: e2021 e2024 | ||
//@[e2021] edition: 2021 | ||
//@[e2021] run-rustfix | ||
//@[e2024] edition: 2024 | ||
//@[e2024] compile-flags: -Zunstable-options | ||
//@[e2024] check-pass | ||
|
||
#![deny(rust_2024_prelude_collisions)] | ||
trait Meow { | ||
fn poll(&self, _ctx: &mut core::task::Context<'_>) {} | ||
} | ||
impl<T> Meow for T {} | ||
fn main() { | ||
core::pin::pin!(async {}).poll(&mut context()); | ||
//[e2021]~^ ERROR trait method `poll` will become ambiguous in Rust 2024 | ||
//[e2021]~| WARN this is accepted in the current edition (Rust 2021) but is a hard error in Rust 2024! | ||
} | ||
|
||
fn context() -> core::task::Context<'static> { | ||
loop {} | ||
} |
21 changes: 21 additions & 0 deletions
21
tests/ui/rust-2024/prelude-migration/future-poll-not-future-pinned.e2021.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,21 @@ | ||
//@ revisions: e2021 e2024 | ||
//@[e2021] edition: 2021 | ||
//@[e2021] run-rustfix | ||
//@[e2024] edition: 2024 | ||
//@[e2024] compile-flags: -Zunstable-options | ||
//@[e2024] check-pass | ||
|
||
#![deny(rust_2024_prelude_collisions)] | ||
trait Meow { | ||
fn poll(&self) {} | ||
} | ||
impl<T> Meow for T {} | ||
fn main() { | ||
// This is a deliberate false positive. | ||
// While `()` does not implement `Future` and can therefore not be ambiguous, we | ||
// do not check that in the lint, as that introduces additional complexities. | ||
// Just checking whether the self type is `Pin<&mut _>` is enough. | ||
Meow::poll(&core::pin::pin!(())); | ||
//[e2021]~^ ERROR trait method `poll` will become ambiguous in Rust 2024 | ||
//[e2021]~| WARN this is accepted in the current edition (Rust 2021) but is a hard error in Rust 2024! | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/ui/rust-2024/prelude-migration/future-poll-not-future-pinned.e2021.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,16 @@ | ||
error: trait method `poll` will become ambiguous in Rust 2024 | ||
--> $DIR/future-poll-not-future-pinned.rs:18:5 | ||
| | ||
LL | core::pin::pin!(()).poll(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `Meow::poll(&core::pin::pin!(()))` | ||
| | ||
= warning: this is accepted in the current edition (Rust 2021) but is a hard error in Rust 2024! | ||
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/prelude.html> | ||
note: the lint level is defined here | ||
--> $DIR/future-poll-not-future-pinned.rs:8:9 | ||
| | ||
LL | #![deny(rust_2024_prelude_collisions)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
21 changes: 21 additions & 0 deletions
21
tests/ui/rust-2024/prelude-migration/future-poll-not-future-pinned.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,21 @@ | ||
//@ revisions: e2021 e2024 | ||
//@[e2021] edition: 2021 | ||
//@[e2021] run-rustfix | ||
//@[e2024] edition: 2024 | ||
//@[e2024] compile-flags: -Zunstable-options | ||
//@[e2024] check-pass | ||
|
||
#![deny(rust_2024_prelude_collisions)] | ||
trait Meow { | ||
fn poll(&self) {} | ||
} | ||
impl<T> Meow for T {} | ||
fn main() { | ||
// This is a deliberate false positive. | ||
// While `()` does not implement `Future` and can therefore not be ambiguous, we | ||
// do not check that in the lint, as that introduces additional complexities. | ||
// Just checking whether the self type is `Pin<&mut _>` is enough. | ||
core::pin::pin!(()).poll(); | ||
//[e2021]~^ ERROR trait method `poll` will become ambiguous in Rust 2024 | ||
//[e2021]~| WARN this is accepted in the current edition (Rust 2021) but is a hard error in Rust 2024! | ||
} |
15 changes: 15 additions & 0 deletions
15
tests/ui/rust-2024/prelude-migration/future-poll-not-future.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,15 @@ | ||
//@ revisions: e2021 e2024 | ||
//@[e2021] edition: 2021 | ||
//@[e2024] edition: 2024 | ||
//@[e2024] compile-flags: -Zunstable-options | ||
//@ check-pass | ||
|
||
#![deny(rust_2024_prelude_collisions)] | ||
trait Meow { | ||
fn poll(&self) {} | ||
} | ||
impl<T> Meow for T {} | ||
fn main() { | ||
// As the self type here is not `Pin<&mut _>`, the lint does not fire. | ||
().poll(); | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/ui/rust-2024/prelude-migration/in_2024_compatibility.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,17 @@ | ||
//@ edition: 2021 | ||
|
||
#![deny(rust_2024_compatibility)] | ||
|
||
trait Meow { | ||
fn poll(&self, _ctx: &mut core::task::Context<'_>) {} | ||
} | ||
impl<T> Meow for T {} | ||
fn main() { | ||
core::pin::pin!(async {}).poll(&mut context()); | ||
//~^ ERROR trait method `poll` will become ambiguous in Rust 2024 | ||
//~| WARN this is accepted in the current edition (Rust 2021) but is a hard error in Rust 2024! | ||
} | ||
|
||
fn context() -> core::task::Context<'static> { | ||
loop {} | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/ui/rust-2024/prelude-migration/in_2024_compatibility.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,17 @@ | ||
error: trait method `poll` will become ambiguous in Rust 2024 | ||
--> $DIR/in_2024_compatibility.rs:10:5 | ||
| | ||
LL | core::pin::pin!(async {}).poll(&mut context()); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `Meow::poll(&core::pin::pin!(async {}), &mut context())` | ||
| | ||
= warning: this is accepted in the current edition (Rust 2021) but is a hard error in Rust 2024! | ||
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/prelude.html> | ||
note: the lint level is defined here | ||
--> $DIR/in_2024_compatibility.rs:3:9 | ||
| | ||
LL | #![deny(rust_2024_compatibility)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: `#[deny(rust_2024_prelude_collisions)]` implied by `#[deny(rust_2024_compatibility)]` | ||
|
||
error: aborting due to 1 previous error | ||
|
29 changes: 29 additions & 0 deletions
29
tests/ui/rust-2024/prelude-migration/into-future-adt.e2021.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,29 @@ | ||
//@ revisions: e2021 e2024 | ||
//@[e2021] edition: 2021 | ||
//@[e2021] run-rustfix | ||
//@[e2024] edition: 2024 | ||
//@[e2024] compile-flags: -Zunstable-options | ||
//@[e2024] check-pass | ||
|
||
#![deny(rust_2024_prelude_collisions)] | ||
trait Meow { | ||
fn into_future(&self) {} | ||
} | ||
impl Meow for Cat {} | ||
|
||
struct Cat; | ||
|
||
impl core::future::IntoFuture for Cat { | ||
type Output = (); | ||
type IntoFuture = core::future::Ready<()>; | ||
|
||
fn into_future(self) -> Self::IntoFuture { | ||
core::future::ready(()) | ||
} | ||
} | ||
|
||
fn main() { | ||
Meow::into_future(&Cat); | ||
//[e2021]~^ ERROR trait method `into_future` will become ambiguous in Rust 2024 | ||
//[e2021]~| WARN this is accepted in the current edition (Rust 2021) but is a hard error in Rust 2024! | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/ui/rust-2024/prelude-migration/into-future-adt.e2021.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,16 @@ | ||
error: trait method `into_future` will become ambiguous in Rust 2024 | ||
--> $DIR/into-future-adt.rs:26:5 | ||
| | ||
LL | Cat.into_future(); | ||
| ^^^^^^^^^^^^^^^^^ help: disambiguate the associated function: `Meow::into_future(&Cat)` | ||
| | ||
= warning: this is accepted in the current edition (Rust 2021) but is a hard error in Rust 2024! | ||
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/prelude.html> | ||
note: the lint level is defined here | ||
--> $DIR/into-future-adt.rs:8:9 | ||
| | ||
LL | #![deny(rust_2024_prelude_collisions)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
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,29 @@ | ||
//@ revisions: e2021 e2024 | ||
//@[e2021] edition: 2021 | ||
//@[e2021] run-rustfix | ||
//@[e2024] edition: 2024 | ||
//@[e2024] compile-flags: -Zunstable-options | ||
//@[e2024] check-pass | ||
|
||
#![deny(rust_2024_prelude_collisions)] | ||
trait Meow { | ||
fn into_future(&self) {} | ||
} | ||
impl Meow for Cat {} | ||
|
||
struct Cat; | ||
|
||
impl core::future::IntoFuture for Cat { | ||
type Output = (); | ||
type IntoFuture = core::future::Ready<()>; | ||
|
||
fn into_future(self) -> Self::IntoFuture { | ||
core::future::ready(()) | ||
} | ||
} | ||
|
||
fn main() { | ||
Cat.into_future(); | ||
//[e2021]~^ ERROR trait method `into_future` will become ambiguous in Rust 2024 | ||
//[e2021]~| WARN this is accepted in the current edition (Rust 2021) but is a hard error in Rust 2024! | ||
} |
24 changes: 24 additions & 0 deletions
24
tests/ui/rust-2024/prelude-migration/into-future-already-into-future.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,24 @@ | ||
//@ revisions: e2021 e2024 | ||
//@[e2021] edition: 2021 | ||
//@[e2024] edition: 2024 | ||
//@[e2024] compile-flags: -Zunstable-options | ||
//@ check-pass | ||
|
||
#![deny(rust_2024_prelude_collisions)] | ||
|
||
use core::future::IntoFuture; | ||
|
||
struct Cat; | ||
|
||
impl IntoFuture for Cat { | ||
type Output = (); | ||
type IntoFuture = core::future::Ready<()>; | ||
|
||
fn into_future(self) -> Self::IntoFuture { | ||
core::future::ready(()) | ||
} | ||
} | ||
|
||
fn main() { | ||
let _ = Cat.into_future(); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be good to add a test to demonstrate that this is picked up in the
rust_2024_compatibility
lint group, as in:tests/ui/unsafe/unsafe_op_in_unsafe_fn/in_2024_compatibility.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea, added it