Skip to content

Warn on indexing in general? #2536

Closed
Closed
@shnewto

Description

@shnewto

👋
I'm interested in contributing a lint I've put together but would love some feedback before starting the PR process. The general idea is that I'd like to dissuade behavior that could cause a runtime panic in my project, in this case, indexing.

Some preliminary work behaves something like the following:

fn main() {
    // Vector containing a single element.
    let x = vec![0;1];
    let _a = x[10];
    //~^ WARNING indexing can result in runtime panics
    let _b = &x[10..]; 
    //~^ WARNING ranged indexing with start/end values can result in runtime panics
    let _c = &x[..10]; 
    //~^ WARNING ranged indexing with start/end values can result in runtime panics
    let _d = &x[10..100]; 
    //~^ WARNING ranged indexing with start/end values can result in runtime panics
    let _e = &x[..]; // OK
}

I guess to start, I'm interested in whether this lint seems like could fit in here. If it does we can go from there, thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions