Skip to content

Slice notation with negative indices #18662

@lovasoa

Description

@lovasoa
fn main() {
    let a = "haha";
    println!("Nope. {}", a[1..-1]);
}

Compilation succeeds without any warning.
-1 is silently converted to an unsigned int, and I get an executable that panics with index 1 and/or 18446744073709551615 inhahado not lie on character boundary

I think there should be a compilation warning or error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions