-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-coercionsArea: implicit and explicit `expr as Type` coercionsArea: implicit and explicit `expr as Type` coercionsA-inferenceArea: Type inferenceArea: Type inferenceC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.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 trying to index an array with another type that is not usize that can be converted to it using as _
inference fails.
Example code:
fn main() {
let array = [0, 1, 1, 2, 3, 5];
let index: u32 = 1;
array[index as _];
}
Error:
error[E0282]: type annotations needed
--> src/main.rs:4:20
|
4 | array[index as _];
| ^ cannot infer type
Metadata
Metadata
Assignees
Labels
A-coercionsArea: implicit and explicit `expr as Type` coercionsArea: implicit and explicit `expr as Type` coercionsA-inferenceArea: Type inferenceArea: Type inferenceC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.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.