Skip to content

// PANIC comment on panic-able calls #15861

@blyxyas

Description

@blyxyas

What it does

Reports on functions marked as panic-able (for example, .expect()) in the config file or with a special #[clippy::may_panic].

Advantage

  • Ensures that specially critical code is handled with the requirement that it won't panic
  • Allows for more flexibility than unwrap_used or disallowed_methods

Drawbacks

No response

Example

#[clippy::may_panic]
fn dangerous(v: Vec<usize>) -> usize {
    v[1]
}

fn foo()  {
    let v = vec![];
    let _ = dangerous(v);
}

Comparison with existing lints

Unlike unwrap_used, this allows for any function marked such as that.
Compared disallowed_methods, this allows for any function call and gives a specific reason.
Unlike indexing_slicing, this works for any function marked as clippy::may_panic
Unlike unreachable/unimplemented, this works for any functions marked with the attribute.

Additional Context

This was requested by the Rust-for-Linux project, giving it priority. I will mentor anyone trying to implement it.

Metadata

Metadata

Assignees

Labels

A-lintArea: New lintsG-Rust-for-LinuxIssues related to Rust-for-Linux wants and bugfixes

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions