Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Incorrect span for suggestion to add type paramater to associated type #82084

Closed
estebank opened this issue Feb 14, 2021 · 1 comment
Closed
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) A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

Given:

#![feature(generic_associated_types)]

// The cyclic dependency between trait A and B compiles as expected
trait A {
    type BType: B<AType = Self>;
}

trait B {
    type AType: A<BType = Self>;
}

// rustc crashes on the generic cyclic dependency between traits C and D
trait C {
    type DType<T>: D<T, CType = Self>;
}
trait D<T> {
    type CType: C<DType = Self>;
}

we currently emit

error[E0107]: missing generics for associated type `C::DType`
  --> src/lib.rs:14:10
   |
14 |     type DType<T>: D<T, CType = Self>;
   |          ^^^^^ expected 1 type argument
   |
note: associated type defined here, with 1 type parameter: `T`
  --> src/lib.rs:14:10
   |
14 |     type DType<T>: D<T, CType = Self>;
   |          ^^^^^ -
help: use angle brackets to add missing type argument
   |
14 |     type DType<T><T>: D<T, CType = Self>;
   |               ^^^

where the correct suggestion would be


error[E0107]: missing generics for associated type `C::DType`
  --> src/lib.rs:14:10
   |
17 |     type CType: C<DType = Self>;
   |                   ^^^^^ expected 1 type argument
   |
note: associated type defined here, with 1 type parameter: `T`
  --> src/lib.rs:14:10
   |
14 |     type DType<T>: D<T, CType = Self>;
   |          ^^^^^ -
help: use angle brackets to add missing type argument
   |
17 |     type CType: C<DType<T> = Self>;
   |                        ^^^

CC #81712

@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints A-associated-items Area: Associated items (types, constants & functions) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` requires-nightly This issue requires a nightly compiler in some way. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. labels Feb 14, 2021
@estebank
Copy link
Contributor Author

Duplicate of #81801

@estebank estebank marked this as a duplicate of #81801 Feb 14, 2021
@fmease fmease added the A-GATs Area: Generic associated types (GATs) label Nov 2, 2024
# for free to join this conversation on GitHub. Already have an account? # 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) A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs requires-nightly This issue requires a nightly compiler in some way. 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

2 participants