Skip to content

Bad generic error for incorrectly placed where clause for tuple struct #100790

Description

@CAD97

Given the following code: [playground]

struct Example
where
    (): Sized,
(usize);

The current output is:

error: expected one of `:`, `==`, or `=`, found `;`
 --> src/lib.rs:4:8
  |
4 | (usize);
  |        ^ expected one of `:`, `==`, or `=`

What appears to be happening is that we're trying to parse this as a unit struct (which can have a where clause), and thus trying to parse the struct tuple as a type to bound.

With a tuple visibility:

struct Example
where
    (): Sized,
(pub usize, usize);
error: expected type, found keyword `pub`
 --> src/lib.rs:4:2
  |
4 | (pub usize, usize);
  |  ^^^ expected type

Ideally,

  • In the former case (easier?) we can notice that we parsed a tuple type and then got ; instead of : (or a currently-just-for-diagnostics =) and then reinterpret the tuple type as a tuple struct tuple, printing a more useful error;
  • In the latter case (harder?) we would likely need to backtrack when seeing a pub visibility marker and retry to parse as a tuple struct definition tuple in order to provide the nicer error.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions