-
-
Notifications
You must be signed in to change notification settings - Fork 17.4k
index out of bound in slice not caught at compilation #38035
Copy link
Copy link
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-mir-optArea: MIR optimizationsArea: MIR optimizationsC-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.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.
Description
Activity
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-mir-optArea: MIR optimizationsArea: MIR optimizationsC-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.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.
Hi! I'm just learning Rust! I saw this odd behavior, where the compiler will nicely tell me that an index in an array is impossible at compile time, but won't tell me that an index in a slice of known size is also impossible.
I thought I'd share.
This fails at compile time:
This fails at runtime:
Would be cool if
&y[0..1][1]also failed at compile time.