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

Bad diagnostics for GATs in trait paths #81801

Closed
Tracked by #44265
jackh726 opened this issue Feb 5, 2021 · 3 comments · Fixed by #82272
Closed
Tracked by #44265

Bad diagnostics for GATs in trait paths #81801

jackh726 opened this issue Feb 5, 2021 · 3 comments · Fixed by #82272
Labels
A-associated-items Area: Associated items such as associated types and consts. A-diagnostics Area: Messages for errors, warnings, and lints 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

@jackh726
Copy link
Member

jackh726 commented Feb 5, 2021

The diagnostics introduced by #77524 are wrong in some cases, e.g. in gat-trait-path-missing-lifetime we get the following stderr:

error[E0107]: missing generics for associated type `X::Y`
 --> src/test/ui/generic-associated-types/gat-trait-path-missing-lifetime.rs:5:8
  |
5 |   type Y<'a>;
  |        ^ expected 1 lifetime argument
  |
note: associated type defined here, with 1 lifetime parameter: `'a`
 --> src/test/ui/generic-associated-types/gat-trait-path-missing-lifetime.rs:5:8
  |
5 |   type Y<'a>;
  |        ^ --
help: use angle brackets to add missing lifetime argument
  |
5 |   type Y<'a><'a>;
  |         ^^^^

error: aborting due to previous error; 1 warning emitted

Originally posted by @b-naber in #79554 (comment)

@jackh726 jackh726 added A-diagnostics Area: Messages for errors, warnings, and lints F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs requires-nightly This issue requires a nightly compiler in some way. labels Feb 5, 2021
@Alexendoo Alexendoo added D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 6, 2021
@henryboisdequin
Copy link
Contributor

The fix to this would be pointing to fn foo<'a, T1: X<Y = T1>>(t : T1) -> T1::Y<'a> and emmiting the error there right?

@b-naber
Copy link
Contributor

b-naber commented Feb 11, 2021

The fix to this would be pointing to fn foo<'a, T1: X<Y = T1>>(t : T1) -> T1::Y<'a> and emmiting the error there right?

Yes.

@estebank
Copy link
Contributor

Another case:

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-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. A-associated-items Area: Associated items such as associated types and consts. labels Feb 14, 2021
@bors bors closed this as completed in ba8d7e2 May 11, 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 such as associated types and consts. A-diagnostics Area: Messages for errors, warnings, and lints 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

Successfully merging a pull request may close this issue.

5 participants