-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Fix prelude collision lint suggestion for generics with lifetimes #88496
Merged
bors
merged 3 commits into
rust-lang:master
from
m-ou-se:prelude-collision-lifetime-generics
Aug 31, 2021
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
30 changes: 30 additions & 0 deletions
30
src/test/ui/rust-2021/future-prelude-collision-generic-trait.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,30 @@ | ||
// See https://github.com/rust-lang/rust/issues/88470 | ||
// run-rustfix | ||
// edition:2018 | ||
// check-pass | ||
#![warn(rust_2021_prelude_collisions)] | ||
#![allow(dead_code)] | ||
#![allow(unused_imports)] | ||
|
||
pub trait PyTryFrom<'v, T>: Sized { | ||
fn try_from<V>(value: V) -> Result<&'v Self, T>; | ||
} | ||
|
||
pub trait PyTryInto<T>: Sized { | ||
fn try_into(&self) -> Result<&T, i32>; | ||
} | ||
|
||
struct Foo; | ||
|
||
impl<U> PyTryInto<U> for Foo | ||
where | ||
U: for<'v> PyTryFrom<'v, i32>, | ||
{ | ||
fn try_into(&self) -> Result<&U, i32> { | ||
<U as PyTryFrom<'_, _>>::try_from(self) | ||
//~^ WARNING trait-associated function `try_from` will become ambiguous in Rust 2021 | ||
//~| this is accepted in the current edition (Rust 2018) | ||
} | ||
} | ||
|
||
fn main() {} |
30 changes: 30 additions & 0 deletions
30
src/test/ui/rust-2021/future-prelude-collision-generic-trait.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,30 @@ | ||
// See https://github.com/rust-lang/rust/issues/88470 | ||
// run-rustfix | ||
// edition:2018 | ||
// check-pass | ||
#![warn(rust_2021_prelude_collisions)] | ||
#![allow(dead_code)] | ||
#![allow(unused_imports)] | ||
|
||
pub trait PyTryFrom<'v, T>: Sized { | ||
fn try_from<V>(value: V) -> Result<&'v Self, T>; | ||
} | ||
|
||
pub trait PyTryInto<T>: Sized { | ||
fn try_into(&self) -> Result<&T, i32>; | ||
} | ||
|
||
struct Foo; | ||
|
||
impl<U> PyTryInto<U> for Foo | ||
where | ||
U: for<'v> PyTryFrom<'v, i32>, | ||
{ | ||
fn try_into(&self) -> Result<&U, i32> { | ||
U::try_from(self) | ||
//~^ WARNING trait-associated function `try_from` will become ambiguous in Rust 2021 | ||
//~| this is accepted in the current edition (Rust 2018) | ||
} | ||
} | ||
|
||
fn main() {} |
16 changes: 16 additions & 0 deletions
16
src/test/ui/rust-2021/future-prelude-collision-generic-trait.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 @@ | ||
warning: trait-associated function `try_from` will become ambiguous in Rust 2021 | ||
--> $DIR/future-prelude-collision-generic-trait.rs:24:9 | ||
| | ||
LL | U::try_from(self) | ||
| ^^^^^^^^^^^ help: disambiguate the associated function: `<U as PyTryFrom<'_, _>>::try_from` | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/future-prelude-collision-generic-trait.rs:5: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: 1 warning emitted | ||
|
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
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
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.
This used
.count()
before, and.own_counts()
now, to get counts for each kind of generics individually. So that does not include the parent counts. I couldn't find any case where that makes a difference though. Will this break (or fix) anything?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.
For a trait, no, traits never have parents.