Skip to content

Unnecessary direct unwraps on Option and Result are not warned/fixed #10352

@pksunkara

Description

@pksunkara

Summary

When we have direct unwraps on an Option or Result like the following:

let val = Some(1).unwrap();
let val = Some(1).expect(...);
let val = Ok(1).unwrap();
let val = Err(1).unwrap_err();
let val = Ok(1).expect(...);

The lint remove the unnecessary unwrap/expect and unnecessary wraps from the above lines.

let val = 1;
let val = 1;
let val = 1;
let val = 1;
let val = 1;

Lint Name

unnecessary_unwrap

Reproducer

I tried this code:

let val = Some(1).unwrap();

I expected to see this happen:

let val = 1;

Instead, this happened:

Nothing changed.

Version

No response

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions