Skip to content

Conversation

@joshtriplett
Copy link
Member

@joshtriplett joshtriplett commented Dec 10, 2025

into_iter serves no function if not iterated over.

If it's being used just to consume self, that would be better served by drop.

@rustbot rustbot added 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 Dec 10, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 10, 2025

r? @joboet

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

@rust-log-analyzer

This comment has been minimized.

`into_iter` serves no function if not iterated over.

If it's being used just to consume `self`, that would be better served
by `drop`.
@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu-llvm-20-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
1 error[E0507]: cannot move out of `y`, a captured variable in an `Fn` closure
-   --> $DIR/unboxed-closures-move-upvar-from-non-once-ref-closure.rs:12:9
+   --> $DIR/unboxed-closures-move-upvar-from-non-once-ref-closure.rs:12:17
3    |
4 LL |     let y = vec![format!("World")];
5    |         - captured outer variable

6 LL |     call(|| {
7    |          -- captured by this `Fn` closure
- LL |         y.into_iter();
-    |         ^ ----------- `y` moved due to this method call
-    |         |
-    |         move occurs because `y` has type `Vec<String>`, which does not implement the `Copy` trait
+ LL |         let _ = y.into_iter();
+    |                 ^ ----------- `y` moved due to this method call
+    |                 |
+    |                 move occurs because `y` has type `Vec<String>`, which does not implement the `Copy` trait
12    |
13 help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but `FnOnce` closures may consume them only once
14   --> $DIR/unboxed-closures-move-upvar-from-non-once-ref-closure.rs:5:28

19   --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
20 help: you can `clone` the value and consume it, but this might not be your desired behavior
21    |
- LL |         <Vec<String> as Clone>::clone(&y).into_iter();
-    |         +++++++++++++++++++++++++++++++ +
+ LL |         let _ = <Vec<String> as Clone>::clone(&y).into_iter();
+    |                 +++++++++++++++++++++++++++++++ +
24 help: consider cloning the value if the performance cost is acceptable
25    |
- LL |         y.clone().into_iter();
-    |          ++++++++
+ LL |         let _ = y.clone().into_iter();
---

Note: some mismatched output was normalized before being compared
-   --> /checkout/tests/ui/borrowck/unboxed-closures-move-upvar-from-non-once-ref-closure.rs:12:17
+   --> $DIR/unboxed-closures-move-upvar-from-non-once-ref-closure.rs:12:17
+ LL |         let _ = y.into_iter();
+    |                 ^ ----------- `y` moved due to this method call
+    |                 |
+    |                 move occurs because `y` has type `Vec<String>`, which does not implement the `Copy` trait
+ LL |         let _ = <Vec<String> as Clone>::clone(&y).into_iter();
+    |                 +++++++++++++++++++++++++++++++ +
+ LL |         let _ = y.clone().into_iter();
+    |                  ++++++++


The actual stderr differed from the expected stderr
Saved the actual fixed to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/borrowck/unboxed-closures-move-upvar-from-non-once-ref-closure/unboxed-closures-move-upvar-from-non-once-ref-closure.fixed`
diff of fixed:

9 fn main() {
10     let y = vec![format!("World")];
11     call(|| {
-         <Vec<String> as Clone>::clone(&y.clone()).into_iter();
+         let _ = <Vec<String> as Clone>::clone(&y.clone()).into_iter();
13         //~^ ERROR cannot move out of `y`, a captured variable in an `Fn` closure
14     });
15 }


The actual fixed differed from the expected fixed
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args borrowck/unboxed-closures-move-upvar-from-non-once-ref-closure.rs`

error: 2 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/borrowck/unboxed-closures-move-upvar-from-non-once-ref-closure.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/borrowck/unboxed-closures-move-upvar-from-non-once-ref-closure" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error[E0507]: cannot move out of `y`, a captured variable in an `Fn` closure
##[error]  --> /checkout/tests/ui/borrowck/unboxed-closures-move-upvar-from-non-once-ref-closure.rs:12:17
   |
LL |     let y = vec![format!("World")];
   |         - captured outer variable
LL |     call(|| {
   |          -- captured by this `Fn` closure
LL |         let _ = y.into_iter();
   |                 ^ ----------- `y` moved due to this method call
   |                 |
   |                 move occurs because `y` has type `Vec<String>`, which does not implement the `Copy` trait
   |
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but `FnOnce` closures may consume them only once
  --> /checkout/tests/ui/borrowck/unboxed-closures-move-upvar-from-non-once-ref-closure.rs:5:28
   |
LL | fn call<F>(f: F) where F : Fn() {
   |                            ^^^^
note: `into_iter` takes ownership of the receiver `self`, which moves `y`
  --> /rustc/FAKE_PREFIX/library/core/src/iter/traits/collect.rs:311:17
help: you can `clone` the value and consume it, but this might not be your desired behavior
   |
LL |         let _ = <Vec<String> as Clone>::clone(&y).into_iter();
   |                 +++++++++++++++++++++++++++++++ +
help: consider cloning the value if the performance cost is acceptable
   |
LL |         let _ = y.clone().into_iter();
   |                  ++++++++

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants