Skip to content

Gracefully handle python-esque sequence slicing #108215

Closed
@hkmatsumoto

Description

@hkmatsumoto

Code

fn main() {
    let a = &[1, 2, 3][1:2];
}

Current output

Compiling playground v0.0.1 (/playground)
error: expected type, found `2`
 --> src/main.rs:2:26
  |
2 |     let a = &[1, 2, 3][1:2];
  |                         -^ expected type
  |                         |
  |                         tried to parse a type due to this type ascription
  |
  = note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `<expr>: <type>`
  = note: see issue #23416 <https://github.com/rust-lang/rust/issues/23416> for more information

error: could not compile `playground` due to previous error

Desired output

help: did you mean [1..2]?

Rationale and extra context

Having written Python for several hours, I made this mistake and couldn't realize what was wrong for a while.

Other cases

No response

Anything else?

@rustbot claim

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions