Open
Description
When you have:
trait Tr {
const C: usize = 0;
fn fun(x: [u8; Self::C]) -> [u8; 0] { x }
}
you get the usual problem:
error[E0599]: no associated item named `C` found for type `Self` in the current scope
--> src/lib.rs:3:26
|
3 | fn fun(x: [u8; Self::C]) -> [u8; 0] { x }
| ^ associated item not found in `Self`
|
= help: items from traits can only be used if the trait is implemented and in scope
= note: the following trait defines an item `C`, perhaps you need to implement it:
candidate #1: `Tr`
That this errors is right. However, it fails for the wrong reason.
What should happen here is that Self::C
is seen as an opaque constant the value of which you don't get to assume in fun
's body. Therefore you should get a type error:
error[E0308]: mismatched types
--> src/lib.rs:L:C
|
L | fn fun(x: [u8; Self::C]) -> [u8; 0] { x }
| ^ expected [u8; 0], found [u8; Self::C]
|
= note: expected type `[u8; 0]`
found type `[u8; Self::C]`
Metadata
Metadata
Assignees
Labels
Area: Associated items (types, constants & functions)Area: Lazy normalization (tracking issue: #60471)Area: Type systemCategory: This is a bug.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.Relevant to the compiler team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.