rust icon indicating copy to clipboard operation
rust copied to clipboard

suggest `into_iter()` when `Iterator` method called on `impl IntoIterator`

Open d-sonuga opened this issue 1 year ago • 2 comments

Fix for issue #117711.

d-sonuga avatar Jan 13 '24 15:01 d-sonuga

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @TaKO8Ki (or someone else) soon.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

rustbot avatar Jan 13 '24 15:01 rustbot

r? compiler

compiler-errors avatar Feb 02 '24 17:02 compiler-errors

:umbrella: The latest upstream changes (presumably #120722) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Feb 07 '24 02:02 bors

The job x86_64-gnu-llvm-16 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
GITHUB_ACTION=__run_7
GITHUB_ACTIONS=true
GITHUB_ACTION_REF=
GITHUB_ACTION_REPOSITORY=
GITHUB_ACTOR=d-sonuga
GITHUB_API_URL=https://api.github.com
GITHUB_BASE_REF=master
GITHUB_ENV=/home/runner/work/_temp/_runner_file_commands/set_env_c8b758d6-7bfc-4153-9739-0ae2d7633fde
GITHUB_EVENT_NAME=pull_request
---
GITHUB_SERVER_URL=https://github.com
GITHUB_SHA=bc9cc99352afadd94676f625d1a7290095c91ec7
GITHUB_STATE=/home/runner/work/_temp/_runner_file_commands/save_state_c8b758d6-7bfc-4153-9739-0ae2d7633fde
GITHUB_STEP_SUMMARY=/home/runner/work/_temp/_runner_file_commands/step_summary_c8b758d6-7bfc-4153-9739-0ae2d7633fde
GITHUB_TRIGGERING_ACTOR=d-sonuga
GITHUB_WORKFLOW_REF=rust-lang/rust/.github/workflows/ci.yml@refs/pull/119928/merge
GITHUB_WORKFLOW_SHA=bc9cc99352afadd94676f625d1a7290095c91ec7
GITHUB_WORKSPACE=/home/runner/work/rust/rust
GOROOT_1_19_X64=/opt/hostedtoolcache/go/1.19.13/x64
---
#12 writing image sha256:f9fe0979ac768bb263744510eed48c1d0386436631cc2ca95679fce9c649519b done
#12 naming to docker.io/library/rust-ci done
#12 DONE 10.0s
##[endgroup]
Setting extra environment values for docker:  --env ENABLE_GCC_CODEGEN=1 --env GCC_EXEC_PREFIX=/usr/lib/gcc/
[CI_JOB_NAME=x86_64-gnu-llvm-16]
##[group]Clock drift check
  local time: Mon Feb 12 08:50:08 UTC 2024
  network time: Mon, 12 Feb 2024 08:50:08 GMT
  network time: Mon, 12 Feb 2024 08:50:08 GMT
##[endgroup]
sccache: Starting the server...
##[group]Configure the build
configure: processing command line
configure: 
configure: build.configure-args := ['--build=x86_64-unknown-linux-gnu', '--llvm-root=/usr/lib/llvm-16', '--enable-llvm-link-shared', '--set', 'rust.thin-lto-import-instr-limit=10', '--set', 'change-id=99999999', '--enable-verbose-configure', '--enable-sccache', '--disable-manage-submodules', '--enable-locked-deps', '--enable-cargo-native-static', '--set', 'rust.codegen-units-std=1', '--set', 'dist.compression-profile=balanced', '--dist-compression-formats=xz', '--set', 'build.optimized-compiler-builtins', '--disable-dist-src', '--release-channel=nightly', '--enable-debug-assertions', '--enable-overflow-checks', '--enable-llvm-assertions', '--set', 'rust.verify-llvm-ir', '--set', 'rust.codegen-backends=llvm,cranelift,gcc', '--set', 'llvm.static-libstdcpp', '--enable-new-symbol-mangling']
configure: target.x86_64-unknown-linux-gnu.llvm-config := /usr/lib/llvm-16/bin/llvm-config
configure: llvm.link-shared     := True
configure: rust.thin-lto-import-instr-limit := 10
configure: change-id            := 99999999
---

---- [ui] tests/ui/did_you_mean/collect-without-into-iter-call.rs stdout ----
diff of stderr:

26 LL | fn process(items: impl IntoIterator<Item = String>) -> Vec<String> {
27    |                   -------------------------------- method `collect` not found for this type parameter
28 LL |     items.collect()
-    |           ^^^^^^^ `impl IntoIterator<Item = String>` is not an iterator
+    |           ^^^^^^^ method cannot be called on `impl IntoIterator<Item = String>` due to unsatisfied trait bounds
30    |
- help: call `.into_iter()` first
+    = help: items from traits can only be used if the type parameter is bounded by the trait
+ help: the following trait defines an item `collect`, perhaps you need to restrict type parameter `impl IntoIterator<Item = String>` with it:
- LL |     items.into_iter().collect()
-    |           ++++++++++++
-    |           ++++++++++++
+ LL | fn process(items: impl IntoIterator<Item = String> + Iterator) -> Vec<String> {
35 
36 error: aborting due to 3 previous errors
37 

---
--- stderr -------------------------------
error[E0599]: no method named `map` found for opaque type `impl IntoIterator<Item = i32>` in the current scope
##[error]  --> /checkout/tests/ui/did_you_mean/collect-without-into-iter-call.rs:6:29
   |
LL |     let other_items = items.map(|i| i + 1);
   |                             ^^^ `impl IntoIterator<Item = i32>` is not an iterator
   |
help: call `.into_iter()` first
Build completed unsuccessfully in 0:14:17
Build completed unsuccessfully in 0:14:17
LL |     let other_items = items.into_iter().map(|i| i + 1);

error[E0599]: no method named `collect` found for opaque type `impl IntoIterator<Item = i32>` in the current scope
##[error]  --> /checkout/tests/ui/did_you_mean/collect-without-into-iter-call.rs:8:31
   |
   |
LL |     let vec: Vec<i32> = items.collect();
   |                               ^^^^^^^ `impl IntoIterator<Item = i32>` is not an iterator
   |
help: call `.into_iter()` first
   |
LL |     let vec: Vec<i32> = items.into_iter().collect();

error[E0599]: no method named `collect` found for type parameter `impl IntoIterator<Item = String>` in the current scope
##[error]  --> /checkout/tests/ui/did_you_mean/collect-without-into-iter-call.rs:17:11
   |
   |
LL | fn process(items: impl IntoIterator<Item = String>) -> Vec<String> {
   |                   -------------------------------- method `collect` not found for this type parameter
LL |     items.collect()
   |           ^^^^^^^ method cannot be called on `impl IntoIterator<Item = String>` due to unsatisfied trait bounds
   = help: items from traits can only be used if the type parameter is bounded by the trait
   = help: items from traits can only be used if the type parameter is bounded by the trait
help: the following trait defines an item `collect`, perhaps you need to restrict type parameter `impl IntoIterator<Item = String>` with it:
   |
LL | fn process(items: impl IntoIterator<Item = String> + Iterator) -> Vec<String> {

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0599`.

rust-log-analyzer avatar Feb 12 '24 09:02 rust-log-analyzer

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
GITHUB_ACTION=__run_7
GITHUB_ACTIONS=true
GITHUB_ACTION_REF=
GITHUB_ACTION_REPOSITORY=
GITHUB_ACTOR=d-sonuga
GITHUB_API_URL=https://api.github.com
GITHUB_BASE_REF=master
GITHUB_ENV=/home/runner/work/_temp/_runner_file_commands/set_env_d8b164cb-d56e-48d7-95e0-cd8e8aeadd89
GITHUB_EVENT_NAME=pull_request
---
GITHUB_SERVER_URL=https://github.com
GITHUB_SHA=9a9b77f326c49c0b90ed72ac7d83f9011c07e8a3
GITHUB_STATE=/home/runner/work/_temp/_runner_file_commands/save_state_d8b164cb-d56e-48d7-95e0-cd8e8aeadd89
GITHUB_STEP_SUMMARY=/home/runner/work/_temp/_runner_file_commands/step_summary_d8b164cb-d56e-48d7-95e0-cd8e8aeadd89
GITHUB_TRIGGERING_ACTOR=d-sonuga
GITHUB_WORKFLOW_REF=rust-lang/rust/.github/workflows/ci.yml@refs/pull/119928/merge
GITHUB_WORKFLOW_SHA=9a9b77f326c49c0b90ed72ac7d83f9011c07e8a3
GITHUB_WORKSPACE=/home/runner/work/rust/rust
GOROOT_1_19_X64=/opt/hostedtoolcache/go/1.19.13/x64
---
#4 [auth] library/ubuntu:pull token for registry-1.docker.io
#4 DONE 0.0s

#3 [internal] load metadata for docker.io/library/ubuntu:22.04
#3 ERROR: failed to authorize: failed to fetch oauth token: unexpected status from POST request to https://auth.docker.io/token: 500 Internal Server Error
 > [internal] load metadata for docker.io/library/ubuntu:22.04:
------
Dockerfile:1
--------------------
--------------------
   1 | >>> FROM ubuntu:22.04
   2 |     
   3 |     ARG DEBIAN_FRONTEND=noninteractive
--------------------
ERROR: failed to solve: ubuntu:22.04: failed to authorize: failed to fetch oauth token: unexpected status from POST request to https://auth.docker.io/token: 500 Internal Server Error
#0 building with "default" instance using docker driver

#1 [internal] load .dockerignore
#1 transferring context: 2B done
---
#3 [auth] library/ubuntu:pull token for registry-1.docker.io
#3 DONE 0.0s

#4 [internal] load metadata for docker.io/library/ubuntu:22.04
#4 ERROR: failed to authorize: failed to fetch oauth token: unexpected status from POST request to https://auth.docker.io/token: 500 Internal Server Error
 > [internal] load metadata for docker.io/library/ubuntu:22.04:
------
Dockerfile:1
--------------------
--------------------
   1 | >>> FROM ubuntu:22.04
   2 |     
   3 |     ARG DEBIAN_FRONTEND=noninteractive
--------------------
ERROR: failed to solve: ubuntu:22.04: failed to authorize: failed to fetch oauth token: unexpected status from POST request to https://auth.docker.io/token: 500 Internal Server Error
#0 building with "default" instance using docker driver

#1 [internal] load .dockerignore
#1 transferring context: 2B done
---
#3 [auth] library/ubuntu:pull token for registry-1.docker.io
#3 DONE 0.0s

#4 [internal] load metadata for docker.io/library/ubuntu:22.04
#4 ERROR: failed to authorize: failed to fetch oauth token: unexpected status from POST request to https://auth.docker.io/token: 500 Internal Server Error
 > [internal] load metadata for docker.io/library/ubuntu:22.04:
------
Dockerfile:1
--------------------
--------------------
   1 | >>> FROM ubuntu:22.04
   2 |     
   3 |     ARG DEBIAN_FRONTEND=noninteractive
--------------------
ERROR: failed to solve: ubuntu:22.04: failed to authorize: failed to fetch oauth token: unexpected status from POST request to https://auth.docker.io/token: 500 Internal Server Error
#0 building with "default" instance using docker driver

#1 [internal] load .dockerignore
#1 transferring context: 2B done
---
#3 [auth] library/ubuntu:pull token for registry-1.docker.io
#3 DONE 0.0s

#4 [internal] load metadata for docker.io/library/ubuntu:22.04
#4 ERROR: failed to authorize: failed to fetch oauth token: unexpected status from POST request to https://auth.docker.io/token: 500 Internal Server Error
 > [internal] load metadata for docker.io/library/ubuntu:22.04:
------
Dockerfile:1
--------------------
--------------------
   1 | >>> FROM ubuntu:22.04
   2 |     
   3 |     ARG DEBIAN_FRONTEND=noninteractive
--------------------
ERROR: failed to solve: ubuntu:22.04: failed to authorize: failed to fetch oauth token: unexpected status from POST request to https://auth.docker.io/token: 500 Internal Server Error
#0 building with "default" instance using docker driver

#1 [internal] load .dockerignore
#1 transferring context: 2B done
---
#3 [auth] library/ubuntu:pull token for registry-1.docker.io
#3 DONE 0.0s

#4 [internal] load metadata for docker.io/library/ubuntu:22.04
#4 ERROR: failed to authorize: failed to fetch oauth token: unexpected status from POST request to https://auth.docker.io/token: 500 Internal Server Error
 > [internal] load metadata for docker.io/library/ubuntu:22.04:
------
Dockerfile:1
--------------------
--------------------
   1 | >>> FROM ubuntu:22.04
   2 |     
   3 |     ARG DEBIAN_FRONTEND=noninteractive
--------------------
ERROR: failed to solve: ubuntu:22.04: failed to authorize: failed to fetch oauth token: unexpected status from POST request to https://auth.docker.io/token: 500 Internal Server Error
##[error]Process completed with exit code 1.
Post job cleanup.

rust-log-analyzer avatar Feb 12 '24 15:02 rust-log-analyzer

@bors r+ rollup

compiler-errors avatar Feb 16 '24 15:02 compiler-errors

:pushpin: Commit e99766d885a9a2c714aa58e06712d30a96b24514 has been approved by compiler-errors

It is now in the queue for this repository.

bors avatar Feb 16 '24 15:02 bors