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

Improve "associated type not found" diagnostics #115662

Merged
merged 2 commits into from Sep 9, 2023

Conversation

ShE3py
Copy link
Contributor

@ShE3py ShE3py commented Sep 8, 2023

use core::ops::Deref;

fn foo<T>() where T: Deref<Output = u32> {}

Before:

error[E0220]: associated type `Output` not found for `Deref`
 --> E0220.rs:5:28
  |
5 | fn foo<T>() where T: Deref<Output = u32> {}
  |                            ^^^^^^ associated type `Output` not found

After:

error[E0220]: associated type `Output` not found for `Deref`
 --> E0220.rs:5:28
  |
5 | fn foo<T>() where T: Deref<Output = u32> {}
  |                            ^^^^^^ help: `Deref` has the following associated type: `Target`

@rustbot label +A-diagnostics +D-papercut

@rustbot
Copy link
Collaborator

rustbot commented Sep 8, 2023

r? @compiler-errors

(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. A-diagnostics Area: Messages for errors, warnings, and lints D-papercut Diagnostics: An error or lint that needs small tweaks. labels Sep 8, 2023
@ShE3py ShE3py changed the title Improve "associated type not defined" diagnostics Improve "associated type not found" diagnostics Sep 8, 2023
| ^^^^ associated type `Item` not found
| ^^^^
|
= help: `M` has no associated type, try removing `Item`
Copy link
Member

Choose a reason for hiding this comment

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

This suggestion doesn't make sense imo.

tests/ui/associated-types/associated-types-path-1.stderr Outdated Show resolved Hide resolved
tests/ui/associated-consts/assoc-const-eq-missing.stderr Outdated Show resolved Hide resolved
return err.emit();
}

let msg = if all_candidate_names.len() > 1 {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should suggest anything if there's >1 candidate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

trait Qux {
    type A;
    type B;
}

fn quux<T>() where T: Qux<A = u32, ZZ = u32> {}

gives

error[E0220]: associated type `ZZ` not found for `Qux`
  --> E0220.rs:14:36
   |
14 | fn quux<T>() where T: Qux<A = u32, ZZ = u32> {}
   |                                    ^^
   |
help: `Qux` has the following associated types
   |
14 | fn quux<T>() where T: Qux<A = u32, A = u32> {}
   |                                    ~
14 | fn quux<T>() where T: Qux<A = u32, B = u32> {}
   |                                    ~

I think this is still helpful?

compiler/rustc_hir_analysis/src/astconv/errors.rs Outdated Show resolved Hide resolved
@rust-log-analyzer

This comment has been minimized.

@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Sep 8, 2023

📌 Commit a0e0a32 has been approved by compiler-errors

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 Sep 8, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 8, 2023
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#113807 (Tests crash from inappropriate use of common linkage)
 - rust-lang#115358 (debuginfo: add compiler option to allow compressed debuginfo sections)
 - rust-lang#115630 (Dont suggest use between `use` and cfg attr)
 - rust-lang#115662 (Improve "associated type not found" diagnostics)
 - rust-lang#115673 (Fix sanitize/cfg.rs test)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 69044a1 into rust-lang:master Sep 9, 2023
11 checks passed
@bors
Copy link
Contributor

bors commented Sep 9, 2023

⌛ Testing commit a0e0a32 with merge b0b8c52...

@rustbot rustbot added this to the 1.74.0 milestone Sep 9, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Sep 9, 2023
Rollup merge of rust-lang#115662 - ShE3py:E0220-note, r=compiler-errors

Improve "associated type not found" diagnostics

```rs
use core::ops::Deref;

fn foo<T>() where T: Deref<Output = u32> {}
```

Before:
```
error[E0220]: associated type `Output` not found for `Deref`
 --> E0220.rs:5:28
  |
5 | fn foo<T>() where T: Deref<Output = u32> {}
  |                            ^^^^^^ associated type `Output` not found
```

After:
```
error[E0220]: associated type `Output` not found for `Deref`
 --> E0220.rs:5:28
  |
5 | fn foo<T>() where T: Deref<Output = u32> {}
  |                            ^^^^^^ help: `Deref` has the following associated type: `Target`
```

---

`@rustbot` label +A-diagnostics +D-papercut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-papercut Diagnostics: An error or lint that needs small tweaks. 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.

None yet

5 participants