Skip to content

Associated constants in trait impls are not required to have a type #8732

@asterite

Description

@asterite

This code in Rust gives an error:

trait Serialize {
    const N: usize;
}

impl Serialize for u32 {
    const N = 1;
}

fn main() {}

The error:

error: missing type for `const` item
 --> src/main.rs:6:12
  |
6 |     const N = 1;
  |            ^ help: provide a type for the associated constant: `: usize`

I think for consistency with Rust we should also require a type for every associated constant.

In particular, for implementing #8548 we need to know the type of an associated constant before resolving its value or checking the associated constant on the related trait. Or, put another way, it simplifies some of the compiler logic.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions