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

Misleading error message on associated type bounds #87493

Closed
sffc opened this issue Jul 26, 2021 · 1 comment · Fixed by #87566
Closed

Misleading error message on associated type bounds #87493

sffc opened this issue Jul 26, 2021 · 1 comment · Fixed by #87566
Labels
A-associated-items Area: Associated items (types, constants & functions) A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST C-bug Category: This is a bug. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. 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

@sffc
Copy link

sffc commented Jul 26, 2021

I tried this code:

trait MyTrait {
    type Assoc;
}

#[allow(dead_code)]
fn foo<S, T>(_s: S, _t: T)
where
    S: MyTrait, T: MyTrait<Assoc == S::Assoc>
{}

Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=adddc330eab816444616202cc576f88e

I expected to see this happen: The error message should indicate that the == should be a single =.

Instead, this happened: The error message gives no hint of the correct syntax. It gives two errors, neither of which are helpful:

error: expected one of `,` or `>`, found `==`
 --> src/lib.rs:8:34
  |
8 |     S: MyTrait, T: MyTrait<Assoc == S::Assoc>
  |                                  ^^ expected one of `,` or `>`
  |
help: expressions must be enclosed in braces to be used as const generic arguments
  |
8 |     S: MyTrait, T: MyTrait<{ Assoc == S::Assoc }>
  |                            ^                   ^

This error is unhelpful because it says "expected one of , or >", but = is also allowed. Also, the suggestion to use curly braces is a red herring.

error[E0107]: this trait takes 0 const arguments but 1 const argument was supplied
 --> src/lib.rs:8:20
  |
8 |     S: MyTrait, T: MyTrait<Assoc == S::Assoc>
  |                    ^^^^^^^------------------- help: remove these generics
  |                    |
  |                    expected 0 const arguments
  |
note: trait defined here, with 0 const parameters
 --> src/lib.rs:1:7
  |
1 | trait MyTrait {
  |       ^^^^^^^

This error is unhelpful because I am not specifying const arguments; I'm specifying associated types.

Meta

Rust version according to play.rust-lang.org: 1.53.0

@sffc sffc added the C-bug Category: This is a bug. label Jul 26, 2021
@Manishearth Manishearth added the A-diagnostics Area: Messages for errors, warnings, and lints label Jul 26, 2021
@Manishearth
Copy link
Member

cc @estebank

@estebank estebank added A-parser Area: The parsing of Rust source code to an AST D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. 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. A-associated-items Area: Associated items (types, constants & functions) F-associated_type_bounds `#![feature(associated_type_bounds)]` and removed F-associated_type_bounds `#![feature(associated_type_bounds)]` labels Jul 27, 2021
@bors bors closed this as completed in 1b78967 Sep 17, 2021
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 A-parser Area: The parsing of Rust source code to an AST C-bug Category: This is a bug. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. 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.

3 participants