-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-arrayArea: `[T; N]`Area: `[T; N]`A-type-systemArea: Type systemArea: Type systemC-bugCategory: This is a bug.Category: This is a bug.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
use std::ops::Index;
enum Foo {
Zero,
One,
Two,
}
impl Index<Foo> for [u8; 3] {
type Output = u8;
fn index(&self, index: Foo) -> &u8 {
unsafe { self.get_unchecked(index as usize) }
}
}
fn main() {
let arr: [u8; 3] = [0, 1, 2];
// OK:
let _ = arr[Foo::Two];
// Error:
let _ = arr[2usize];
// ^^^^^^ expected enum `Foo`, found `usize`
// Error:
let _ = &arr[0usize..2];
// ^^^^^^^^^ expected enum `Foo`, found struct `std::ops::Range<usize>`
// Error:
let _ = &arr[..];
// ^^ expected enum `Foo`, found struct `std::ops::RangeFull`
}
Metadata
Metadata
Assignees
Labels
A-arrayArea: `[T; N]`Area: `[T; N]`A-type-systemArea: Type systemArea: Type systemC-bugCategory: This is a bug.Category: This is a bug.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.