Skip to content

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

Closed
@DutchGhost

Description

@DutchGhost

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.

Metadata

Metadata

Assignees

Labels

A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`A-trait-systemArea: Trait systemC-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-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