Skip to content
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 IntoIterator for Box<[T]> + edition 2024-specific lints #124097

Merged
merged 6 commits into from
May 21, 2024

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Apr 17, 2024

  • Adds a similar method probe opt-out mechanism to the [T;N]: IntoIterator implementation for edition 2021.
  • Adjusts the relevant lints (shadowed .into_iter() calls, new source of method ambiguity).
  • Adds some tests.
  • Took the liberty to rework the logic in the ARRAY_INTO_ITER lint, since it was kind of confusing.

Based mostly off of #116607.

ACP: rust-lang/libs-team#263
References #59878
Tracking for Rust 2024: #123759

Crater run was done here: #116607 (comment)
Consensus afaict was that there is too much breakage, so let's do this in an edition-dependent way much like [T; N]: IntoIterator.

@rustbot
Copy link
Collaborator

rustbot commented Apr 17, 2024

r? @oli-obk

rustbot has assigned @oli-obk.
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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 17, 2024
@rustbot
Copy link
Collaborator

rustbot commented Apr 17, 2024

This PR changes Stable MIR

cc @oli-obk, @celinval, @ouz-a

@compiler-errors compiler-errors added I-lang-nominated The issue / PR has been nominated for discussion during a lang team meeting. I-libs-api-nominated The issue / PR has been nominated for discussion during a libs-api team meeting. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. needs-fcp This change is insta-stable, so needs a completed FCP to proceed. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 17, 2024
@compiler-errors
Copy link
Member Author

Needs a T-compiler review of the impl first, then can go into FCP.

@@ -184,7 +184,7 @@ impl<'a, T> IntoIterator for &'a P<[T]> {
type Item = &'a T;
type IntoIter = slice::Iter<'a, T>;
fn into_iter(self) -> Self::IntoIter {
self.ptr.into_iter()
self.ptr.iter()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very funny to see somewhere in the compiler where we were relying on this behavior.

@rust-log-analyzer

This comment has been minimized.

@tmandry
Copy link
Member

tmandry commented Apr 17, 2024

I looked over the PR and I think we can kick off FCP in tandem with code review. The implementation includes a full migration that behaves as I'd expect.

@rust-lang/lang Are we okay with applying the same method resolution hack used for slices in 2021 to boxed slices in 2024?

@rust-lang/libs-api Are we okay with insta-stabilizing impl<T> IntoIterator for Box<[T]> and applying the method resolution hack?

@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented Apr 17, 2024

Team member @tmandry 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!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Apr 17, 2024
@BurntSushi
Copy link
Member

The IntoIterator impl using vec::IntoIter<I, A> for Box<[T]> strikes me as a little odd, since Box<[T]> isn't a Vec. But I also can't necessarily come up with a specific concern with reusing the type other than "it seems weird."

@rustbot
Copy link
Collaborator

rustbot commented Apr 17, 2024

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@compiler-errors
Copy link
Member Author

compiler-errors commented Apr 18, 2024

For FCP folks, see some of the discussion in #116607 -- apparently reusing vec::IntoIter was discussed in a T-libs-api meeting and the consensus was that it was not desired to add a new type.


Also, this PR doesn't implement IntoIterator for Box<[T; N]>. That impl seems slightly less useful, since calling Box::new([1, 2, 3]).into_iter() already uses the IntoIterator for [T; N] impl via autoderef, so we already get an impl Iterator<Item = T>.

If anyone has a strong opinion, I could either add to this PR, or (ideally) add to this PR in a follow-up. It would only cause a breaking change when the user is relying on the exact array::Iter output type of [T; N], rather than the much larger fallout of this change.

@rust-log-analyzer

This comment has been minimized.

@clarfonthey
Copy link
Contributor

clarfonthey commented Apr 18, 2024

Also, this PR doesn't implement IntoIterator for Box<[T; N]>. That impl seems slightly less useful, since calling Box::new([1, 2, 3]).into_iter() already uses the IntoIterator for [T; N] impl via autoderef, so we already get an impl Iterator<Item = T>.

If anyone has a strong opinion, I could either add to this PR, or (ideally) add to this PR in a follow-up. It would only cause a breaking change when the user is relying on the exact array::Iter output type of [T; N], rather than the much larger fallout of this change.

My personal opinion here is that it would be desirable to have a heap-based iterator here, since using the array implementation would copy the entire array onto the stack before iterating. It also helps avoid the weird discrepancy between Box<[T]> and Box<[T; N]> having different performance implications.

Worth noting that a lot of people will use Box<[T; N]> also instead of [T; N] when N is large because they want to avoid storing the array on the stack, and iterating over it by copying it to the stack would go against these desires.

bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 18, 2024
…=<try>

[crate] Add `Box<[T; N]>: IntoIterator` without any method dispatch hacks

**Unlike** `Box<[T]>` (rust-lang#116607 (comment)), there's a much higher chance that this will not conflict with existing usages since it produces an iterator with the same type before/after this change, but let's test that theory with crater.

Ideally we have fewer migrations that are tangled up in hacks like `rustc_skip_during_method_dispatch`, so if this crater comes back clean, I'd strongly suggest landing this as-is.

As for the rationale for having this impl at all, I agree (as `@clarfonthey` pointed out in rust-lang#124097 (comment)) that it is generally better for any user to not require moving the array *out* of the box just to turn it into an iterator.
@rustbot
Copy link
Collaborator

rustbot commented May 14, 2024

Some changes occurred in src/tools/cargo

cc @ehuss

@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@WaffleLapkin WaffleLapkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me with the nits

&& !span.at_least_rust_2024()
{
// In this case, it wasn't really a prelude addition that was the problem.
// Instead, the problem is that the array-into_iter hack will no longer apply in Rust 2021.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is still the same?

Comment on lines 2124 to 2137
/// `Box` is fundamental, so coherence needs help understanding these impls are okay.
#[stable(feature = "boxed_slice_into_iter", since = "CURRENT_RUSTC_VERSION")]
impl<I, A: Allocator> !Iterator for Box<[I], A> {}

/// `Box` is fundamental, so coherence needs help understanding these impls are okay.
#[stable(feature = "boxed_slice_into_iter", since = "CURRENT_RUSTC_VERSION")]
impl<'a, I, A: Allocator> !Iterator for &'a Box<[I], A> {}

/// `Box` is fundamental, so coherence needs help understanding these impls are okay.
#[stable(feature = "boxed_slice_into_iter", since = "CURRENT_RUSTC_VERSION")]
impl<'a, I, A: Allocator> !Iterator for &'a mut Box<[I], A> {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are user facing docs, maybe we should write something that can be understood by normal users? (this can be a follow up)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fff I thought I fixed these. I'll copy them over from the other PR for Box<[T; N]> where I think did.

@WaffleLapkin
Copy link
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 15, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request May 15, 2024
…not-notable, r=fmease

rustdoc: Negative impls are not notable

In rust-lang#124097, we add `impl !Iterator for [T]` for coherence reasons, and since `Iterator` is a [notable trait](https://github.com/rust-lang/rust/blob/8387315ab3c26a57a1f53a90f188f0bc88514bca/library/core/src/iter/traits/iterator.rs#L40), this means that all `-> &[_]` now are tagged with a `!Iterator` impl as a notable trait.

I "fixed" the failing tests in that PR with 6cbbb8b, where I just blessed the tests, since I didn't want to mix these changes with that PR; however, don't believe negative impls are notable, and this PR aims to prevent these impls from being mentioned.

In the standard library, we use negative impls purely to guide coherence. They're not really a signal of anything useful to the end-user. If there ever is a case that we want negative impls to be mentioned as notable, this really should be an opt-in feature.
@bors
Copy link
Contributor

bors commented May 19, 2024

☔ The latest upstream changes (presumably #125006) made this pull request unmergeable. Please resolve the merge conflicts.

@compiler-errors
Copy link
Member Author

@bors r=WaffleLapkin

@bors
Copy link
Contributor

bors commented May 21, 2024

📌 Commit 917bb83 has been approved by WaffleLapkin

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 21, 2024
@bors
Copy link
Contributor

bors commented May 21, 2024

⌛ Testing commit 917bb83 with merge e8fbd99...

@bors
Copy link
Contributor

bors commented May 21, 2024

☀️ Test successful - checks-actions
Approved by: WaffleLapkin
Pushing e8fbd99 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 21, 2024
@bors bors merged commit e8fbd99 into rust-lang:master May 21, 2024
7 checks passed
@rustbot rustbot added this to the 1.80.0 milestone May 21, 2024
@bors bors mentioned this pull request May 21, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (e8fbd99): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.4% [0.3%, 0.5%] 4
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary -2.1%, secondary -3.4%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.1% [-2.1%, -2.1%] 1
Improvements ✅
(secondary)
-3.4% [-3.4%, -3.4%] 1
All ❌✅ (primary) -2.1% [-2.1%, -2.1%] 1

Cycles

Results (secondary -4.0%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-4.0% [-4.0%, -4.0%] 1
All ❌✅ (primary) - - 0

Binary size

Results (secondary 0.0%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.0% [0.0%, 0.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Bootstrap: 669.761s -> 671.391s (0.24%)
Artifact size: 316.16 MiB -> 315.47 MiB (-0.22%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. merged-by-bors This PR was explicitly merged by bors. needs-fcp This change is insta-stable, so needs a completed FCP to proceed. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet