-
Notifications
You must be signed in to change notification settings - Fork 13.7k
add Iterator::contains #141994
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 Iterator::contains #141994
Conversation
r? @ibraheemdev
rustbot has assigned @ibraheemdev.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.
Use r?
to explicitly pick a reviewer
This comment has been minimized.
This comment has been minimized.
rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead.
cc @rust-lang/rust-analyzer
This comment has been minimized.
This comment has been minimized.
cb04a2d
to
606cd35
Compare
This comment has been minimized.
This comment has been minimized.
src/tools/rust-analyzer/crates/ide-assists/src/handlers/convert_bool_to_enum.rs
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
9e27be5
to
8fccd73
Compare
r? libs-api to confirm that this is fine to merge with nightly breakage due to the conflicts.
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.
Thank you!
Stabilizing this is going to be blocked on #89151 to avoid breaking code that currently uses Itertools's contains
. The signatures are different — itertools looks more like HashSet::contains
with a bound of Self::Item: Borrow<Q>, Q: PartialEq
whereas what we are planning for the standard library is Q: PartialEq<Self::Item>
.
https://docs.rs/itertools/0.14.0/itertools/trait.Itertools.html#method.contains
@rfcbot fcp merge
Even though this is an unstable addition, let me run this by the team to assess whether we want to take this step now. This PR causes new warnings in code that uses itertools::Itertools::contains
(which is one of the more widely used itertools extension trait methods).
Unfortunately the warning is 100% spurious, because we have no intention of stabilizing Iterator::contains
in a way that would cause the breakage that it warns about. With #89151, code like the following from rust-analyzer will retain its current behavior because Iterator
is a supertrait of Itertools
so the supertrait method will be shadowed instead of ambiguous.
If we merge this as-is, a lot of people will get warnings and uselessly rewrite their code.
warning: a method with this name may be added to the standard library in the future --> crates/ide-assists/src/handlers/convert_bool_to_enum.rs:381:48 | 381 | if !bin_expr.lhs()?.syntax().descendants().contains(name.syntax()) { | ^^^^^^^^ | = warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior! = note: for more information, see issue #48919 <https://github.com/rust-lang/rust/issues/48919> = help: call with fully qualified syntax `itertools::Itertools::contains(...)` to keep using the current method = note: `#[warn(unstable_name_collisions)]` on by default help: add `#![feature(iter_contains)]` to the crate attributes to enable `std::iter::Iterator::contains` --> crates/ide-assists/src/lib.rs:63:1 | 63 + #![feature(iter_contains)] | warning: a method with this name may be added to the standard library in the future --> crates/ide-assists/src/handlers/convert_bool_to_enum.rs:447:41 | 447 | if !receiver.syntax().descendants().contains(name.syntax()) { | ^^^^^^^^ | = warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior! = note: for more information, see issue #48919 <https://github.com/rust-lang/rust/issues/48919> = help: call with fully qualified syntax `itertools::Itertools::contains(...)` to keep using the current method help: add `#![feature(iter_contains)]` to the crate attributes to enable `std::iter::Iterator::contains` --> crates/ide-assists/src/lib.rs:63:1 | 63 + #![feature(iter_contains)] |
Team member @dtolnay has proposed to merge this. The next step is review by the rest of the tagged team members:
No concerns currently listed.
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!
See this document for info about what commands tagged team members can give me.
I think I would prefer to block this PR on not necessarily stabilizing #89151, but just a compiler fix that prevents the unstable_name_collisions
warning in the case of supertrait colliding methods.
I'm also happy to block this on #89151.
Uh oh!
There was an error while loading. Please reload this page.
Tracking issue: #127494
Continuing from where #135018 left off