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 diagnostics for missing associated types #60595

Closed
alexreg opened this issue May 7, 2019 · 3 comments · Fixed by #67268
Closed

Improve diagnostics for missing associated types #60595

alexreg opened this issue May 7, 2019 · 3 comments · Fixed by #67268
Labels
A-associated-items Area: Associated items (types, constants & functions) A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@alexreg
Copy link
Contributor

alexreg commented May 7, 2019

When the user fails to specify associated types for a trait object, the span used for the label associated type `Output` must be specified is the entire trait object, when it should ideally just be the trait (bound) from which the associated type is missing.

For example, we currently get:

3 | type Foo = Add + Sub;
  |            ^^^^^^^^^ associated type `Output` must be specified

when we really want something like:

3 | type Foo = Add + Sub;
  |            |     ^^^ associated type `Output` must be specified
  |            ^^^^      associated type `Output` must be specified

Note that PR #59445 will ensure that there at least are two labels in the above example, which is more correct, although the spans of both labels will still be the entire trait object.

See also #59445 (comment).

CC @estebank @eddyb @Centril

@estebank estebank added A-associated-items Area: Associated items (types, constants & functions) A-diagnostics Area: Messages for errors, warnings, and lints labels May 7, 2019
@jonas-schievink jonas-schievink added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 7, 2019
@eddyb
Copy link
Member

eddyb commented May 7, 2019

cc @varkor

@estebank
Copy link
Contributor

Current output:

error[E0191]: the value of the associated types `Output` (from the trait `std::ops::Add`), `Output` (from the trait `std::ops::Sub`) must be specified
 --> src/lib.rs:1:12
  |
1 | type Foo = std::ops::Add + std::ops::Sub;
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |            |
  |            associated type `Output` must be specified
  |            associated type `Output` must be specified

It mentions all of the types that need the associated type set, but the span is still the same.

@estebank estebank added the D-papercut Diagnostics: An error or lint that needs small tweaks. label Oct 8, 2019
@estebank
Copy link
Contributor

#67268 touches this part of the codebase. It doesn't address it, but it should be possible to build on it to do so. With that PR, the output is

error[E0191]: the value of the associated types `Output` (from trait `std::ops::Add`), `Output` (from trait `std::ops::Sub`) must be specified
 --> file12.rs:1:12
  |
1 | type Foo = std::ops::Add + std::ops::Sub;
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated types `Output`, `Output` must be specified

Centril added a commit to Centril/rust that referenced this issue Dec 20, 2019
Tweak errors for missing associated types and type parameters

* On `dyn Trait` missing associated types, provide a structured suggestion for them
* On missing type parameters, provide structured suggestion for them
* Point at trait definition when missing required type parameter
* Tweak output of E0658
* Tweak wording of E0719
* Account for `Trait1 + Trait2` case

Fix rust-lang#66380, fix rust-lang#60595. CC rust-lang#63711.
@bors bors closed this as completed in c0b16b4 Dec 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants