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

GAT's + const generics error yields Invalid suggestion #81175

Closed
DutchGhost opened this issue Jan 18, 2021 · 2 comments · Fixed by #81195
Closed

GAT's + const generics error yields Invalid suggestion #81175

DutchGhost opened this issue Jan 18, 2021 · 2 comments · Fixed by #81195
Assignees
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. A-traits Area: Trait system C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@DutchGhost
Copy link
Contributor

DutchGhost commented Jan 18, 2021

The following code errors, and the error contains a suggestion how to fix the error:

#![feature(generic_associated_types)]
#![feature(const_generics)]
#![feature(const_evaluatable_checked)]

trait Funk<const P: usize> {
    type Item<const N: usize>: Funk<{core::mem::size_of::<Self>()}>;
}

The error message states:

error[E0277]: the size for values of type `Self` cannot be known at compilation time
   --> src/lib.rs:6:59
    |
6   |     type Item<const N: usize>: Funk<{core::mem::size_of::<Self>()}>;
    |                                                           ^^^^ doesn't have a size known at compile-time
    |
help: consider further restricting `Self`
    |
5   | trait Funk: Sized<const P: usize> {
    |           ^^^^^^^

error: aborting due to previous error; 3 warnings emitted

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground`

Obviously, writing trait Funk: Sized<const P: usize> { is invalid syntax.

@camelid camelid added A-const-generics Area: const generics (parameters and arguments) A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. F-const_generics `#![feature(const_generics)]` requires-nightly This issue requires a nightly compiler in some way. F-generic_const_exprs `#![feature(generic_const_exprs)]` F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs C-bug Category: This is a bug. labels Jan 18, 2021
@camelid
Copy link
Member

camelid commented Jan 18, 2021

It seems the issue is that it's inserting the suggestion after the trait name and before the generics, rather than after the generics.

@SNCPlay42
Copy link
Contributor

No-nightly-features code that exhibits the same problem:

trait Foo<T> {
    const SIZE: usize = core::mem::size_of::<Self>();
}
error[E0277]: the size for values of type `Self` cannot be known at compilation time
   --> src/lib.rs:2:46
    |
2   |     const SIZE: usize = core::mem::size_of::<Self>();
    |                                              ^^^^ doesn't have a size known at compile-time
    |
help: consider further restricting `Self`
    |
1   | trait Foo: Sized<T> {
    |          ^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground`

@rustbot label -requires-nightly

(should the F-labels go as well?)

@rustbot rustbot removed the requires-nightly This issue requires a nightly compiler in some way. label Jan 18, 2021
@camelid camelid added A-traits Area: Trait system and removed A-const-generics Area: const generics (parameters and arguments) F-generic_const_exprs `#![feature(generic_const_exprs)]` F-const_generics `#![feature(const_generics)]` F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs labels Jan 18, 2021
@estebank estebank added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jan 19, 2021
@estebank estebank self-assigned this Jan 19, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this issue Jan 26, 2021
…h-params, r=oli-obk

Account for generics when suggesting bound

Fix rust-lang#81175.
JohnTitor added a commit to JohnTitor/rust that referenced this issue Jan 26, 2021
…h-params, r=oli-obk

Account for generics when suggesting bound

Fix rust-lang#81175.
@bors bors closed this as completed in 088c89d Jan 26, 2021
zaharidichev pushed a commit to zaharidichev/rust that referenced this issue Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. A-traits Area: Trait system C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. 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