-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Open
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-lazy-normalizationArea: Lazy normalization (tracking issue: #60471)Area: Lazy normalization (tracking issue: #60471)A-type-systemArea: Type systemArea: Type systemC-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
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
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-lazy-normalizationArea: Lazy normalization (tracking issue: #60471)Area: Lazy normalization (tracking issue: #60471)A-type-systemArea: Type systemArea: Type systemC-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
jonas-schievink commentedon Jan 5, 2020
I think this is just #43408?
Since
#![feature(const_generics)]
does make generics available in that context, enabling it results in the correct error:mcy commentedon Feb 6, 2020
This seems to be different, because I ran into the same diagnostic with code that, as far as I can tell, is actually correct:
(i.e., the compiler suggests constraining
Self: T
).When I turn on const generics, I get
which I assume is just some array-specific failsafe, since this all works fine when I use
pub struct Ignore<const N: usize>;
instead.