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

Point out the type of associated types in every method call of iterator chains #105332

Merged
merged 12 commits into from
Dec 13, 2022

Conversation

estebank
Copy link
Contributor

@estebank estebank commented Dec 5, 2022

Partially address #105184 by pointing out the type of associated types in every method call of iterator chains:

note: the expression is of type `Map<std::slice::Iter<'_, {integer}>, [closure@src/test/ui/iterators/invalid-iterator-chain.rs:12:18: 12:21]>`
    --> src/test/ui/iterators/invalid-iterator-chain.rs:12:14
     |
10   |         vec![0, 1]
     |         ---------- this expression has type `Vec<{integer}>`
11   |             .iter()
     |              ------ associated type `std::iter::Iterator::Item` is `&{integer}` here
12   |             .map(|x| { x; })
     |              ^^^^^^^^^^^^^^^ associated type `std::iter::Iterator::Item` is `()` here

We also reduce the number of impls we mention when any of the candidates is an "exact match". This benefits the output of cases with numerics greatly.

Outstanding work would be to provide a structured suggestion for appropriate changes, like in this case detecting the spurious ; in the closure.

@rustbot
Copy link
Collaborator

rustbot commented Dec 5, 2022

r? @lcnr

(rustbot has picked a reviewer for you, use r? to override)

@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. labels Dec 5, 2022
@rust-log-analyzer

This comment was marked as resolved.

@compiler-errors
Copy link
Member

I think 42847b08439f853116064ec37c255db4776a5e2d should be pulled into a different PR since it's unrelated.

@bors

This comment was marked as resolved.

@oli-obk
Copy link
Contributor

oli-obk commented Dec 7, 2022

r? @oli-obk

@rustbot rustbot assigned oli-obk and unassigned lcnr Dec 7, 2022
compiler-errors and others added 9 commits December 11, 2022 09:46
When encountering an unmet obligation that affects a method chain, like
in iterator chains where one of the links has the wrong associated
type, we point at every method call and mention their evaluated
associated type at that point to give context to the user of where
expectations diverged from the code as written.

```
note: the expression is of type `Map<std::slice::Iter<'_, {integer}>, [closure@$DIR/invalid-iterator-chain.rs:12:18: 12:21]>`
  --> $DIR/invalid-iterator-chain.rs:12:14
   |
LL |         vec![0, 1]
   |         ---------- this expression has type `Vec<{integer}>`
LL |             .iter()
   |              ------ associated type `std::iter::Iterator::Item` is `&{integer}` here
LL |             .map(|x| { x; })
   |              ^^^^^^^^^^^^^^^ associated type `std::iter::Iterator::Item` is `()` here
```
@oli-obk
Copy link
Contributor

oli-obk commented Dec 11, 2022

Could be a good opportunity to move the entire ObligationCauseCode::FunctionArgumentObligation arm into a new module

@oli-obk
Copy link
Contributor

oli-obk commented Dec 12, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Dec 12, 2022

📌 Commit f4ed2d1 has been approved by oli-obk

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-review Status: Awaiting review from the assignee but also interested parties. labels Dec 12, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 13, 2022
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#104864 (Account for item-local in inner scope for E0425)
 - rust-lang#105332 (Point out the type of associated types in every method call of iterator chains)
 - rust-lang#105620 (Remove unnecessary uses of `clone`)
 - rust-lang#105625 (minor code cleanups)
 - rust-lang#105629 (rustdoc: stop treating everything in a trait item as a method)
 - rust-lang#105636 (Add check for local-storage value when changing "display line numbers" settings)
 - rust-lang#105639 (rustdoc: remove `type="text/css" from stylesheet links)
 - rust-lang#105640 (Adjust miri to still be optional)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 8917cc0 into rust-lang:master Dec 13, 2022
@rustbot rustbot added this to the 1.68.0 milestone Dec 13, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 14, 2022
Point at method chains on `E0271` errors

Follow up to rust-lang#105332. Fix rust-lang#33941. CC rust-lang#9082.

r? `@oli-obk`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 14, 2022
Point at method chains on `E0271` errors

Follow up to rust-lang#105332. Fix rust-lang#33941. CC rust-lang#9082.

r? ``@oli-obk``
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 15, 2022
Point at method chains on `E0271` errors

Follow up to rust-lang#105332. Fix rust-lang#33941. CC rust-lang#9082.

r? ```@oli-obk```
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 15, 2022
Point at method chains on `E0271` errors

Follow up to rust-lang#105332. Fix rust-lang#33941. CC rust-lang#9082.

r? `@oli-obk`
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 3, 2024
…piler-errors,estebank

Properly deal with GATs when looking for method chains to point at

Fixes rust-lang#121898.

~~While it prevents an ICE and the structured suggestion is correct, the method chain diagnostic notes are weird / useless / incorrect judging by a quick look. I guess I should improve that in this PR.~~ Sufficiently taken care of.

r? estebank or compiler-errors (rust-lang#105332, rust-lang#105674).
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 4, 2024
…ompiler-errors,estebank

Properly deal with GATs when looking for method chains to point at

Fixes rust-lang#121898.

~~While it prevents an ICE and the structured suggestion is correct, the method chain diagnostic notes are weird / useless / incorrect judging by a quick look. I guess I should improve that in this PR.~~ Sufficiently taken care of.

r? estebank or compiler-errors (rust-lang#105332, rust-lang#105674).
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 4, 2024
Rollup merge of rust-lang#121912 - fmease:diag-method-chains-gat, r=compiler-errors,estebank

Properly deal with GATs when looking for method chains to point at

Fixes rust-lang#121898.

~~While it prevents an ICE and the structured suggestion is correct, the method chain diagnostic notes are weird / useless / incorrect judging by a quick look. I guess I should improve that in this PR.~~ Sufficiently taken care of.

r? estebank or compiler-errors (rust-lang#105332, rust-lang#105674).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants