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

Incorrect span for GAT equality bound with missing type parameter in where clause #84009

Closed
PatchMixolydic opened this issue Apr 8, 2021 · 2 comments
Labels
A-associated-items Area: Associated items (types, constants & functions) A-diagnostics Area: Messages for errors, warnings, and lints A-GATs Area: Generic associated types (GATs) F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@PatchMixolydic
Copy link
Contributor

Given the following code (taken from #79636 (comment), playground):

#![allow(incomplete_features)]
#![feature(generic_associated_types)]

pub trait SomeTrait {
    type Wrapped<A>: SomeTrait;

    fn f() -> ();
}

fn program<W>() -> ()
where
    // Missing type parameter for `Wrapped`
    W: SomeTrait<Wrapped = W>,
{
    return W::f();
}

fn main() {}

The current output is:

error[E0107]: missing generics for associated type `SomeTrait::Wrapped`
 --> src/main.rs:5:10
  |
5 |     type Wrapped<A>: SomeTrait;
  |          ^^^^^^^ expected 1 type argument
  |
note: associated type defined here, with 1 type parameter: `A`
 --> src/main.rs:5:10
  |
5 |     type Wrapped<A>: SomeTrait;
  |          ^^^^^^^ -
help: use angle brackets to add missing type argument
  |
5 |     type Wrapped<A><A>: SomeTrait;
  |                 ^^^

Note that the suggestion is syntactically invalid:

pub trait SomeTrait {
    type Wrapped<A><A>: SomeTrait;

    fn f() -> ();
}
error: expected one of `:`, `;`, `=`, or `where`, found `<`
 --> src/main.rs:5:20
  |
4 | pub trait SomeTrait {
  |                     - while parsing this item list starting here
5 |     type Wrapped<A><A>: SomeTrait;
  |                    ^ expected one of `:`, `;`, `=`, or `where`
...
8 | }
  | - the item list ends here

The problem is that the span is pointing at the associated type, not the where clause bound.

Ideally the output should look like:

error[E0107]: missing generics for associated type `SomeTrait::Wrapped`
  --> src/main.rs:12:18
   |
12 |     W: SomeTrait<Wrapped = W>,
   |                  ^^^^^^^ expected 1 type argument
   |
note: associated type defined here, with 1 type parameter: `A`
 --> src/main.rs:5:10
  |
5 |     type Wrapped<A>: SomeTrait;
  |          ^^^^^^^ -
help: use angle brackets to add missing type argument
   |
12 |     W: SomeTrait<Wrapped<A> = W>,
   |                         ^^^
@PatchMixolydic PatchMixolydic added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 8, 2021
@PatchMixolydic
Copy link
Contributor Author

@rustbot modify labels: +A-associated-items +F-generic_associated_types

@rustbot rustbot added A-associated-items Area: Associated items (types, constants & functions) F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs labels Apr 8, 2021
@PatchMixolydic
Copy link
Contributor Author

Duplicate of #81801 😅

@fmease fmease added the A-GATs Area: Generic associated types (GATs) label Nov 2, 2024
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-GATs Area: Generic associated types (GATs) F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants