Preserve type annotations when present

This commit is contained in:
Pavan Kumar Sunkara 2023-05-31 20:09:12 +01:00
parent 6cf138e9b6
commit 6e4c5561be
7 changed files with 935 additions and 227 deletions

View file

@ -276,52 +276,28 @@ declare_clippy_lint! {
declare_clippy_lint! {
/// ### What it does
/// Checks for `.unwrap()` or `.unwrap_err()` calls on `Result`s and `.unwrap()` call on `Option`s.
/// Checks for `.unwrap()` related calls on `Result`s and `Option`s that are constructed.
///
/// ### Why is this bad?
/// It is better to handle the `None` or `Err` case,
/// or at least call `.expect(_)` with a more helpful message. Still, for a lot of
/// quick-and-dirty code, `unwrap` is a good choice, which is why this lint is
/// `Allow` by default.
///
/// `result.unwrap()` will let the thread panic on `Err` values.
/// Normally, you want to implement more sophisticated error handling,
/// and propagate errors upwards with `?` operator.
///
/// Even if you want to panic on errors, not all `Error`s implement good
/// messages on display. Therefore, it may be beneficial to look at the places
/// where they may get displayed. Activate this lint to do just that.
/// It is better to write the value directly without the indirection.
///
/// ### Examples
/// ```rust
/// # let option = Some(1);
/// # let result: Result<usize, ()> = Ok(1);
/// option.unwrap();
/// result.unwrap();
/// let val1 = Some(1).unwrap();
/// let val2 = Ok::<_, ()>(1).unwrap();
/// let val3 = Err::<(), _>(1).unwrap_err();
/// ```
///
/// Use instead:
/// ```rust
/// # let option = Some(1);
/// # let result: Result<usize, ()> = Ok(1);
/// option.expect("more helpful message");
/// result.expect("more helpful message");
/// ```
///
/// If [expect_used](#expect_used) is enabled, instead:
/// ```rust,ignore
/// # let option = Some(1);
/// # let result: Result<usize, ()> = Ok(1);
/// option?;
///
/// // or
///
/// result?;
/// let val1 = 1;
/// let val2 = 1;
/// let val3 = 1;
/// ```
#[clippy::version = "1.69.0"]
pub UNNECESSARY_LITERAL_UNWRAP,
complexity,
"checks for calls of `unwrap()` or `expect()` on `Some()` that cannot fail"
"using `unwrap()` related calls on `Result` and `Option` constructors"
}
declare_clippy_lint! {

View file

@ -1,10 +1,26 @@
use clippy_utils::{diagnostics::span_lint_and_then, is_res_lang_ctor, path_res};
use clippy_utils::{diagnostics::span_lint_and_then, is_res_lang_ctor, last_path_segment, path_res, MaybePath};
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_lint::LateContext;
use super::UNNECESSARY_LITERAL_UNWRAP;
fn get_ty_from_args<'a>(args: Option<&'a [hir::GenericArg<'a>]>, index: usize) -> Option<&'a hir::Ty<'a>> {
let args = args?;
if args.len() <= index {
return None;
}
match args[index] {
hir::GenericArg::Type(ty) => match ty.kind {
hir::TyKind::Infer => None,
_ => Some(ty),
},
_ => None,
}
}
pub(super) fn check(
cx: &LateContext<'_>,
expr: &hir::Expr<'_>,
@ -14,19 +30,24 @@ pub(super) fn check(
) {
let init = clippy_utils::expr_or_init(cx, recv);
let (constructor, call_args) = if let hir::ExprKind::Call(call, call_args) = init.kind {
if is_res_lang_ctor(cx, path_res(cx, call), hir::LangItem::OptionSome) {
("Some", call_args)
} else if is_res_lang_ctor(cx, path_res(cx, call), hir::LangItem::ResultOk) {
("Ok", call_args)
} else if is_res_lang_ctor(cx, path_res(cx, call), hir::LangItem::ResultErr) {
("Err", call_args)
let (constructor, call_args, ty) = if let hir::ExprKind::Call(call, call_args) = init.kind {
let Some(qpath) = call.qpath_opt() else { return };
let args = last_path_segment(qpath).args.map(|args| args.args);
let res = cx.qpath_res(qpath, call.hir_id());
if is_res_lang_ctor(cx, res, hir::LangItem::OptionSome) {
("Some", call_args, get_ty_from_args(args, 0))
} else if is_res_lang_ctor(cx, res, hir::LangItem::ResultOk) {
("Ok", call_args, get_ty_from_args(args, 0))
} else if is_res_lang_ctor(cx, res, hir::LangItem::ResultErr) {
("Err", call_args, get_ty_from_args(args, 1))
} else {
return;
}
} else if is_res_lang_ctor(cx, path_res(cx, init), hir::LangItem::OptionNone) {
let call_args: &[hir::Expr<'_>] = &[];
("None", call_args)
("None", call_args, None)
} else {
return;
};
@ -34,39 +55,41 @@ pub(super) fn check(
let help_message = format!("used `{method}()` on `{constructor}` value");
let suggestion_message = format!("remove the `{constructor}` and `{method}()`");
if init.span == recv.span {
span_lint_and_then(cx, UNNECESSARY_LITERAL_UNWRAP, expr.span, &help_message, |diag| {
let suggestions = match (constructor, method) {
("None", "unwrap") => vec![(expr.span, "panic!()".to_string())],
("None", "expect") => vec![
(expr.span.with_hi(args[0].span.lo()), "panic!(".to_string()),
(expr.span.with_lo(args[0].span.hi()), ")".to_string()),
],
("Ok", "unwrap_err") | ("Err", "unwrap") => vec![
(
recv.span.with_hi(call_args[0].span.lo()),
"panic!(\"{:?}\", ".to_string(),
),
(expr.span.with_lo(call_args[0].span.hi()), ")".to_string()),
],
("Ok", "expect_err") | ("Err", "expect") => vec![
(
recv.span.with_hi(call_args[0].span.lo()),
"panic!(\"{1}: {:?}\", ".to_string(),
),
(call_args[0].span.with_lo(args[0].span.lo()), ", ".to_string()),
],
_ => vec![
(recv.span.with_hi(call_args[0].span.lo()), String::new()),
(expr.span.with_lo(call_args[0].span.hi()), String::new()),
],
};
span_lint_and_then(cx, UNNECESSARY_LITERAL_UNWRAP, expr.span, &help_message, |diag| {
let suggestions = match (constructor, method, ty) {
("None", "unwrap", _) => Some(vec![(expr.span, "panic!()".to_string())]),
("None", "expect", _) => Some(vec![
(expr.span.with_hi(args[0].span.lo()), "panic!(".to_string()),
(expr.span.with_lo(args[0].span.hi()), ")".to_string()),
]),
(_, _, Some(_)) => None,
("Ok", "unwrap_err", None) | ("Err", "unwrap", None) => Some(vec![
(
recv.span.with_hi(call_args[0].span.lo()),
"panic!(\"{:?}\", ".to_string(),
),
(expr.span.with_lo(call_args[0].span.hi()), ")".to_string()),
]),
("Ok", "expect_err", None) | ("Err", "expect", None) => Some(vec![
(
recv.span.with_hi(call_args[0].span.lo()),
"panic!(\"{1}: {:?}\", ".to_string(),
),
(call_args[0].span.with_lo(args[0].span.lo()), ", ".to_string()),
]),
(_, _, None) => Some(vec![
(recv.span.with_hi(call_args[0].span.lo()), String::new()),
(expr.span.with_lo(call_args[0].span.hi()), String::new()),
]),
};
diag.multipart_suggestion(suggestion_message, suggestions, Applicability::MachineApplicable);
});
} else {
span_lint_and_then(cx, UNNECESSARY_LITERAL_UNWRAP, expr.span, &help_message, |diag| {
diag.span_help(init.span, suggestion_message);
});
}
match (init.span == recv.span, suggestions) {
(true, Some(suggestions)) => {
diag.multipart_suggestion(suggestion_message, suggestions, Applicability::MachineApplicable);
},
_ => {
diag.span_help(init.span, suggestion_message);
},
}
});
}

View file

@ -1,14 +1,25 @@
//@run-rustfix
#![warn(clippy::unnecessary_literal_unwrap)]
#![allow(unreachable_code)]
#![allow(clippy::unnecessary_lazy_evaluations)]
#![allow(
clippy::unnecessary_lazy_evaluations,
clippy::diverging_sub_expression,
clippy::let_unit_value,
clippy::no_effect
)]
fn unwrap_option_some() {
let _val = 1;
let _val = 1;
1;
1;
}
fn unwrap_option_none() {
let _val = panic!();
let _val = panic!("this always happens");
panic!();
panic!("this always happens");
}
@ -16,6 +27,11 @@ fn unwrap_option_none() {
fn unwrap_result_ok() {
let _val = 1;
let _val = 1;
let _val = panic!("{:?}", 1);
let _val = panic!("{1}: {:?}", 1, "this always happens");
1;
1;
panic!("{:?}", 1);
panic!("{1}: {:?}", 1, "this always happens");
}
@ -23,6 +39,11 @@ fn unwrap_result_ok() {
fn unwrap_result_err() {
let _val = 1;
let _val = 1;
let _val = panic!("{:?}", 1);
let _val = panic!("{1}: {:?}", 1, "this always happens");
1;
1;
panic!("{:?}", 1);
panic!("{1}: {:?}", 1, "this always happens");
}
@ -31,12 +52,20 @@ fn unwrap_methods_option() {
let _val = 1;
let _val = 1;
let _val = 1;
1;
1;
1;
}
fn unwrap_methods_result() {
let _val = 1;
let _val = 1;
let _val = 1;
1;
1;
1;
}
fn main() {

View file

@ -1,42 +1,71 @@
//@run-rustfix
#![warn(clippy::unnecessary_literal_unwrap)]
#![allow(unreachable_code)]
#![allow(clippy::unnecessary_lazy_evaluations)]
#![allow(
clippy::unnecessary_lazy_evaluations,
clippy::diverging_sub_expression,
clippy::let_unit_value,
clippy::no_effect
)]
fn unwrap_option_some() {
let _val = Some(1).unwrap();
let _val = Some(1).expect("this never happens");
Some(1).unwrap();
Some(1).expect("this never happens");
}
fn unwrap_option_none() {
None::<usize>.unwrap();
None::<usize>.expect("this always happens");
let _val = None::<()>.unwrap();
let _val = None::<()>.expect("this always happens");
None::<()>.unwrap();
None::<()>.expect("this always happens");
}
fn unwrap_result_ok() {
let _val = Ok::<usize, ()>(1).unwrap();
let _val = Ok::<usize, ()>(1).expect("this never happens");
Ok::<usize, ()>(1).unwrap_err();
Ok::<usize, ()>(1).expect_err("this always happens");
let _val = Ok::<_, ()>(1).unwrap();
let _val = Ok::<_, ()>(1).expect("this never happens");
let _val = Ok::<_, ()>(1).unwrap_err();
let _val = Ok::<_, ()>(1).expect_err("this always happens");
Ok::<_, ()>(1).unwrap();
Ok::<_, ()>(1).expect("this never happens");
Ok::<_, ()>(1).unwrap_err();
Ok::<_, ()>(1).expect_err("this always happens");
}
fn unwrap_result_err() {
let _val = Err::<(), usize>(1).unwrap_err();
let _val = Err::<(), usize>(1).expect_err("this never happens");
Err::<(), usize>(1).unwrap();
Err::<(), usize>(1).expect("this always happens");
let _val = Err::<(), _>(1).unwrap_err();
let _val = Err::<(), _>(1).expect_err("this never happens");
let _val = Err::<(), _>(1).unwrap();
let _val = Err::<(), _>(1).expect("this always happens");
Err::<(), _>(1).unwrap_err();
Err::<(), _>(1).expect_err("this never happens");
Err::<(), _>(1).unwrap();
Err::<(), _>(1).expect("this always happens");
}
fn unwrap_methods_option() {
let _val = Some(1).unwrap_or(2);
let _val = Some(1).unwrap_or_default();
let _val = Some(1).unwrap_or_else(|| 2);
Some(1).unwrap_or(2);
Some(1).unwrap_or_default();
Some(1).unwrap_or_else(|| 2);
}
fn unwrap_methods_result() {
let _val = Ok::<usize, ()>(1).unwrap_or(2);
let _val = Ok::<usize, ()>(1).unwrap_or_default();
let _val = Ok::<usize, ()>(1).unwrap_or_else(|_| 2);
let _val = Ok::<_, ()>(1).unwrap_or(2);
let _val = Ok::<_, ()>(1).unwrap_or_default();
let _val = Ok::<_, ()>(1).unwrap_or_else(|_| 2);
Ok::<_, ()>(1).unwrap_or(2);
Ok::<_, ()>(1).unwrap_or_default();
Ok::<_, ()>(1).unwrap_or_else(|_| 2);
}
fn main() {

View file

@ -1,5 +1,5 @@
error: used `unwrap()` on `Some` value
--> $DIR/unnecessary_literal_unwrap.rs:7:16
--> $DIR/unnecessary_literal_unwrap.rs:12:16
|
LL | let _val = Some(1).unwrap();
| ^^^^^^^^^^^^^^^^
@ -12,7 +12,7 @@ LL + let _val = 1;
|
error: used `expect()` on `Some` value
--> $DIR/unnecessary_literal_unwrap.rs:8:16
--> $DIR/unnecessary_literal_unwrap.rs:13:16
|
LL | let _val = Some(1).expect("this never happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -23,17 +23,58 @@ LL - let _val = Some(1).expect("this never happens");
LL + let _val = 1;
|
error: used `unwrap()` on `None` value
--> $DIR/unnecessary_literal_unwrap.rs:12:5
error: used `unwrap()` on `Some` value
--> $DIR/unnecessary_literal_unwrap.rs:15:5
|
LL | None::<usize>.unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap()`: `panic!()`
LL | Some(1).unwrap();
| ^^^^^^^^^^^^^^^^
|
help: remove the `Some` and `unwrap()`
|
LL - Some(1).unwrap();
LL + 1;
|
error: used `expect()` on `Some` value
--> $DIR/unnecessary_literal_unwrap.rs:16:5
|
LL | Some(1).expect("this never happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Some` and `expect()`
|
LL - Some(1).expect("this never happens");
LL + 1;
|
error: used `unwrap()` on `None` value
--> $DIR/unnecessary_literal_unwrap.rs:20:16
|
LL | let _val = None::<()>.unwrap();
| ^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap()`: `panic!()`
error: used `expect()` on `None` value
--> $DIR/unnecessary_literal_unwrap.rs:13:5
--> $DIR/unnecessary_literal_unwrap.rs:21:16
|
LL | None::<usize>.expect("this always happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | let _val = None::<()>.expect("this always happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `None` and `expect()`
|
LL | let _val = panic!("this always happens");
| ~~~~~~~ ~
error: used `unwrap()` on `None` value
--> $DIR/unnecessary_literal_unwrap.rs:23:5
|
LL | None::<()>.unwrap();
| ^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap()`: `panic!()`
error: used `expect()` on `None` value
--> $DIR/unnecessary_literal_unwrap.rs:24:5
|
LL | None::<()>.expect("this always happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `None` and `expect()`
|
@ -41,34 +82,80 @@ LL | panic!("this always happens");
| ~~~~~~~ ~
error: used `unwrap()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap.rs:17:16
--> $DIR/unnecessary_literal_unwrap.rs:28:16
|
LL | let _val = Ok::<usize, ()>(1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | let _val = Ok::<_, ()>(1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `unwrap()`
|
LL - let _val = Ok::<usize, ()>(1).unwrap();
LL - let _val = Ok::<_, ()>(1).unwrap();
LL + let _val = 1;
|
error: used `expect()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap.rs:18:16
--> $DIR/unnecessary_literal_unwrap.rs:29:16
|
LL | let _val = Ok::<usize, ()>(1).expect("this never happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | let _val = Ok::<_, ()>(1).expect("this never happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `expect()`
|
LL - let _val = Ok::<usize, ()>(1).expect("this never happens");
LL - let _val = Ok::<_, ()>(1).expect("this never happens");
LL + let _val = 1;
|
error: used `unwrap_err()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap.rs:19:5
--> $DIR/unnecessary_literal_unwrap.rs:30:16
|
LL | Ok::<usize, ()>(1).unwrap_err();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | let _val = Ok::<_, ()>(1).unwrap_err();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `unwrap_err()`
|
LL | let _val = panic!("{:?}", 1);
| ~~~~~~~~~~~~~~ ~
error: used `expect_err()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap.rs:31:16
|
LL | let _val = Ok::<_, ()>(1).expect_err("this always happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `expect_err()`
|
LL | let _val = panic!("{1}: {:?}", 1, "this always happens");
| ~~~~~~~~~~~~~~~~~~~ ~
error: used `unwrap()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap.rs:33:5
|
LL | Ok::<_, ()>(1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `unwrap()`
|
LL - Ok::<_, ()>(1).unwrap();
LL + 1;
|
error: used `expect()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap.rs:34:5
|
LL | Ok::<_, ()>(1).expect("this never happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `expect()`
|
LL - Ok::<_, ()>(1).expect("this never happens");
LL + 1;
|
error: used `unwrap_err()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap.rs:35:5
|
LL | Ok::<_, ()>(1).unwrap_err();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `unwrap_err()`
|
@ -76,10 +163,10 @@ LL | panic!("{:?}", 1);
| ~~~~~~~~~~~~~~ ~
error: used `expect_err()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap.rs:20:5
--> $DIR/unnecessary_literal_unwrap.rs:36:5
|
LL | Ok::<usize, ()>(1).expect_err("this always happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | Ok::<_, ()>(1).expect_err("this always happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `expect_err()`
|
@ -87,45 +174,91 @@ LL | panic!("{1}: {:?}", 1, "this always happens");
| ~~~~~~~~~~~~~~~~~~~ ~
error: used `unwrap_err()` on `Err` value
--> $DIR/unnecessary_literal_unwrap.rs:24:16
--> $DIR/unnecessary_literal_unwrap.rs:40:16
|
LL | let _val = Err::<(), usize>(1).unwrap_err();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | let _val = Err::<(), _>(1).unwrap_err();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Err` and `unwrap_err()`
|
LL - let _val = Err::<(), usize>(1).unwrap_err();
LL - let _val = Err::<(), _>(1).unwrap_err();
LL + let _val = 1;
|
error: used `expect_err()` on `Err` value
--> $DIR/unnecessary_literal_unwrap.rs:25:16
--> $DIR/unnecessary_literal_unwrap.rs:41:16
|
LL | let _val = Err::<(), usize>(1).expect_err("this never happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | let _val = Err::<(), _>(1).expect_err("this never happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Err` and `expect_err()`
|
LL - let _val = Err::<(), usize>(1).expect_err("this never happens");
LL - let _val = Err::<(), _>(1).expect_err("this never happens");
LL + let _val = 1;
|
error: used `unwrap()` on `Err` value
--> $DIR/unnecessary_literal_unwrap.rs:26:5
--> $DIR/unnecessary_literal_unwrap.rs:42:16
|
LL | Err::<(), usize>(1).unwrap();
LL | let _val = Err::<(), _>(1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Err` and `unwrap()`
|
LL | let _val = panic!("{:?}", 1);
| ~~~~~~~~~~~~~~ ~
error: used `expect()` on `Err` value
--> $DIR/unnecessary_literal_unwrap.rs:43:16
|
LL | let _val = Err::<(), _>(1).expect("this always happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Err` and `expect()`
|
LL | let _val = panic!("{1}: {:?}", 1, "this always happens");
| ~~~~~~~~~~~~~~~~~~~ ~
error: used `unwrap_err()` on `Err` value
--> $DIR/unnecessary_literal_unwrap.rs:45:5
|
LL | Err::<(), _>(1).unwrap_err();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Err` and `unwrap_err()`
|
LL - Err::<(), _>(1).unwrap_err();
LL + 1;
|
error: used `expect_err()` on `Err` value
--> $DIR/unnecessary_literal_unwrap.rs:46:5
|
LL | Err::<(), _>(1).expect_err("this never happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Err` and `expect_err()`
|
LL - Err::<(), _>(1).expect_err("this never happens");
LL + 1;
|
error: used `unwrap()` on `Err` value
--> $DIR/unnecessary_literal_unwrap.rs:47:5
|
LL | Err::<(), _>(1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Err` and `unwrap()`
|
LL | panic!("{:?}", 1);
| ~~~~~~~~~~~~~~ ~
error: used `expect()` on `Err` value
--> $DIR/unnecessary_literal_unwrap.rs:27:5
--> $DIR/unnecessary_literal_unwrap.rs:48:5
|
LL | Err::<(), usize>(1).expect("this always happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | Err::<(), _>(1).expect("this always happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Err` and `expect()`
|
@ -133,7 +266,7 @@ LL | panic!("{1}: {:?}", 1, "this always happens");
| ~~~~~~~~~~~~~~~~~~~ ~
error: used `unwrap_or()` on `Some` value
--> $DIR/unnecessary_literal_unwrap.rs:31:16
--> $DIR/unnecessary_literal_unwrap.rs:52:16
|
LL | let _val = Some(1).unwrap_or(2);
| ^^^^^^^^^^^^^^^^^^^^
@ -145,7 +278,7 @@ LL + let _val = 1;
|
error: used `unwrap_or_default()` on `Some` value
--> $DIR/unnecessary_literal_unwrap.rs:32:16
--> $DIR/unnecessary_literal_unwrap.rs:53:16
|
LL | let _val = Some(1).unwrap_or_default();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -157,7 +290,7 @@ LL + let _val = 1;
|
error: used `unwrap_or_else()` on `Some` value
--> $DIR/unnecessary_literal_unwrap.rs:33:16
--> $DIR/unnecessary_literal_unwrap.rs:54:16
|
LL | let _val = Some(1).unwrap_or_else(|| 2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -168,41 +301,113 @@ LL - let _val = Some(1).unwrap_or_else(|| 2);
LL + let _val = 1;
|
error: used `unwrap_or()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap.rs:37:16
error: used `unwrap_or()` on `Some` value
--> $DIR/unnecessary_literal_unwrap.rs:56:5
|
LL | let _val = Ok::<usize, ()>(1).unwrap_or(2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | Some(1).unwrap_or(2);
| ^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Some` and `unwrap_or()`
|
LL - Some(1).unwrap_or(2);
LL + 1;
|
error: used `unwrap_or_default()` on `Some` value
--> $DIR/unnecessary_literal_unwrap.rs:57:5
|
LL | Some(1).unwrap_or_default();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Some` and `unwrap_or_default()`
|
LL - Some(1).unwrap_or_default();
LL + 1;
|
error: used `unwrap_or_else()` on `Some` value
--> $DIR/unnecessary_literal_unwrap.rs:58:5
|
LL | Some(1).unwrap_or_else(|| 2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Some` and `unwrap_or_else()`
|
LL - Some(1).unwrap_or_else(|| 2);
LL + 1;
|
error: used `unwrap_or()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap.rs:62:16
|
LL | let _val = Ok::<_, ()>(1).unwrap_or(2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `unwrap_or()`
|
LL - let _val = Ok::<usize, ()>(1).unwrap_or(2);
LL - let _val = Ok::<_, ()>(1).unwrap_or(2);
LL + let _val = 1;
|
error: used `unwrap_or_default()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap.rs:38:16
--> $DIR/unnecessary_literal_unwrap.rs:63:16
|
LL | let _val = Ok::<usize, ()>(1).unwrap_or_default();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | let _val = Ok::<_, ()>(1).unwrap_or_default();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `unwrap_or_default()`
|
LL - let _val = Ok::<usize, ()>(1).unwrap_or_default();
LL - let _val = Ok::<_, ()>(1).unwrap_or_default();
LL + let _val = 1;
|
error: used `unwrap_or_else()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap.rs:39:16
--> $DIR/unnecessary_literal_unwrap.rs:64:16
|
LL | let _val = Ok::<usize, ()>(1).unwrap_or_else(|_| 2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | let _val = Ok::<_, ()>(1).unwrap_or_else(|_| 2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `unwrap_or_else()`
|
LL - let _val = Ok::<usize, ()>(1).unwrap_or_else(|_| 2);
LL - let _val = Ok::<_, ()>(1).unwrap_or_else(|_| 2);
LL + let _val = 1;
|
error: aborting due to 18 previous errors
error: used `unwrap_or()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap.rs:66:5
|
LL | Ok::<_, ()>(1).unwrap_or(2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `unwrap_or()`
|
LL - Ok::<_, ()>(1).unwrap_or(2);
LL + 1;
|
error: used `unwrap_or_default()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap.rs:67:5
|
LL | Ok::<_, ()>(1).unwrap_or_default();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `unwrap_or_default()`
|
LL - Ok::<_, ()>(1).unwrap_or_default();
LL + 1;
|
error: used `unwrap_or_else()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap.rs:68:5
|
LL | Ok::<_, ()>(1).unwrap_or_else(|_| 2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `unwrap_or_else()`
|
LL - Ok::<_, ()>(1).unwrap_or_else(|_| 2);
LL + 1;
|
error: aborting due to 36 previous errors

View file

@ -1,6 +1,6 @@
#![warn(clippy::unnecessary_literal_unwrap)]
#![allow(clippy::unnecessary_lazy_evaluations)]
#![allow(unreachable_code)]
#![allow(clippy::unnecessary_lazy_evaluations, clippy::let_unit_value)]
fn unwrap_option_some() {
let val = Some(1);
@ -8,26 +8,61 @@ fn unwrap_option_some() {
let _val2 = val.expect("this never happens");
}
fn unwrap_option_some_context() {
let _val = Some::<usize>([1, 2, 3].iter().sum()).unwrap();
let _val = Some::<usize>([1, 2, 3].iter().sum()).expect("this never happens");
let val = Some::<usize>([1, 2, 3].iter().sum());
let _val2 = val.unwrap();
let _val2 = val.expect("this never happens");
}
fn unwrap_option_none() {
let val = None::<usize>;
val.unwrap();
val.expect("this always happens");
let val = None::<()>;
let _val2 = val.unwrap();
let _val2 = val.expect("this always happens");
}
fn unwrap_result_ok() {
let val = Ok::<usize, ()>(1);
let val = Ok::<_, ()>(1);
let _val2 = val.unwrap();
let _val2 = val.expect("this never happens");
val.unwrap_err();
val.expect_err("this always happens");
let _val2 = val.unwrap_err();
let _val2 = val.expect_err("this always happens");
}
fn unwrap_result_ok_context() {
let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap();
let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).expect("this never happens");
let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_err();
let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).expect_err("this always happens");
let val = Ok::<usize, ()>([1, 2, 3].iter().sum());
let _val2 = val.unwrap();
let _val2 = val.expect("this never happens");
let _val2 = val.unwrap_err();
let _val2 = val.expect_err("this always happens");
}
fn unwrap_result_err() {
let val = Err::<(), usize>(1);
let val = Err::<(), _>(1);
let _val2 = val.unwrap_err();
let _val2 = val.expect_err("this never happens");
val.unwrap();
val.expect("this always happens");
let _val2 = val.unwrap();
let _val2 = val.expect("this always happens");
}
fn unwrap_result_err_context() {
let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap_err();
let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect_err("this never happens");
let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap();
let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect("this always happens");
let val = Err::<(), usize>([1, 2, 3].iter().sum());
let _val2 = val.unwrap_err();
let _val2 = val.expect_err("this never happens");
let _val2 = val.unwrap();
let _val2 = val.expect("this always happens");
}
fn unwrap_methods_option() {
@ -37,8 +72,30 @@ fn unwrap_methods_option() {
let _val2 = val.unwrap_or_else(|| 2);
}
fn unwrap_methods_option_context() {
let _val = Some::<usize>([1, 2, 3].iter().sum()).unwrap_or(2);
let _val = Some::<usize>([1, 2, 3].iter().sum()).unwrap_or_default();
let _val = Some::<usize>([1, 2, 3].iter().sum()).unwrap_or_else(|| 2);
let val = Some::<usize>([1, 2, 3].iter().sum());
let _val2 = val.unwrap_or(2);
let _val2 = val.unwrap_or_default();
let _val2 = val.unwrap_or_else(|| 2);
}
fn unwrap_methods_result() {
let val = Ok::<usize, ()>(1);
let val = Ok::<_, ()>(1);
let _val2 = val.unwrap_or(2);
let _val2 = val.unwrap_or_default();
let _val2 = val.unwrap_or_else(|_| 2);
}
fn unwrap_methods_result_context() {
let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_or(2);
let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_or_default();
let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_or_else(|_| 2);
let val = Ok::<usize, ()>([1, 2, 3].iter().sum());
let _val2 = val.unwrap_or(2);
let _val2 = val.unwrap_or_default();
let _val2 = val.unwrap_or_else(|_| 2);
@ -46,9 +103,14 @@ fn unwrap_methods_result() {
fn main() {
unwrap_option_some();
unwrap_option_some_context();
unwrap_option_none();
unwrap_result_ok();
unwrap_result_ok_context();
unwrap_result_err();
unwrap_result_err_context();
unwrap_methods_option();
unwrap_methods_option_context();
unwrap_methods_result();
unwrap_methods_result_context();
}

View file

@ -23,197 +23,581 @@ help: remove the `Some` and `expect()`
LL | let val = Some(1);
| ^^^^^^^
error: used `unwrap()` on `None` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:13:5
error: used `unwrap()` on `Some` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:12:16
|
LL | val.unwrap();
| ^^^^^^^^^^^^
LL | let _val = Some::<usize>([1, 2, 3].iter().sum()).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Some` and `unwrap()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:12:16
|
LL | let _val = Some::<usize>([1, 2, 3].iter().sum()).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `expect()` on `Some` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:13:16
|
LL | let _val = Some::<usize>([1, 2, 3].iter().sum()).expect("this never happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Some` and `expect()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:13:16
|
LL | let _val = Some::<usize>([1, 2, 3].iter().sum()).expect("this never happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `unwrap()` on `Some` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:16:17
|
LL | let _val2 = val.unwrap();
| ^^^^^^^^^^^^
|
help: remove the `Some` and `unwrap()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:15:15
|
LL | let val = Some::<usize>([1, 2, 3].iter().sum());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `expect()` on `Some` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:17:17
|
LL | let _val2 = val.expect("this never happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Some` and `expect()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:15:15
|
LL | let val = Some::<usize>([1, 2, 3].iter().sum());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `unwrap()` on `None` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:22:17
|
LL | let _val2 = val.unwrap();
| ^^^^^^^^^^^^
|
help: remove the `None` and `unwrap()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:12:15
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:21:15
|
LL | let val = None::<usize>;
| ^^^^^^^^^^^^^
LL | let val = None::<()>;
| ^^^^^^^^^^
error: used `expect()` on `None` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:14:5
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:23:17
|
LL | val.expect("this always happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | let _val2 = val.expect("this always happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `None` and `expect()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:12:15
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:21:15
|
LL | let val = None::<usize>;
| ^^^^^^^^^^^^^
LL | let val = None::<()>;
| ^^^^^^^^^^
error: used `unwrap()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:19:17
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:28:17
|
LL | let _val2 = val.unwrap();
| ^^^^^^^^^^^^
|
help: remove the `Ok` and `unwrap()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:18:15
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:27:15
|
LL | let val = Ok::<usize, ()>(1);
| ^^^^^^^^^^^^^^^^^^
LL | let val = Ok::<_, ()>(1);
| ^^^^^^^^^^^^^^
error: used `expect()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:20:17
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:29:17
|
LL | let _val2 = val.expect("this never happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `expect()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:18:15
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:27:15
|
LL | let val = Ok::<usize, ()>(1);
| ^^^^^^^^^^^^^^^^^^
LL | let val = Ok::<_, ()>(1);
| ^^^^^^^^^^^^^^
error: used `unwrap_err()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:21:5
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:30:17
|
LL | val.unwrap_err();
| ^^^^^^^^^^^^^^^^
LL | let _val2 = val.unwrap_err();
| ^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `unwrap_err()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:18:15
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:27:15
|
LL | let val = Ok::<usize, ()>(1);
| ^^^^^^^^^^^^^^^^^^
LL | let val = Ok::<_, ()>(1);
| ^^^^^^^^^^^^^^
error: used `expect_err()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:22:5
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:31:17
|
LL | val.expect_err("this always happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | let _val2 = val.expect_err("this always happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `expect_err()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:18:15
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:27:15
|
LL | let val = Ok::<usize, ()>(1);
| ^^^^^^^^^^^^^^^^^^
LL | let val = Ok::<_, ()>(1);
| ^^^^^^^^^^^^^^
error: used `unwrap()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:35:16
|
LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `unwrap()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:35:16
|
LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `expect()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:36:16
|
LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).expect("this never happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `expect()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:36:16
|
LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).expect("this never happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `unwrap_err()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:37:16
|
LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_err();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `unwrap_err()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:37:16
|
LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_err();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `expect_err()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:38:16
|
LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).expect_err("this always happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `expect_err()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:38:16
|
LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).expect_err("this always happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `unwrap()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:41:17
|
LL | let _val2 = val.unwrap();
| ^^^^^^^^^^^^
|
help: remove the `Ok` and `unwrap()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:40:15
|
LL | let val = Ok::<usize, ()>([1, 2, 3].iter().sum());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `expect()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:42:17
|
LL | let _val2 = val.expect("this never happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `expect()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:40:15
|
LL | let val = Ok::<usize, ()>([1, 2, 3].iter().sum());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `unwrap_err()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:43:17
|
LL | let _val2 = val.unwrap_err();
| ^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `unwrap_err()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:40:15
|
LL | let val = Ok::<usize, ()>([1, 2, 3].iter().sum());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `expect_err()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:44:17
|
LL | let _val2 = val.expect_err("this always happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `expect_err()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:40:15
|
LL | let val = Ok::<usize, ()>([1, 2, 3].iter().sum());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `unwrap_err()` on `Err` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:27:17
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:49:17
|
LL | let _val2 = val.unwrap_err();
| ^^^^^^^^^^^^^^^^
|
help: remove the `Err` and `unwrap_err()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:26:15
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:48:15
|
LL | let val = Err::<(), usize>(1);
| ^^^^^^^^^^^^^^^^^^^
LL | let val = Err::<(), _>(1);
| ^^^^^^^^^^^^^^^
error: used `expect_err()` on `Err` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:28:17
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:50:17
|
LL | let _val2 = val.expect_err("this never happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Err` and `expect_err()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:26:15
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:48:15
|
LL | let val = Err::<(), usize>(1);
| ^^^^^^^^^^^^^^^^^^^
LL | let val = Err::<(), _>(1);
| ^^^^^^^^^^^^^^^
error: used `unwrap()` on `Err` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:29:5
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:51:17
|
LL | val.unwrap();
| ^^^^^^^^^^^^
LL | let _val2 = val.unwrap();
| ^^^^^^^^^^^^
|
help: remove the `Err` and `unwrap()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:26:15
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:48:15
|
LL | let val = Err::<(), usize>(1);
| ^^^^^^^^^^^^^^^^^^^
LL | let val = Err::<(), _>(1);
| ^^^^^^^^^^^^^^^
error: used `expect()` on `Err` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:30:5
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:52:17
|
LL | val.expect("this always happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | let _val2 = val.expect("this always happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Err` and `expect()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:26:15
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:48:15
|
LL | let val = Err::<(), usize>(1);
| ^^^^^^^^^^^^^^^^^^^
LL | let val = Err::<(), _>(1);
| ^^^^^^^^^^^^^^^
error: used `unwrap_err()` on `Err` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:56:16
|
LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap_err();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Err` and `unwrap_err()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:56:16
|
LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap_err();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `expect_err()` on `Err` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:57:16
|
LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect_err("this never happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Err` and `expect_err()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:57:16
|
LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect_err("this never happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `unwrap()` on `Err` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:58:16
|
LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Err` and `unwrap()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:58:16
|
LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `expect()` on `Err` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:59:16
|
LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect("this always happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Err` and `expect()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:59:16
|
LL | let _val = Err::<(), usize>([1, 2, 3].iter().sum()).expect("this always happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `unwrap_err()` on `Err` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:62:17
|
LL | let _val2 = val.unwrap_err();
| ^^^^^^^^^^^^^^^^
|
help: remove the `Err` and `unwrap_err()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:61:15
|
LL | let val = Err::<(), usize>([1, 2, 3].iter().sum());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `expect_err()` on `Err` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:63:17
|
LL | let _val2 = val.expect_err("this never happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Err` and `expect_err()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:61:15
|
LL | let val = Err::<(), usize>([1, 2, 3].iter().sum());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `unwrap()` on `Err` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:64:17
|
LL | let _val2 = val.unwrap();
| ^^^^^^^^^^^^
|
help: remove the `Err` and `unwrap()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:61:15
|
LL | let val = Err::<(), usize>([1, 2, 3].iter().sum());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `expect()` on `Err` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:65:17
|
LL | let _val2 = val.expect("this always happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Err` and `expect()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:61:15
|
LL | let val = Err::<(), usize>([1, 2, 3].iter().sum());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `unwrap_or()` on `Some` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:35:17
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:70:17
|
LL | let _val2 = val.unwrap_or(2);
| ^^^^^^^^^^^^^^^^
|
help: remove the `Some` and `unwrap_or()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:34:15
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:69:15
|
LL | let val = Some(1);
| ^^^^^^^
error: used `unwrap_or_default()` on `Some` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:36:17
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:71:17
|
LL | let _val2 = val.unwrap_or_default();
| ^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Some` and `unwrap_or_default()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:34:15
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:69:15
|
LL | let val = Some(1);
| ^^^^^^^
error: used `unwrap_or_else()` on `Some` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:37:17
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:72:17
|
LL | let _val2 = val.unwrap_or_else(|| 2);
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Some` and `unwrap_or_else()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:34:15
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:69:15
|
LL | let val = Some(1);
| ^^^^^^^
error: used `unwrap_or()` on `Some` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:76:16
|
LL | let _val = Some::<usize>([1, 2, 3].iter().sum()).unwrap_or(2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Some` and `unwrap_or()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:76:16
|
LL | let _val = Some::<usize>([1, 2, 3].iter().sum()).unwrap_or(2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `unwrap_or_default()` on `Some` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:77:16
|
LL | let _val = Some::<usize>([1, 2, 3].iter().sum()).unwrap_or_default();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Some` and `unwrap_or_default()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:77:16
|
LL | let _val = Some::<usize>([1, 2, 3].iter().sum()).unwrap_or_default();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `unwrap_or_else()` on `Some` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:78:16
|
LL | let _val = Some::<usize>([1, 2, 3].iter().sum()).unwrap_or_else(|| 2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Some` and `unwrap_or_else()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:78:16
|
LL | let _val = Some::<usize>([1, 2, 3].iter().sum()).unwrap_or_else(|| 2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `unwrap_or()` on `Some` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:81:17
|
LL | let _val2 = val.unwrap_or(2);
| ^^^^^^^^^^^^^^^^
|
help: remove the `Some` and `unwrap_or()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:80:15
|
LL | let val = Some::<usize>([1, 2, 3].iter().sum());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `unwrap_or_default()` on `Some` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:82:17
|
LL | let _val2 = val.unwrap_or_default();
| ^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Some` and `unwrap_or_default()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:80:15
|
LL | let val = Some::<usize>([1, 2, 3].iter().sum());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `unwrap_or_else()` on `Some` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:83:17
|
LL | let _val2 = val.unwrap_or_else(|| 2);
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Some` and `unwrap_or_else()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:80:15
|
LL | let val = Some::<usize>([1, 2, 3].iter().sum());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `unwrap_or()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:42:17
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:88:17
|
LL | let _val2 = val.unwrap_or(2);
| ^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `unwrap_or()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:41:15
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:87:15
|
LL | let val = Ok::<usize, ()>(1);
| ^^^^^^^^^^^^^^^^^^
LL | let val = Ok::<_, ()>(1);
| ^^^^^^^^^^^^^^
error: used `unwrap_or_default()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:43:17
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:89:17
|
LL | let _val2 = val.unwrap_or_default();
| ^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `unwrap_or_default()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:41:15
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:87:15
|
LL | let val = Ok::<usize, ()>(1);
| ^^^^^^^^^^^^^^^^^^
LL | let val = Ok::<_, ()>(1);
| ^^^^^^^^^^^^^^
error: used `unwrap_or_else()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:44:17
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:90:17
|
LL | let _val2 = val.unwrap_or_else(|_| 2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `unwrap_or_else()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:41:15
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:87:15
|
LL | let val = Ok::<usize, ()>(1);
| ^^^^^^^^^^^^^^^^^^
LL | let val = Ok::<_, ()>(1);
| ^^^^^^^^^^^^^^
error: aborting due to 18 previous errors
error: used `unwrap_or()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:94:16
|
LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_or(2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `unwrap_or()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:94:16
|
LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_or(2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `unwrap_or_default()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:95:16
|
LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_or_default();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `unwrap_or_default()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:95:16
|
LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_or_default();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `unwrap_or_else()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:96:16
|
LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_or_else(|_| 2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `unwrap_or_else()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:96:16
|
LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_or_else(|_| 2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `unwrap_or()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:99:17
|
LL | let _val2 = val.unwrap_or(2);
| ^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `unwrap_or()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:98:15
|
LL | let val = Ok::<usize, ()>([1, 2, 3].iter().sum());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `unwrap_or_default()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:100:17
|
LL | let _val2 = val.unwrap_or_default();
| ^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `unwrap_or_default()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:98:15
|
LL | let val = Ok::<usize, ()>([1, 2, 3].iter().sum());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `unwrap_or_else()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:101:17
|
LL | let _val2 = val.unwrap_or_else(|_| 2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `unwrap_or_else()`
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:98:15
|
LL | let val = Ok::<usize, ()>([1, 2, 3].iter().sum());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 50 previous errors