From 1af23d246362451faa2ff6fd3e5de5a6e5dd549a Mon Sep 17 00:00:00 2001
From: rsdy
Date: Thu, 16 Feb 2023 10:47:12 +0000
Subject: [PATCH 01/16] Add test code
---
tests/ui/unwrap_literal.rs | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
create mode 100644 tests/ui/unwrap_literal.rs
diff --git a/tests/ui/unwrap_literal.rs b/tests/ui/unwrap_literal.rs
new file mode 100644
index 000000000000..917ef2126f51
--- /dev/null
+++ b/tests/ui/unwrap_literal.rs
@@ -0,0 +1,17 @@
+#![warn(clippy::unnecessary_unwrap)]
+
+fn unwrap_option() {
+ let val = Some(1).unwrap();
+ let val = Some(1).expect("this never happens");
+}
+
+fn unwrap_result() {
+ let val = Ok(1).unwrap();
+ let val = Err(1).unwrap_err();
+ let val = Ok(1).expect("this never happens");
+}
+
+fn main() {
+ unwrap_option();
+ unwrap_result();
+}
From e707447a861739fa3e12e9c05c039c8c9c6b0544 Mon Sep 17 00:00:00 2001
From: Pavan Kumar Sunkara
Date: Thu, 16 Feb 2023 11:32:12 +0000
Subject: [PATCH 02/16] Boilerplate for the new lint
---
clippy_lints/src/methods/mod.rs | 52 +++++++++++++++++++
.../src/methods/unnecessary_literal_unwrap.rs | 30 +++++++++++
tests/ui/unnecessary_literal_unwrap.rs | 10 ++++
tests/ui/unwrap_literal.rs | 17 ------
4 files changed, 92 insertions(+), 17 deletions(-)
create mode 100644 clippy_lints/src/methods/unnecessary_literal_unwrap.rs
create mode 100644 tests/ui/unnecessary_literal_unwrap.rs
delete mode 100644 tests/ui/unwrap_literal.rs
diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs
index 88cbefbb5d3d..f24f00ef6a7f 100644
--- a/clippy_lints/src/methods/mod.rs
+++ b/clippy_lints/src/methods/mod.rs
@@ -93,6 +93,7 @@ mod unnecessary_fold;
mod unnecessary_iter_cloned;
mod unnecessary_join;
mod unnecessary_lazy_eval;
+mod unnecessary_literal_unwrap;
mod unnecessary_sort_by;
mod unnecessary_to_owned;
mod unwrap_or_else_default;
@@ -273,6 +274,56 @@ declare_clippy_lint! {
"using `.unwrap()` on `Result` or `Option`, which should at least get a better message using `expect()`"
}
+declare_clippy_lint! {
+ /// ### What it does
+ /// Checks for `.unwrap()` or `.unwrap_err()` calls on `Result`s and `.unwrap()` call on `Option`s.
+ ///
+ /// ### 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.
+ ///
+ /// ### Examples
+ /// ```rust
+ /// # let option = Some(1);
+ /// # let result: Result = Ok(1);
+ /// option.unwrap();
+ /// result.unwrap();
+ /// ```
+ ///
+ /// Use instead:
+ /// ```rust
+ /// # let option = Some(1);
+ /// # let result: Result = 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 = Ok(1);
+ /// option?;
+ ///
+ /// // or
+ ///
+ /// result?;
+ /// ```
+ #[clippy::version = "1.69.0"]
+ pub UNNECESSARY_LITERAL_UNWRAP,
+ complexity,
+ "checks for calls of `unwrap()` or `expect()` on `Some()` that cannot fail"
+}
+
declare_clippy_lint! {
/// ### What it does
/// Checks for `.expect()` or `.expect_err()` calls on `Result`s and `.expect()` call on `Option`s.
@@ -3814,6 +3865,7 @@ impl Methods {
Some(("or", recv, [or_arg], or_span, _)) => {
or_then_unwrap::check(cx, expr, recv, or_arg, or_span);
},
+ // unnecessary_literal_unwrap::check(cx, expr, recv);
_ => {},
}
unwrap_used::check(cx, expr, recv, false, self.allow_unwrap_in_tests);
diff --git a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
new file mode 100644
index 000000000000..39b30b7769db
--- /dev/null
+++ b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
@@ -0,0 +1,30 @@
+use clippy_utils::diagnostics::span_lint_and_help;
+use clippy_utils::ty::is_type_diagnostic_item;
+use rustc_hir as hir;
+use rustc_lint::LateContext;
+use rustc_span::sym;
+
+use super::UNNECESSARY_LITERAL_UNWRAP;
+
+pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) {
+ let obj_ty = cx.typeck_results().expr_ty(recv).peel_refs();
+
+ let mess = if is_type_diagnostic_item(cx, obj_ty, sym::Option) {
+ Some((UNNECESSARY_LITERAL_UNWRAP, "an `Option`", "None", ""))
+ } else {
+ None
+ };
+
+ if let Some((lint, kind, none_value, none_prefix)) = mess {
+ let help = format!("if this value is {none_prefix}`{none_value}`, it will panic");
+
+ span_lint_and_help(
+ cx,
+ lint,
+ expr.span,
+ &format!("used `unwrap()` on {kind} value"),
+ None,
+ &help,
+ );
+ }
+}
diff --git a/tests/ui/unnecessary_literal_unwrap.rs b/tests/ui/unnecessary_literal_unwrap.rs
new file mode 100644
index 000000000000..9ae50517a3ea
--- /dev/null
+++ b/tests/ui/unnecessary_literal_unwrap.rs
@@ -0,0 +1,10 @@
+#![warn(clippy::unnecessary_literal_unwrap)]
+
+fn unwrap_option() {
+ let val = Some(1).unwrap();
+ let val = Some(1).expect("this never happens");
+}
+
+fn main() {
+ unwrap_option();
+}
diff --git a/tests/ui/unwrap_literal.rs b/tests/ui/unwrap_literal.rs
deleted file mode 100644
index 917ef2126f51..000000000000
--- a/tests/ui/unwrap_literal.rs
+++ /dev/null
@@ -1,17 +0,0 @@
-#![warn(clippy::unnecessary_unwrap)]
-
-fn unwrap_option() {
- let val = Some(1).unwrap();
- let val = Some(1).expect("this never happens");
-}
-
-fn unwrap_result() {
- let val = Ok(1).unwrap();
- let val = Err(1).unwrap_err();
- let val = Ok(1).expect("this never happens");
-}
-
-fn main() {
- unwrap_option();
- unwrap_result();
-}
From 5bb768177ee83065191b1f47111ecf63de347cff Mon Sep 17 00:00:00 2001
From: rsdy
Date: Thu, 16 Feb 2023 11:49:19 +0000
Subject: [PATCH 03/16] Add hook
---
clippy_lints/src/methods/mod.rs | 4 +++-
clippy_lints/src/methods/unnecessary_literal_unwrap.rs | 2 +-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs
index f24f00ef6a7f..9d7b607ec7bb 100644
--- a/clippy_lints/src/methods/mod.rs
+++ b/clippy_lints/src/methods/mod.rs
@@ -3865,7 +3865,9 @@ impl Methods {
Some(("or", recv, [or_arg], or_span, _)) => {
or_then_unwrap::check(cx, expr, recv, or_arg, or_span);
},
- // unnecessary_literal_unwrap::check(cx, expr, recv);
+ Some((constructor @ "Some", _, _, _, _)) => {
+ unnecessary_literal_unwrap::check(cx, expr, recv, constructor);
+ }
_ => {},
}
unwrap_used::check(cx, expr, recv, false, self.allow_unwrap_in_tests);
diff --git a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
index 39b30b7769db..3572f4965ef7 100644
--- a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
+++ b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
@@ -6,7 +6,7 @@ use rustc_span::sym;
use super::UNNECESSARY_LITERAL_UNWRAP;
-pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) {
+pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>, constructor: &str) {
let obj_ty = cx.typeck_results().expr_ty(recv).peel_refs();
let mess = if is_type_diagnostic_item(cx, obj_ty, sym::Option) {
From 2902359b3c922910b5b5bc1c2fa73c3e8bf2fcfb Mon Sep 17 00:00:00 2001
From: Pavan Kumar Sunkara
Date: Thu, 16 Feb 2023 11:32:12 +0000
Subject: [PATCH 04/16] Add the lint to the lib
---
clippy_lints/src/declared_lints.rs | 1 +
clippy_lints/src/methods/mod.rs | 1 +
2 files changed, 2 insertions(+)
diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs
index 523faa302dc7..62317dc60ebf 100644
--- a/clippy_lints/src/declared_lints.rs
+++ b/clippy_lints/src/declared_lints.rs
@@ -408,6 +408,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
crate::methods::UNNECESSARY_FOLD_INFO,
crate::methods::UNNECESSARY_JOIN_INFO,
crate::methods::UNNECESSARY_LAZY_EVALUATIONS_INFO,
+ crate::methods::UNNECESSARY_LITERAL_UNWRAP_INFO,
crate::methods::UNNECESSARY_SORT_BY_INFO,
crate::methods::UNNECESSARY_TO_OWNED_INFO,
crate::methods::UNWRAP_OR_ELSE_DEFAULT_INFO,
diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs
index 9d7b607ec7bb..6eb97227e0ac 100644
--- a/clippy_lints/src/methods/mod.rs
+++ b/clippy_lints/src/methods/mod.rs
@@ -3400,6 +3400,7 @@ impl_lint_pass!(Methods => [
SUSPICIOUS_COMMAND_ARG_SPACE,
CLEAR_WITH_DRAIN,
MANUAL_NEXT_BACK,
+ UNNECESSARY_LITERAL_UNWRAP,
]);
/// Extracts a method call name, args, and `Span` of the method name.
From 0b1bb5fbf3a4d3e73192f95490ce7246f9fd1914 Mon Sep 17 00:00:00 2001
From: Pavan Kumar Sunkara
Date: Thu, 16 Feb 2023 13:36:51 +0000
Subject: [PATCH 05/16] Implement the lint
---
clippy_lints/src/methods/mod.rs | 6 +++---
.../src/methods/unnecessary_literal_unwrap.rs | 19 +++++++------------
tests/ui/unnecessary_literal_unwrap.stderr | 11 +++++++++++
3 files changed, 21 insertions(+), 15 deletions(-)
create mode 100644 tests/ui/unnecessary_literal_unwrap.stderr
diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs
index 6eb97227e0ac..7a7d5a588b00 100644
--- a/clippy_lints/src/methods/mod.rs
+++ b/clippy_lints/src/methods/mod.rs
@@ -3866,11 +3866,11 @@ impl Methods {
Some(("or", recv, [or_arg], or_span, _)) => {
or_then_unwrap::check(cx, expr, recv, or_arg, or_span);
},
- Some((constructor @ "Some", _, _, _, _)) => {
- unnecessary_literal_unwrap::check(cx, expr, recv, constructor);
- }
_ => {},
}
+ if let ExprKind::Call(recv, _) = recv.kind {
+ unnecessary_literal_unwrap::check(cx, expr, recv, name);
+ }
unwrap_used::check(cx, expr, recv, false, self.allow_unwrap_in_tests);
},
("unwrap_err", []) => unwrap_used::check(cx, expr, recv, true, self.allow_unwrap_in_tests),
diff --git a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
index 3572f4965ef7..181e4a06664b 100644
--- a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
+++ b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
@@ -1,28 +1,23 @@
-use clippy_utils::diagnostics::span_lint_and_help;
-use clippy_utils::ty::is_type_diagnostic_item;
+use clippy_utils::{diagnostics::span_lint_and_help, is_res_lang_ctor, path_res};
use rustc_hir as hir;
use rustc_lint::LateContext;
-use rustc_span::sym;
use super::UNNECESSARY_LITERAL_UNWRAP;
-pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>, constructor: &str) {
- let obj_ty = cx.typeck_results().expr_ty(recv).peel_refs();
-
- let mess = if is_type_diagnostic_item(cx, obj_ty, sym::Option) {
- Some((UNNECESSARY_LITERAL_UNWRAP, "an `Option`", "None", ""))
+pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>, name: &str) {
+ let mess = if is_res_lang_ctor(cx, path_res(cx, recv), hir::LangItem::OptionSome) {
+ Some((UNNECESSARY_LITERAL_UNWRAP, "Some"))
} else {
None
};
- if let Some((lint, kind, none_value, none_prefix)) = mess {
- let help = format!("if this value is {none_prefix}`{none_value}`, it will panic");
-
+ if let Some((lint, constructor)) = mess {
+ let help = String::new();
span_lint_and_help(
cx,
lint,
expr.span,
- &format!("used `unwrap()` on {kind} value"),
+ &format!("used `{name}()` on `{constructor}` value"),
None,
&help,
);
diff --git a/tests/ui/unnecessary_literal_unwrap.stderr b/tests/ui/unnecessary_literal_unwrap.stderr
new file mode 100644
index 000000000000..5f9881b2ae34
--- /dev/null
+++ b/tests/ui/unnecessary_literal_unwrap.stderr
@@ -0,0 +1,11 @@
+error: used `unwrap()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap.rs:4:15
+ |
+LL | let val = Some(1).unwrap();
+ | ^^^^^^^^^^^^^^^^
+ |
+ = help:
+ = note: `-D clippy::unnecessary-literal-unwrap` implied by `-D warnings`
+
+error: aborting due to previous error
+
From 21b88ce290ee90259fdd35b33923ee330acb0991 Mon Sep 17 00:00:00 2001
From: Pavan Kumar Sunkara
Date: Thu, 16 Feb 2023 13:44:11 +0000
Subject: [PATCH 06/16] Implement the lint for expect
---
clippy_lints/src/methods/mod.rs | 13 +++++++++----
tests/ui/unnecessary_literal_unwrap.stderr | 10 +++++++++-
2 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs
index 7a7d5a588b00..cb82aef1ef0f 100644
--- a/clippy_lints/src/methods/mod.rs
+++ b/clippy_lints/src/methods/mod.rs
@@ -3658,10 +3658,15 @@ impl Methods {
case_sensitive_file_extension_comparisons::check(cx, expr, span, recv, arg);
}
},
- ("expect", [_]) => match method_call(recv) {
- Some(("ok", recv, [], _, _)) => ok_expect::check(cx, expr, recv),
- Some(("err", recv, [], err_span, _)) => err_expect::check(cx, expr, recv, span, err_span, &self.msrv),
- _ => expect_used::check(cx, expr, recv, false, self.allow_expect_in_tests),
+ ("expect", [_]) => {
+ match method_call(recv) {
+ Some(("ok", recv, [], _, _)) => ok_expect::check(cx, expr, recv),
+ Some(("err", recv, [], err_span, _)) => err_expect::check(cx, expr, recv, span, err_span, &self.msrv),
+ _ => expect_used::check(cx, expr, recv, false, self.allow_expect_in_tests),
+ }
+ if let ExprKind::Call(recv, _) = recv.kind {
+ unnecessary_literal_unwrap::check(cx, expr, recv, name);
+ }
},
("expect_err", [_]) => expect_used::check(cx, expr, recv, true, self.allow_expect_in_tests),
("extend", [arg]) => {
diff --git a/tests/ui/unnecessary_literal_unwrap.stderr b/tests/ui/unnecessary_literal_unwrap.stderr
index 5f9881b2ae34..414d4445caeb 100644
--- a/tests/ui/unnecessary_literal_unwrap.stderr
+++ b/tests/ui/unnecessary_literal_unwrap.stderr
@@ -7,5 +7,13 @@ LL | let val = Some(1).unwrap();
= help:
= note: `-D clippy::unnecessary-literal-unwrap` implied by `-D warnings`
-error: aborting due to previous error
+error: used `expect()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap.rs:5:15
+ |
+LL | let val = Some(1).expect("this never happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help:
+
+error: aborting due to 2 previous errors
From daf61974813ba6f9e7513068bc8cce2839fb8939 Mon Sep 17 00:00:00 2001
From: Pavan Kumar Sunkara
Date: Thu, 16 Feb 2023 14:21:43 +0000
Subject: [PATCH 07/16] Implement the suggestion
---
clippy_lints/src/methods/mod.rs | 8 +++----
.../src/methods/unnecessary_literal_unwrap.rs | 22 ++++++++++++++-----
tests/ui/unnecessary_literal_unwrap.fixed | 11 ++++++++++
tests/ui/unnecessary_literal_unwrap.rs | 1 +
tests/ui/unnecessary_literal_unwrap.stderr | 16 ++++++++++----
5 files changed, 44 insertions(+), 14 deletions(-)
create mode 100644 tests/ui/unnecessary_literal_unwrap.fixed
diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs
index cb82aef1ef0f..a5c55a42ea55 100644
--- a/clippy_lints/src/methods/mod.rs
+++ b/clippy_lints/src/methods/mod.rs
@@ -3664,8 +3664,8 @@ impl Methods {
Some(("err", recv, [], err_span, _)) => err_expect::check(cx, expr, recv, span, err_span, &self.msrv),
_ => expect_used::check(cx, expr, recv, false, self.allow_expect_in_tests),
}
- if let ExprKind::Call(recv, _) = recv.kind {
- unnecessary_literal_unwrap::check(cx, expr, recv, name);
+ if let ExprKind::Call(recv, [arg]) = recv.kind {
+ unnecessary_literal_unwrap::check(cx, expr, recv, arg, name);
}
},
("expect_err", [_]) => expect_used::check(cx, expr, recv, true, self.allow_expect_in_tests),
@@ -3873,8 +3873,8 @@ impl Methods {
},
_ => {},
}
- if let ExprKind::Call(recv, _) = recv.kind {
- unnecessary_literal_unwrap::check(cx, expr, recv, name);
+ if let ExprKind::Call(recv, [arg]) = recv.kind {
+ unnecessary_literal_unwrap::check(cx, expr, recv, arg, name);
}
unwrap_used::check(cx, expr, recv, false, self.allow_unwrap_in_tests);
},
diff --git a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
index 181e4a06664b..9a82d7e58ea6 100644
--- a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
+++ b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
@@ -1,10 +1,11 @@
-use clippy_utils::{diagnostics::span_lint_and_help, is_res_lang_ctor, path_res};
+use clippy_utils::{diagnostics::span_lint_and_then, is_res_lang_ctor, path_res};
+use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_lint::LateContext;
use super::UNNECESSARY_LITERAL_UNWRAP;
-pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>, name: &str) {
+pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>, arg: &hir::Expr<'_>, name: &str) {
let mess = if is_res_lang_ctor(cx, path_res(cx, recv), hir::LangItem::OptionSome) {
Some((UNNECESSARY_LITERAL_UNWRAP, "Some"))
} else {
@@ -12,14 +13,23 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr
};
if let Some((lint, constructor)) = mess {
- let help = String::new();
- span_lint_and_help(
+ span_lint_and_then(
cx,
lint,
expr.span,
&format!("used `{name}()` on `{constructor}` value"),
- None,
- &help,
+ |diag| {
+ let suggestions = vec![
+ (recv.span.with_hi(arg.span.lo()), String::new()),
+ (expr.span.with_lo(arg.span.hi()), String::new()),
+ ];
+
+ diag.multipart_suggestion(
+ format!("remove the `{constructor}` and `{name}()`"),
+ suggestions,
+ Applicability::MachineApplicable,
+ );
+ },
);
}
}
diff --git a/tests/ui/unnecessary_literal_unwrap.fixed b/tests/ui/unnecessary_literal_unwrap.fixed
new file mode 100644
index 000000000000..8696048d3324
--- /dev/null
+++ b/tests/ui/unnecessary_literal_unwrap.fixed
@@ -0,0 +1,11 @@
+//run-rustfix
+#![warn(clippy::unnecessary_literal_unwrap)]
+
+fn unwrap_option() {
+ let val = 1;
+ let val = 1;
+}
+
+fn main() {
+ unwrap_option();
+}
diff --git a/tests/ui/unnecessary_literal_unwrap.rs b/tests/ui/unnecessary_literal_unwrap.rs
index 9ae50517a3ea..ae41634495b3 100644
--- a/tests/ui/unnecessary_literal_unwrap.rs
+++ b/tests/ui/unnecessary_literal_unwrap.rs
@@ -1,3 +1,4 @@
+//run-rustfix
#![warn(clippy::unnecessary_literal_unwrap)]
fn unwrap_option() {
diff --git a/tests/ui/unnecessary_literal_unwrap.stderr b/tests/ui/unnecessary_literal_unwrap.stderr
index 414d4445caeb..00d7f186fc41 100644
--- a/tests/ui/unnecessary_literal_unwrap.stderr
+++ b/tests/ui/unnecessary_literal_unwrap.stderr
@@ -1,19 +1,27 @@
error: used `unwrap()` on `Some` value
- --> $DIR/unnecessary_literal_unwrap.rs:4:15
+ --> $DIR/unnecessary_literal_unwrap.rs:5:15
|
LL | let val = Some(1).unwrap();
| ^^^^^^^^^^^^^^^^
|
- = help:
= note: `-D clippy::unnecessary-literal-unwrap` implied by `-D warnings`
+help: remove the `Some` and `unwrap()`
+ |
+LL - let val = Some(1).unwrap();
+LL + let val = 1;
+ |
error: used `expect()` on `Some` value
- --> $DIR/unnecessary_literal_unwrap.rs:5:15
+ --> $DIR/unnecessary_literal_unwrap.rs:6:15
|
LL | let val = Some(1).expect("this never happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = help:
+help: remove the `Some` and `expect()`
+ |
+LL - let val = Some(1).expect("this never happens");
+LL + let val = 1;
+ |
error: aborting due to 2 previous errors
From 1d159e7d11d86d030c030ec0ec23a88871289d1b Mon Sep 17 00:00:00 2001
From: rsdy
Date: Thu, 16 Feb 2023 14:37:18 +0000
Subject: [PATCH 08/16] Recognize `Ok`
---
.../src/methods/unnecessary_literal_unwrap.rs | 8 ++--
tests/ui/unnecessary_literal_unwrap.fixed | 11 ++++-
tests/ui/unnecessary_literal_unwrap.rs | 11 ++++-
tests/ui/unnecessary_literal_unwrap.stderr | 46 ++++++++++++++-----
4 files changed, 58 insertions(+), 18 deletions(-)
diff --git a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
index 9a82d7e58ea6..0c8a70fedb9c 100644
--- a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
+++ b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
@@ -7,15 +7,17 @@ use super::UNNECESSARY_LITERAL_UNWRAP;
pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>, arg: &hir::Expr<'_>, name: &str) {
let mess = if is_res_lang_ctor(cx, path_res(cx, recv), hir::LangItem::OptionSome) {
- Some((UNNECESSARY_LITERAL_UNWRAP, "Some"))
+ Some("Some")
+ } else if is_res_lang_ctor(cx, path_res(cx, recv), hir::LangItem::ResultOk) {
+ Some("Ok")
} else {
None
};
- if let Some((lint, constructor)) = mess {
+ if let Some(constructor) = mess {
span_lint_and_then(
cx,
- lint,
+ UNNECESSARY_LITERAL_UNWRAP,
expr.span,
&format!("used `{name}()` on `{constructor}` value"),
|diag| {
diff --git a/tests/ui/unnecessary_literal_unwrap.fixed b/tests/ui/unnecessary_literal_unwrap.fixed
index 8696048d3324..b59dec7d48a5 100644
--- a/tests/ui/unnecessary_literal_unwrap.fixed
+++ b/tests/ui/unnecessary_literal_unwrap.fixed
@@ -2,10 +2,17 @@
#![warn(clippy::unnecessary_literal_unwrap)]
fn unwrap_option() {
- let val = 1;
- let val = 1;
+ let _val = 1;
+ let _val = 1;
+}
+
+fn unwrap_result() {
+ let _val = 1;
+ let _val = 1;
+ // let val = Err(1).unwrap_err();
}
fn main() {
unwrap_option();
+ unwrap_result();
}
diff --git a/tests/ui/unnecessary_literal_unwrap.rs b/tests/ui/unnecessary_literal_unwrap.rs
index ae41634495b3..c46204f7a99e 100644
--- a/tests/ui/unnecessary_literal_unwrap.rs
+++ b/tests/ui/unnecessary_literal_unwrap.rs
@@ -2,10 +2,17 @@
#![warn(clippy::unnecessary_literal_unwrap)]
fn unwrap_option() {
- let val = Some(1).unwrap();
- let val = Some(1).expect("this never happens");
+ let _val = Some(1).unwrap();
+ let _val = Some(1).expect("this never happens");
+}
+
+fn unwrap_result() {
+ let _val = Ok::(1).unwrap();
+ let _val = Ok::(1).expect("this never happens");
+ // let val = Err(1).unwrap_err();
}
fn main() {
unwrap_option();
+ unwrap_result();
}
diff --git a/tests/ui/unnecessary_literal_unwrap.stderr b/tests/ui/unnecessary_literal_unwrap.stderr
index 00d7f186fc41..c5e3cd1657be 100644
--- a/tests/ui/unnecessary_literal_unwrap.stderr
+++ b/tests/ui/unnecessary_literal_unwrap.stderr
@@ -1,27 +1,51 @@
error: used `unwrap()` on `Some` value
- --> $DIR/unnecessary_literal_unwrap.rs:5:15
+ --> $DIR/unnecessary_literal_unwrap.rs:5:16
|
-LL | let val = Some(1).unwrap();
- | ^^^^^^^^^^^^^^^^
+LL | let _val = Some(1).unwrap();
+ | ^^^^^^^^^^^^^^^^
|
= note: `-D clippy::unnecessary-literal-unwrap` implied by `-D warnings`
help: remove the `Some` and `unwrap()`
|
-LL - let val = Some(1).unwrap();
-LL + let val = 1;
+LL - let _val = Some(1).unwrap();
+LL + let _val = 1;
|
error: used `expect()` on `Some` value
- --> $DIR/unnecessary_literal_unwrap.rs:6:15
+ --> $DIR/unnecessary_literal_unwrap.rs:6:16
|
-LL | let val = Some(1).expect("this never happens");
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | let _val = Some(1).expect("this never happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Some` and `expect()`
|
-LL - let val = Some(1).expect("this never happens");
-LL + let val = 1;
+LL - let _val = Some(1).expect("this never happens");
+LL + let _val = 1;
|
-error: aborting due to 2 previous errors
+error: used `unwrap()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap.rs:10:16
+ |
+LL | let _val = Ok::(1).unwrap();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap()`
+ |
+LL - let _val = Ok::(1).unwrap();
+LL + let _val = 1;
+ |
+
+error: used `expect()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap.rs:11:16
+ |
+LL | let _val = Ok::(1).expect("this never happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `expect()`
+ |
+LL - let _val = Ok::(1).expect("this never happens");
+LL + let _val = 1;
+ |
+
+error: aborting due to 4 previous errors
From 8f83502989f8723377082c52c3aa5c086d5fd3f2 Mon Sep 17 00:00:00 2001
From: Pavan Kumar Sunkara
Date: Thu, 16 Feb 2023 14:43:41 +0000
Subject: [PATCH 09/16] Recognize `unwrap_or` methods
---
clippy_lints/src/methods/mod.rs | 36 +++++++------
.../src/methods/unnecessary_literal_unwrap.rs | 54 ++++++++++---------
tests/ui/unnecessary_literal_unwrap.fixed | 12 +++++
tests/ui/unnecessary_literal_unwrap.rs | 12 +++++
tests/ui/unnecessary_literal_unwrap.stderr | 50 ++++++++++++++++-
5 files changed, 120 insertions(+), 44 deletions(-)
diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs
index a5c55a42ea55..5e42123a8dad 100644
--- a/clippy_lints/src/methods/mod.rs
+++ b/clippy_lints/src/methods/mod.rs
@@ -3664,9 +3664,7 @@ impl Methods {
Some(("err", recv, [], err_span, _)) => err_expect::check(cx, expr, recv, span, err_span, &self.msrv),
_ => expect_used::check(cx, expr, recv, false, self.allow_expect_in_tests),
}
- if let ExprKind::Call(recv, [arg]) = recv.kind {
- unnecessary_literal_unwrap::check(cx, expr, recv, arg, name);
- }
+ unnecessary_literal_unwrap::check(cx, expr, recv, name);
},
("expect_err", [_]) => expect_used::check(cx, expr, recv, true, self.allow_expect_in_tests),
("extend", [arg]) => {
@@ -3873,24 +3871,28 @@ impl Methods {
},
_ => {},
}
- if let ExprKind::Call(recv, [arg]) = recv.kind {
- unnecessary_literal_unwrap::check(cx, expr, recv, arg, name);
- }
+ unnecessary_literal_unwrap::check(cx, expr, recv, name);
unwrap_used::check(cx, expr, recv, false, self.allow_unwrap_in_tests);
},
("unwrap_err", []) => unwrap_used::check(cx, expr, recv, true, self.allow_unwrap_in_tests),
- ("unwrap_or", [u_arg]) => match method_call(recv) {
- Some((arith @ ("checked_add" | "checked_sub" | "checked_mul"), lhs, [rhs], _, _)) => {
- manual_saturating_arithmetic::check(cx, expr, lhs, rhs, u_arg, &arith["checked_".len()..]);
- },
- Some(("map", m_recv, [m_arg], span, _)) => {
- option_map_unwrap_or::check(cx, expr, m_recv, m_arg, recv, u_arg, span);
- },
- Some(("then_some", t_recv, [t_arg], _, _)) => {
- obfuscated_if_else::check(cx, expr, t_recv, t_arg, u_arg);
- },
- _ => {},
+ ("unwrap_or", [u_arg]) => {
+ match method_call(recv) {
+ Some((arith @ ("checked_add" | "checked_sub" | "checked_mul"), lhs, [rhs], _, _)) => {
+ manual_saturating_arithmetic::check(cx, expr, lhs, rhs, u_arg, &arith["checked_".len()..]);
+ },
+ Some(("map", m_recv, [m_arg], span, _)) => {
+ option_map_unwrap_or::check(cx, expr, m_recv, m_arg, recv, u_arg, span);
+ },
+ Some(("then_some", t_recv, [t_arg], _, _)) => {
+ obfuscated_if_else::check(cx, expr, t_recv, t_arg, u_arg);
+ },
+ _ => {},
+ }
+ unnecessary_literal_unwrap::check(cx, expr, recv, name);
},
+ ("unwrap_or_default", []) => {
+ unnecessary_literal_unwrap::check(cx, expr, recv, name);
+ }
("unwrap_or_else", [u_arg]) => match method_call(recv) {
Some(("map", recv, [map_arg], _, _))
if map_unwrap_or::check(cx, expr, recv, map_arg, u_arg, &self.msrv) => {},
diff --git a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
index 0c8a70fedb9c..9a9c659b2325 100644
--- a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
+++ b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
@@ -5,33 +5,35 @@ use rustc_lint::LateContext;
use super::UNNECESSARY_LITERAL_UNWRAP;
-pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>, arg: &hir::Expr<'_>, name: &str) {
- let mess = if is_res_lang_ctor(cx, path_res(cx, recv), hir::LangItem::OptionSome) {
- Some("Some")
- } else if is_res_lang_ctor(cx, path_res(cx, recv), hir::LangItem::ResultOk) {
- Some("Ok")
- } else {
- None
- };
+pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>, name: &str) {
+ if let hir::ExprKind::Call(call, [arg]) = recv.kind {
+ let mess = if is_res_lang_ctor(cx, path_res(cx, call), hir::LangItem::OptionSome) {
+ Some("Some")
+ } else if is_res_lang_ctor(cx, path_res(cx, call), hir::LangItem::ResultOk) {
+ Some("Ok")
+ } else {
+ None
+ };
- if let Some(constructor) = mess {
- span_lint_and_then(
- cx,
- UNNECESSARY_LITERAL_UNWRAP,
- expr.span,
- &format!("used `{name}()` on `{constructor}` value"),
- |diag| {
- let suggestions = vec![
- (recv.span.with_hi(arg.span.lo()), String::new()),
- (expr.span.with_lo(arg.span.hi()), String::new()),
- ];
+ if let Some(constructor) = mess {
+ span_lint_and_then(
+ cx,
+ UNNECESSARY_LITERAL_UNWRAP,
+ expr.span,
+ &format!("used `{name}()` on `{constructor}` value"),
+ |diag| {
+ let suggestions = vec![
+ (call.span.with_hi(arg.span.lo()), String::new()),
+ (expr.span.with_lo(arg.span.hi()), String::new()),
+ ];
- diag.multipart_suggestion(
- format!("remove the `{constructor}` and `{name}()`"),
- suggestions,
- Applicability::MachineApplicable,
- );
- },
- );
+ diag.multipart_suggestion(
+ format!("remove the `{constructor}` and `{name}()`"),
+ suggestions,
+ Applicability::MachineApplicable,
+ );
+ },
+ );
+ }
}
}
diff --git a/tests/ui/unnecessary_literal_unwrap.fixed b/tests/ui/unnecessary_literal_unwrap.fixed
index b59dec7d48a5..55a210bdb985 100644
--- a/tests/ui/unnecessary_literal_unwrap.fixed
+++ b/tests/ui/unnecessary_literal_unwrap.fixed
@@ -12,7 +12,19 @@ fn unwrap_result() {
// let val = Err(1).unwrap_err();
}
+fn unwrap_methods_option() {
+ let _val = 1;
+ let _val = 1;
+}
+
+fn unwrap_methods_result() {
+ let _val = 1;
+ let _val = 1;
+}
+
fn main() {
unwrap_option();
unwrap_result();
+ unwrap_methods_option();
+ unwrap_methods_result();
}
diff --git a/tests/ui/unnecessary_literal_unwrap.rs b/tests/ui/unnecessary_literal_unwrap.rs
index c46204f7a99e..80f72ce3cf29 100644
--- a/tests/ui/unnecessary_literal_unwrap.rs
+++ b/tests/ui/unnecessary_literal_unwrap.rs
@@ -12,7 +12,19 @@ fn unwrap_result() {
// let val = Err(1).unwrap_err();
}
+fn unwrap_methods_option() {
+ let _val = Some(1).unwrap_or(2);
+ let _val = Some(1).unwrap_or_default();
+}
+
+fn unwrap_methods_result() {
+ let _val = Ok::(1).unwrap_or(2);
+ let _val = Ok::(1).unwrap_or_default();
+}
+
fn main() {
unwrap_option();
unwrap_result();
+ unwrap_methods_option();
+ unwrap_methods_result();
}
diff --git a/tests/ui/unnecessary_literal_unwrap.stderr b/tests/ui/unnecessary_literal_unwrap.stderr
index c5e3cd1657be..b8b5a612da13 100644
--- a/tests/ui/unnecessary_literal_unwrap.stderr
+++ b/tests/ui/unnecessary_literal_unwrap.stderr
@@ -47,5 +47,53 @@ LL - let _val = Ok::(1).expect("this never happens");
LL + let _val = 1;
|
-error: aborting due to 4 previous errors
+error: used `unwrap_or()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap.rs:16:16
+ |
+LL | let _val = Some(1).unwrap_or(2);
+ | ^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Some` and `unwrap_or()`
+ |
+LL - let _val = Some(1).unwrap_or(2);
+LL + let _val = 1;
+ |
+
+error: used `unwrap_or_default()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap.rs:17:16
+ |
+LL | let _val = Some(1).unwrap_or_default();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Some` and `unwrap_or_default()`
+ |
+LL - let _val = Some(1).unwrap_or_default();
+LL + let _val = 1;
+ |
+
+error: used `unwrap_or()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap.rs:21:16
+ |
+LL | let _val = Ok::(1).unwrap_or(2);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap_or()`
+ |
+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:22:16
+ |
+LL | let _val = Ok::(1).unwrap_or_default();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap_or_default()`
+ |
+LL - let _val = Ok::(1).unwrap_or_default();
+LL + let _val = 1;
+ |
+
+error: aborting due to 8 previous errors
From 7ed7283e0f9de697f8d5c8c2118c4b0b8bc7d6b0 Mon Sep 17 00:00:00 2001
From: Pavan Kumar Sunkara
Date: Thu, 16 Feb 2023 15:05:56 +0000
Subject: [PATCH 10/16] Recognize `unwrap_or_else` method
---
CHANGELOG.md | 1 +
clippy_lints/src/methods/mod.rs | 17 +++++----
tests/ui/unnecessary_literal_unwrap.fixed | 3 ++
tests/ui/unnecessary_literal_unwrap.rs | 3 ++
tests/ui/unnecessary_literal_unwrap.stderr | 42 +++++++++++++++++-----
5 files changed, 50 insertions(+), 16 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 85fddc970473..abc35e8546f8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5248,6 +5248,7 @@ Released 2018-09-13
[`unnecessary_fold`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_fold
[`unnecessary_join`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_join
[`unnecessary_lazy_evaluations`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations
+[`unnecessary_literal_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_literal_unwrap
[`unnecessary_mut_passed`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_mut_passed
[`unnecessary_operation`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_operation
[`unnecessary_owned_empty_strings`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_owned_empty_strings
diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs
index 5e42123a8dad..4686adda6834 100644
--- a/clippy_lints/src/methods/mod.rs
+++ b/clippy_lints/src/methods/mod.rs
@@ -3893,13 +3893,16 @@ impl Methods {
("unwrap_or_default", []) => {
unnecessary_literal_unwrap::check(cx, expr, recv, name);
}
- ("unwrap_or_else", [u_arg]) => match method_call(recv) {
- Some(("map", recv, [map_arg], _, _))
- if map_unwrap_or::check(cx, expr, recv, map_arg, u_arg, &self.msrv) => {},
- _ => {
- unwrap_or_else_default::check(cx, expr, recv, u_arg);
- unnecessary_lazy_eval::check(cx, expr, recv, u_arg, "unwrap_or");
- },
+ ("unwrap_or_else", [u_arg]) => {
+ match method_call(recv) {
+ Some(("map", recv, [map_arg], _, _))
+ if map_unwrap_or::check(cx, expr, recv, map_arg, u_arg, &self.msrv) => {},
+ _ => {
+ unwrap_or_else_default::check(cx, expr, recv, u_arg);
+ unnecessary_lazy_eval::check(cx, expr, recv, u_arg, "unwrap_or");
+ },
+ }
+ unnecessary_literal_unwrap::check(cx, expr, recv, name);
},
("zip", [arg]) => {
if let ExprKind::MethodCall(name, iter_recv, [], _) = recv.kind
diff --git a/tests/ui/unnecessary_literal_unwrap.fixed b/tests/ui/unnecessary_literal_unwrap.fixed
index 55a210bdb985..a388a7f83d2d 100644
--- a/tests/ui/unnecessary_literal_unwrap.fixed
+++ b/tests/ui/unnecessary_literal_unwrap.fixed
@@ -1,5 +1,6 @@
//run-rustfix
#![warn(clippy::unnecessary_literal_unwrap)]
+#![allow(clippy::unnecessary_lazy_evaluations)]
fn unwrap_option() {
let _val = 1;
@@ -15,11 +16,13 @@ fn unwrap_result() {
fn unwrap_methods_option() {
let _val = 1;
let _val = 1;
+ let _val = 1;
}
fn unwrap_methods_result() {
let _val = 1;
let _val = 1;
+ let _val = 1;
}
fn main() {
diff --git a/tests/ui/unnecessary_literal_unwrap.rs b/tests/ui/unnecessary_literal_unwrap.rs
index 80f72ce3cf29..fe557957dd9f 100644
--- a/tests/ui/unnecessary_literal_unwrap.rs
+++ b/tests/ui/unnecessary_literal_unwrap.rs
@@ -1,5 +1,6 @@
//run-rustfix
#![warn(clippy::unnecessary_literal_unwrap)]
+#![allow(clippy::unnecessary_lazy_evaluations)]
fn unwrap_option() {
let _val = Some(1).unwrap();
@@ -15,11 +16,13 @@ fn unwrap_result() {
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(|| _val);
}
fn unwrap_methods_result() {
let _val = Ok::(1).unwrap_or(2);
let _val = Ok::(1).unwrap_or_default();
+ let _val = Ok::(1).unwrap_or_else(|()| _val);
}
fn main() {
diff --git a/tests/ui/unnecessary_literal_unwrap.stderr b/tests/ui/unnecessary_literal_unwrap.stderr
index b8b5a612da13..60499fe700bc 100644
--- a/tests/ui/unnecessary_literal_unwrap.stderr
+++ b/tests/ui/unnecessary_literal_unwrap.stderr
@@ -1,5 +1,5 @@
error: used `unwrap()` on `Some` value
- --> $DIR/unnecessary_literal_unwrap.rs:5:16
+ --> $DIR/unnecessary_literal_unwrap.rs:6: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:6:16
+ --> $DIR/unnecessary_literal_unwrap.rs:7:16
|
LL | let _val = Some(1).expect("this never happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -24,7 +24,7 @@ LL + let _val = 1;
|
error: used `unwrap()` on `Ok` value
- --> $DIR/unnecessary_literal_unwrap.rs:10:16
+ --> $DIR/unnecessary_literal_unwrap.rs:11:16
|
LL | let _val = Ok::(1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -36,7 +36,7 @@ LL + let _val = 1;
|
error: used `expect()` on `Ok` value
- --> $DIR/unnecessary_literal_unwrap.rs:11:16
+ --> $DIR/unnecessary_literal_unwrap.rs:12:16
|
LL | let _val = Ok::(1).expect("this never happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -48,7 +48,7 @@ LL + let _val = 1;
|
error: used `unwrap_or()` on `Some` value
- --> $DIR/unnecessary_literal_unwrap.rs:16:16
+ --> $DIR/unnecessary_literal_unwrap.rs:17:16
|
LL | let _val = Some(1).unwrap_or(2);
| ^^^^^^^^^^^^^^^^^^^^
@@ -60,7 +60,7 @@ LL + let _val = 1;
|
error: used `unwrap_or_default()` on `Some` value
- --> $DIR/unnecessary_literal_unwrap.rs:17:16
+ --> $DIR/unnecessary_literal_unwrap.rs:18:16
|
LL | let _val = Some(1).unwrap_or_default();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -71,8 +71,20 @@ LL - let _val = Some(1).unwrap_or_default();
LL + let _val = 1;
|
+error: used `unwrap_or_else()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap.rs:19:16
+ |
+LL | let _val = Some(1).unwrap_or_else(|| _val);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Some` and `unwrap_or_else()`
+ |
+LL - let _val = Some(1).unwrap_or_else(|| _val);
+LL + let _val = 1;
+ |
+
error: used `unwrap_or()` on `Ok` value
- --> $DIR/unnecessary_literal_unwrap.rs:21:16
+ --> $DIR/unnecessary_literal_unwrap.rs:23:16
|
LL | let _val = Ok::(1).unwrap_or(2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -84,7 +96,7 @@ LL + let _val = 1;
|
error: used `unwrap_or_default()` on `Ok` value
- --> $DIR/unnecessary_literal_unwrap.rs:22:16
+ --> $DIR/unnecessary_literal_unwrap.rs:24:16
|
LL | let _val = Ok::(1).unwrap_or_default();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -95,5 +107,17 @@ LL - let _val = Ok::(1).unwrap_or_default();
LL + let _val = 1;
|
-error: aborting due to 8 previous errors
+error: used `unwrap_or_else()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap.rs:25:16
+ |
+LL | let _val = Ok::(1).unwrap_or_else(|()| _val);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap_or_else()`
+ |
+LL - let _val = Ok::(1).unwrap_or_else(|()| _val);
+LL + let _val = 1;
+ |
+
+error: aborting due to 10 previous errors
From 6e0e09c8f7622caa6ea6536f2bbc5c033a9cffa2 Mon Sep 17 00:00:00 2001
From: rsdy
Date: Thu, 16 Feb 2023 15:30:09 +0000
Subject: [PATCH 11/16] Track init and unwrap of expr
---
.../src/methods/unnecessary_literal_unwrap.rs | 22 ++++++++++++++++---
.../unnecessary_literal_unwrap_unfixable.rs | 6 +++++
...nnecessary_literal_unwrap_unfixable.stderr | 15 +++++++++++++
3 files changed, 40 insertions(+), 3 deletions(-)
create mode 100644 tests/ui/unnecessary_literal_unwrap_unfixable.rs
create mode 100644 tests/ui/unnecessary_literal_unwrap_unfixable.stderr
diff --git a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
index 9a9c659b2325..54160a27cb29 100644
--- a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
+++ b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
@@ -6,7 +6,9 @@ use rustc_lint::LateContext;
use super::UNNECESSARY_LITERAL_UNWRAP;
pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>, name: &str) {
- if let hir::ExprKind::Call(call, [arg]) = recv.kind {
+ let init = clippy_utils::expr_or_init(cx, recv);
+
+ if let hir::ExprKind::Call(call, [arg]) = init.kind {
let mess = if is_res_lang_ctor(cx, path_res(cx, call), hir::LangItem::OptionSome) {
Some("Some")
} else if is_res_lang_ctor(cx, path_res(cx, call), hir::LangItem::ResultOk) {
@@ -15,7 +17,11 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr
None
};
- if let Some(constructor) = mess {
+ let Some(constructor) = mess else {
+ return;
+ };
+
+ if init.span == recv.span {
span_lint_and_then(
cx,
UNNECESSARY_LITERAL_UNWRAP,
@@ -23,7 +29,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr
&format!("used `{name}()` on `{constructor}` value"),
|diag| {
let suggestions = vec![
- (call.span.with_hi(arg.span.lo()), String::new()),
+ (recv.span.with_hi(arg.span.lo()), String::new()),
(expr.span.with_lo(arg.span.hi()), String::new()),
];
@@ -34,6 +40,16 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr
);
},
);
+ } else {
+ span_lint_and_then(
+ cx,
+ UNNECESSARY_LITERAL_UNWRAP,
+ expr.span,
+ &format!("used `{name}()` on `{constructor}` value"),
+ |diag| {
+ diag.span_help(init.span, format!("remove the `{constructor}` and `{name}()`"));
+ },
+ );
}
}
}
diff --git a/tests/ui/unnecessary_literal_unwrap_unfixable.rs b/tests/ui/unnecessary_literal_unwrap_unfixable.rs
new file mode 100644
index 000000000000..ac3a84934afe
--- /dev/null
+++ b/tests/ui/unnecessary_literal_unwrap_unfixable.rs
@@ -0,0 +1,6 @@
+#![warn(clippy::unnecessary_literal_unwrap)]
+
+fn main() {
+ let val = Some(1);
+ let _val2 = val.unwrap();
+}
diff --git a/tests/ui/unnecessary_literal_unwrap_unfixable.stderr b/tests/ui/unnecessary_literal_unwrap_unfixable.stderr
new file mode 100644
index 000000000000..abc789ccda4b
--- /dev/null
+++ b/tests/ui/unnecessary_literal_unwrap_unfixable.stderr
@@ -0,0 +1,15 @@
+error: used `unwrap()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:5:17
+ |
+LL | let _val2 = val.unwrap();
+ | ^^^^^^^^^^^^
+ |
+help: remove the `Some` and `unwrap()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:4:15
+ |
+LL | let val = Some(1);
+ | ^^^^^^^
+ = note: `-D clippy::unnecessary-literal-unwrap` implied by `-D warnings`
+
+error: aborting due to previous error
+
From 69af0e13b2662807ba51ffc3a9fe4a9576e100e2 Mon Sep 17 00:00:00 2001
From: Pavan Kumar Sunkara
Date: Thu, 16 Feb 2023 17:15:19 +0000
Subject: [PATCH 12/16] Recognize `Err`
---
clippy_lints/src/methods/mod.rs | 10 ++++-
.../src/methods/unnecessary_literal_unwrap.rs | 14 +++----
tests/ui/unnecessary_literal_unwrap.fixed | 11 ++++--
tests/ui/unnecessary_literal_unwrap.rs | 11 ++++--
tests/ui/unnecessary_literal_unwrap.stderr | 38 +++++++++++++++----
5 files changed, 61 insertions(+), 23 deletions(-)
diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs
index 4686adda6834..66789e6137a9 100644
--- a/clippy_lints/src/methods/mod.rs
+++ b/clippy_lints/src/methods/mod.rs
@@ -3666,7 +3666,10 @@ impl Methods {
}
unnecessary_literal_unwrap::check(cx, expr, recv, name);
},
- ("expect_err", [_]) => expect_used::check(cx, expr, recv, true, self.allow_expect_in_tests),
+ ("expect_err", [_]) => {
+ unnecessary_literal_unwrap::check(cx, expr, recv, name);
+ expect_used::check(cx, expr, recv, true, self.allow_expect_in_tests);
+ },
("extend", [arg]) => {
string_extend_chars::check(cx, expr, recv, arg);
extend_with_drain::check(cx, expr, recv, arg);
@@ -3874,7 +3877,10 @@ impl Methods {
unnecessary_literal_unwrap::check(cx, expr, recv, name);
unwrap_used::check(cx, expr, recv, false, self.allow_unwrap_in_tests);
},
- ("unwrap_err", []) => unwrap_used::check(cx, expr, recv, true, self.allow_unwrap_in_tests),
+ ("unwrap_err", []) => {
+ unnecessary_literal_unwrap::check(cx, expr, recv, name);
+ unwrap_used::check(cx, expr, recv, true, self.allow_unwrap_in_tests)
+ },
("unwrap_or", [u_arg]) => {
match method_call(recv) {
Some((arith @ ("checked_add" | "checked_sub" | "checked_mul"), lhs, [rhs], _, _)) => {
diff --git a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
index 54160a27cb29..56d3c16a5d27 100644
--- a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
+++ b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
@@ -9,18 +9,16 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr
let init = clippy_utils::expr_or_init(cx, recv);
if let hir::ExprKind::Call(call, [arg]) = init.kind {
- let mess = if is_res_lang_ctor(cx, path_res(cx, call), hir::LangItem::OptionSome) {
- Some("Some")
+ let constructor = if is_res_lang_ctor(cx, path_res(cx, call), hir::LangItem::OptionSome) {
+ "Some"
} else if is_res_lang_ctor(cx, path_res(cx, call), hir::LangItem::ResultOk) {
- Some("Ok")
+ "Ok"
+ } else if is_res_lang_ctor(cx, path_res(cx, call), hir::LangItem::ResultErr) {
+ "Err"
} else {
- None
+ return;
};
- let Some(constructor) = mess else {
- return;
- };
-
if init.span == recv.span {
span_lint_and_then(
cx,
diff --git a/tests/ui/unnecessary_literal_unwrap.fixed b/tests/ui/unnecessary_literal_unwrap.fixed
index a388a7f83d2d..9733993d6191 100644
--- a/tests/ui/unnecessary_literal_unwrap.fixed
+++ b/tests/ui/unnecessary_literal_unwrap.fixed
@@ -7,10 +7,14 @@ fn unwrap_option() {
let _val = 1;
}
-fn unwrap_result() {
+fn unwrap_result_ok() {
+ let _val = 1;
+ let _val = 1;
+}
+
+fn unwrap_result_err() {
let _val = 1;
let _val = 1;
- // let val = Err(1).unwrap_err();
}
fn unwrap_methods_option() {
@@ -27,7 +31,8 @@ fn unwrap_methods_result() {
fn main() {
unwrap_option();
- unwrap_result();
+ unwrap_result_ok();
+ unwrap_result_err();
unwrap_methods_option();
unwrap_methods_result();
}
diff --git a/tests/ui/unnecessary_literal_unwrap.rs b/tests/ui/unnecessary_literal_unwrap.rs
index fe557957dd9f..775d744c13e7 100644
--- a/tests/ui/unnecessary_literal_unwrap.rs
+++ b/tests/ui/unnecessary_literal_unwrap.rs
@@ -7,10 +7,14 @@ fn unwrap_option() {
let _val = Some(1).expect("this never happens");
}
-fn unwrap_result() {
+fn unwrap_result_ok() {
let _val = Ok::(1).unwrap();
let _val = Ok::(1).expect("this never happens");
- // let val = Err(1).unwrap_err();
+}
+
+fn unwrap_result_err() {
+ let _val = Err::<(), usize>(1).unwrap_err();
+ let _val = Err::<(), usize>(1).expect_err("this never happens");
}
fn unwrap_methods_option() {
@@ -27,7 +31,8 @@ fn unwrap_methods_result() {
fn main() {
unwrap_option();
- unwrap_result();
+ unwrap_result_ok();
+ unwrap_result_err();
unwrap_methods_option();
unwrap_methods_result();
}
diff --git a/tests/ui/unnecessary_literal_unwrap.stderr b/tests/ui/unnecessary_literal_unwrap.stderr
index 60499fe700bc..622743f8c855 100644
--- a/tests/ui/unnecessary_literal_unwrap.stderr
+++ b/tests/ui/unnecessary_literal_unwrap.stderr
@@ -47,9 +47,33 @@ LL - let _val = Ok::(1).expect("this never happens");
LL + let _val = 1;
|
-error: used `unwrap_or()` on `Some` value
+error: used `unwrap_err()` on `Err` value
+ --> $DIR/unnecessary_literal_unwrap.rs:16:16
+ |
+LL | let _val = Err::<(), usize>(1).unwrap_err();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Err` and `unwrap_err()`
+ |
+LL - let _val = Err::<(), usize>(1).unwrap_err();
+LL + let _val = 1;
+ |
+
+error: used `expect_err()` on `Err` value
--> $DIR/unnecessary_literal_unwrap.rs:17:16
|
+LL | let _val = Err::<(), usize>(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 = 1;
+ |
+
+error: used `unwrap_or()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap.rs:21:16
+ |
LL | let _val = Some(1).unwrap_or(2);
| ^^^^^^^^^^^^^^^^^^^^
|
@@ -60,7 +84,7 @@ LL + let _val = 1;
|
error: used `unwrap_or_default()` on `Some` value
- --> $DIR/unnecessary_literal_unwrap.rs:18:16
+ --> $DIR/unnecessary_literal_unwrap.rs:22:16
|
LL | let _val = Some(1).unwrap_or_default();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -72,7 +96,7 @@ LL + let _val = 1;
|
error: used `unwrap_or_else()` on `Some` value
- --> $DIR/unnecessary_literal_unwrap.rs:19:16
+ --> $DIR/unnecessary_literal_unwrap.rs:23:16
|
LL | let _val = Some(1).unwrap_or_else(|| _val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -84,7 +108,7 @@ LL + let _val = 1;
|
error: used `unwrap_or()` on `Ok` value
- --> $DIR/unnecessary_literal_unwrap.rs:23:16
+ --> $DIR/unnecessary_literal_unwrap.rs:27:16
|
LL | let _val = Ok::(1).unwrap_or(2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -96,7 +120,7 @@ LL + let _val = 1;
|
error: used `unwrap_or_default()` on `Ok` value
- --> $DIR/unnecessary_literal_unwrap.rs:24:16
+ --> $DIR/unnecessary_literal_unwrap.rs:28:16
|
LL | let _val = Ok::(1).unwrap_or_default();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -108,7 +132,7 @@ LL + let _val = 1;
|
error: used `unwrap_or_else()` on `Ok` value
- --> $DIR/unnecessary_literal_unwrap.rs:25:16
+ --> $DIR/unnecessary_literal_unwrap.rs:29:16
|
LL | let _val = Ok::(1).unwrap_or_else(|()| _val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -119,5 +143,5 @@ LL - let _val = Ok::(1).unwrap_or_else(|()| _val);
LL + let _val = 1;
|
-error: aborting due to 10 previous errors
+error: aborting due to 12 previous errors
From 6e4dc93e24866018f2567a7a0baa1955a4c7d868 Mon Sep 17 00:00:00 2001
From: Pavan Kumar Sunkara
Date: Thu, 16 Feb 2023 22:31:52 +0000
Subject: [PATCH 13/16] Support suggesting panics
---
clippy_lints/src/methods/mod.rs | 16 ++--
.../src/methods/unnecessary_literal_unwrap.rs | 91 +++++++++++--------
tests/ui/unnecessary_literal_unwrap.fixed | 15 ++-
tests/ui/unnecessary_literal_unwrap.rs | 15 ++-
tests/ui/unnecessary_literal_unwrap.stderr | 87 +++++++++++++++---
5 files changed, 163 insertions(+), 61 deletions(-)
diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs
index 66789e6137a9..912cce39e2ea 100644
--- a/clippy_lints/src/methods/mod.rs
+++ b/clippy_lints/src/methods/mod.rs
@@ -3664,10 +3664,10 @@ impl Methods {
Some(("err", recv, [], err_span, _)) => err_expect::check(cx, expr, recv, span, err_span, &self.msrv),
_ => expect_used::check(cx, expr, recv, false, self.allow_expect_in_tests),
}
- unnecessary_literal_unwrap::check(cx, expr, recv, name);
+ unnecessary_literal_unwrap::check(cx, expr, recv, name, args);
},
("expect_err", [_]) => {
- unnecessary_literal_unwrap::check(cx, expr, recv, name);
+ unnecessary_literal_unwrap::check(cx, expr, recv, name, args);
expect_used::check(cx, expr, recv, true, self.allow_expect_in_tests);
},
("extend", [arg]) => {
@@ -3874,12 +3874,12 @@ impl Methods {
},
_ => {},
}
- unnecessary_literal_unwrap::check(cx, expr, recv, name);
+ unnecessary_literal_unwrap::check(cx, expr, recv, name, args);
unwrap_used::check(cx, expr, recv, false, self.allow_unwrap_in_tests);
},
("unwrap_err", []) => {
- unnecessary_literal_unwrap::check(cx, expr, recv, name);
- unwrap_used::check(cx, expr, recv, true, self.allow_unwrap_in_tests)
+ unnecessary_literal_unwrap::check(cx, expr, recv, name, args);
+ unwrap_used::check(cx, expr, recv, true, self.allow_unwrap_in_tests);
},
("unwrap_or", [u_arg]) => {
match method_call(recv) {
@@ -3894,10 +3894,10 @@ impl Methods {
},
_ => {},
}
- unnecessary_literal_unwrap::check(cx, expr, recv, name);
+ unnecessary_literal_unwrap::check(cx, expr, recv, name, args);
},
("unwrap_or_default", []) => {
- unnecessary_literal_unwrap::check(cx, expr, recv, name);
+ unnecessary_literal_unwrap::check(cx, expr, recv, name, args);
}
("unwrap_or_else", [u_arg]) => {
match method_call(recv) {
@@ -3908,7 +3908,7 @@ impl Methods {
unnecessary_lazy_eval::check(cx, expr, recv, u_arg, "unwrap_or");
},
}
- unnecessary_literal_unwrap::check(cx, expr, recv, name);
+ unnecessary_literal_unwrap::check(cx, expr, recv, name, args);
},
("zip", [arg]) => {
if let ExprKind::MethodCall(name, iter_recv, [], _) = recv.kind
diff --git a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
index 56d3c16a5d27..fe6b86b34f5e 100644
--- a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
+++ b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
@@ -5,49 +5,68 @@ use rustc_lint::LateContext;
use super::UNNECESSARY_LITERAL_UNWRAP;
-pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>, name: &str) {
+pub(super) fn check(
+ cx: &LateContext<'_>,
+ expr: &hir::Expr<'_>,
+ recv: &hir::Expr<'_>,
+ method: &str,
+ args: &[hir::Expr<'_>],
+) {
let init = clippy_utils::expr_or_init(cx, recv);
- if let hir::ExprKind::Call(call, [arg]) = init.kind {
- let constructor = if is_res_lang_ctor(cx, path_res(cx, call), hir::LangItem::OptionSome) {
- "Some"
+ 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"
+ ("Ok", call_args)
} else if is_res_lang_ctor(cx, path_res(cx, call), hir::LangItem::ResultErr) {
- "Err"
+ ("Err", call_args)
} else {
return;
- };
+ }
+ } else if is_res_lang_ctor(cx, path_res(cx, init), hir::LangItem::OptionNone) {
+ let call_args: &[hir::Expr<'_>] = &[];
+ ("None", call_args)
+ } else {
+ return;
+ };
- if init.span == recv.span {
- span_lint_and_then(
- cx,
- UNNECESSARY_LITERAL_UNWRAP,
- expr.span,
- &format!("used `{name}()` on `{constructor}` value"),
- |diag| {
- let suggestions = vec![
- (recv.span.with_hi(arg.span.lo()), String::new()),
- (expr.span.with_lo(arg.span.hi()), String::new()),
- ];
+ let help_message = format!("used `{method}()` on `{constructor}` value");
+ let suggestion_message = format!("remove the `{constructor}` and `{method}()`");
- diag.multipart_suggestion(
- format!("remove the `{constructor}` and `{name}()`"),
- suggestions,
- Applicability::MachineApplicable,
- );
- },
- );
- } else {
- span_lint_and_then(
- cx,
- UNNECESSARY_LITERAL_UNWRAP,
- expr.span,
- &format!("used `{name}()` on `{constructor}` value"),
- |diag| {
- diag.span_help(init.span, format!("remove the `{constructor}` and `{name}()`"));
- },
- );
- }
+ 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()),
+ ],
+ };
+
+ 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);
+ });
}
}
diff --git a/tests/ui/unnecessary_literal_unwrap.fixed b/tests/ui/unnecessary_literal_unwrap.fixed
index 9733993d6191..d622c984c527 100644
--- a/tests/ui/unnecessary_literal_unwrap.fixed
+++ b/tests/ui/unnecessary_literal_unwrap.fixed
@@ -1,20 +1,30 @@
//run-rustfix
#![warn(clippy::unnecessary_literal_unwrap)]
#![allow(clippy::unnecessary_lazy_evaluations)]
+#![allow(unreachable_code)]
-fn unwrap_option() {
+fn unwrap_option_some() {
let _val = 1;
let _val = 1;
}
+fn unwrap_option_none() {
+ panic!();
+ panic!("this always happens");
+}
+
fn unwrap_result_ok() {
let _val = 1;
let _val = 1;
+ panic!("{:?}", 1);
+ panic!("{1}: {:?}", 1, "this always happens");
}
fn unwrap_result_err() {
let _val = 1;
let _val = 1;
+ panic!("{:?}", 1);
+ panic!("{1}: {:?}", 1, "this always happens");
}
fn unwrap_methods_option() {
@@ -30,7 +40,8 @@ fn unwrap_methods_result() {
}
fn main() {
- unwrap_option();
+ unwrap_option_some();
+ unwrap_option_none();
unwrap_result_ok();
unwrap_result_err();
unwrap_methods_option();
diff --git a/tests/ui/unnecessary_literal_unwrap.rs b/tests/ui/unnecessary_literal_unwrap.rs
index 775d744c13e7..926265a34711 100644
--- a/tests/ui/unnecessary_literal_unwrap.rs
+++ b/tests/ui/unnecessary_literal_unwrap.rs
@@ -1,20 +1,30 @@
//run-rustfix
#![warn(clippy::unnecessary_literal_unwrap)]
#![allow(clippy::unnecessary_lazy_evaluations)]
+#![allow(unreachable_code)]
-fn unwrap_option() {
+fn unwrap_option_some() {
let _val = Some(1).unwrap();
let _val = Some(1).expect("this never happens");
}
+fn unwrap_option_none() {
+ None::.unwrap();
+ None::.expect("this always happens");
+}
+
fn unwrap_result_ok() {
let _val = Ok::(1).unwrap();
let _val = 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");
}
fn unwrap_methods_option() {
@@ -30,7 +40,8 @@ fn unwrap_methods_result() {
}
fn main() {
- unwrap_option();
+ unwrap_option_some();
+ unwrap_option_none();
unwrap_result_ok();
unwrap_result_err();
unwrap_methods_option();
diff --git a/tests/ui/unnecessary_literal_unwrap.stderr b/tests/ui/unnecessary_literal_unwrap.stderr
index 622743f8c855..1d23bb22bdd2 100644
--- a/tests/ui/unnecessary_literal_unwrap.stderr
+++ b/tests/ui/unnecessary_literal_unwrap.stderr
@@ -1,5 +1,5 @@
error: used `unwrap()` on `Some` value
- --> $DIR/unnecessary_literal_unwrap.rs:6:16
+ --> $DIR/unnecessary_literal_unwrap.rs:7: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:7:16
+ --> $DIR/unnecessary_literal_unwrap.rs:8:16
|
LL | let _val = Some(1).expect("this never happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -23,8 +23,25 @@ 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
+ |
+LL | None::.unwrap();
+ | ^^^^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap()`: `panic!()`
+
+error: used `expect()` on `None` value
+ --> $DIR/unnecessary_literal_unwrap.rs:13:5
+ |
+LL | None::.expect("this always happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `None` and `expect()`
+ |
+LL | panic!("this always happens");
+ | ~~~~~~~ ~
+
error: used `unwrap()` on `Ok` value
- --> $DIR/unnecessary_literal_unwrap.rs:11:16
+ --> $DIR/unnecessary_literal_unwrap.rs:17:16
|
LL | let _val = Ok::(1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -36,7 +53,7 @@ LL + let _val = 1;
|
error: used `expect()` on `Ok` value
- --> $DIR/unnecessary_literal_unwrap.rs:12:16
+ --> $DIR/unnecessary_literal_unwrap.rs:18:16
|
LL | let _val = Ok::(1).expect("this never happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -47,8 +64,30 @@ 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
+ |
+LL | Ok::(1).unwrap_err();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap_err()`
+ |
+LL | panic!("{:?}", 1);
+ | ~~~~~~~~~~~~~~ ~
+
+error: used `expect_err()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap.rs:20:5
+ |
+LL | Ok::(1).expect_err("this always happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `expect_err()`
+ |
+LL | panic!("{1}: {:?}", 1, "this always happens");
+ | ~~~~~~~~~~~~~~~~~~~ ~
+
error: used `unwrap_err()` on `Err` value
- --> $DIR/unnecessary_literal_unwrap.rs:16:16
+ --> $DIR/unnecessary_literal_unwrap.rs:24:16
|
LL | let _val = Err::<(), usize>(1).unwrap_err();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -60,7 +99,7 @@ LL + let _val = 1;
|
error: used `expect_err()` on `Err` value
- --> $DIR/unnecessary_literal_unwrap.rs:17:16
+ --> $DIR/unnecessary_literal_unwrap.rs:25:16
|
LL | let _val = Err::<(), usize>(1).expect_err("this never happens");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -71,8 +110,30 @@ LL - let _val = Err::<(), usize>(1).expect_err("this never happens");
LL + let _val = 1;
|
+error: used `unwrap()` on `Err` value
+ --> $DIR/unnecessary_literal_unwrap.rs:26:5
+ |
+LL | Err::<(), usize>(1).unwrap();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Err` and `unwrap()`
+ |
+LL | panic!("{:?}", 1);
+ | ~~~~~~~~~~~~~~ ~
+
+error: used `expect()` on `Err` value
+ --> $DIR/unnecessary_literal_unwrap.rs:27:5
+ |
+LL | Err::<(), usize>(1).expect("this always happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Err` and `expect()`
+ |
+LL | panic!("{1}: {:?}", 1, "this always happens");
+ | ~~~~~~~~~~~~~~~~~~~ ~
+
error: used `unwrap_or()` on `Some` value
- --> $DIR/unnecessary_literal_unwrap.rs:21:16
+ --> $DIR/unnecessary_literal_unwrap.rs:31:16
|
LL | let _val = Some(1).unwrap_or(2);
| ^^^^^^^^^^^^^^^^^^^^
@@ -84,7 +145,7 @@ LL + let _val = 1;
|
error: used `unwrap_or_default()` on `Some` value
- --> $DIR/unnecessary_literal_unwrap.rs:22:16
+ --> $DIR/unnecessary_literal_unwrap.rs:32:16
|
LL | let _val = Some(1).unwrap_or_default();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -96,7 +157,7 @@ LL + let _val = 1;
|
error: used `unwrap_or_else()` on `Some` value
- --> $DIR/unnecessary_literal_unwrap.rs:23:16
+ --> $DIR/unnecessary_literal_unwrap.rs:33:16
|
LL | let _val = Some(1).unwrap_or_else(|| _val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -108,7 +169,7 @@ LL + let _val = 1;
|
error: used `unwrap_or()` on `Ok` value
- --> $DIR/unnecessary_literal_unwrap.rs:27:16
+ --> $DIR/unnecessary_literal_unwrap.rs:37:16
|
LL | let _val = Ok::(1).unwrap_or(2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -120,7 +181,7 @@ LL + let _val = 1;
|
error: used `unwrap_or_default()` on `Ok` value
- --> $DIR/unnecessary_literal_unwrap.rs:28:16
+ --> $DIR/unnecessary_literal_unwrap.rs:38:16
|
LL | let _val = Ok::(1).unwrap_or_default();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -132,7 +193,7 @@ LL + let _val = 1;
|
error: used `unwrap_or_else()` on `Ok` value
- --> $DIR/unnecessary_literal_unwrap.rs:29:16
+ --> $DIR/unnecessary_literal_unwrap.rs:39:16
|
LL | let _val = Ok::(1).unwrap_or_else(|()| _val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -143,5 +204,5 @@ LL - let _val = Ok::(1).unwrap_or_else(|()| _val);
LL + let _val = 1;
|
-error: aborting due to 12 previous errors
+error: aborting due to 18 previous errors
From 6cf138e9b63e63b913b5b567d9a1cb6870a8738f Mon Sep 17 00:00:00 2001
From: Pavan Kumar Sunkara
Date: Thu, 16 Feb 2023 23:14:20 +0000
Subject: [PATCH 14/16] Add more tests
---
tests/ui/unnecessary_literal_unwrap.fixed | 4 +-
tests/ui/unnecessary_literal_unwrap.rs | 8 +-
tests/ui/unnecessary_literal_unwrap.stderr | 12 +-
.../unnecessary_literal_unwrap_unfixable.rs | 50 ++++-
...nnecessary_literal_unwrap_unfixable.stderr | 210 +++++++++++++++++-
5 files changed, 268 insertions(+), 16 deletions(-)
diff --git a/tests/ui/unnecessary_literal_unwrap.fixed b/tests/ui/unnecessary_literal_unwrap.fixed
index d622c984c527..41c4dfda47fb 100644
--- a/tests/ui/unnecessary_literal_unwrap.fixed
+++ b/tests/ui/unnecessary_literal_unwrap.fixed
@@ -1,7 +1,7 @@
-//run-rustfix
+//@run-rustfix
#![warn(clippy::unnecessary_literal_unwrap)]
-#![allow(clippy::unnecessary_lazy_evaluations)]
#![allow(unreachable_code)]
+#![allow(clippy::unnecessary_lazy_evaluations)]
fn unwrap_option_some() {
let _val = 1;
diff --git a/tests/ui/unnecessary_literal_unwrap.rs b/tests/ui/unnecessary_literal_unwrap.rs
index 926265a34711..f15c063fe542 100644
--- a/tests/ui/unnecessary_literal_unwrap.rs
+++ b/tests/ui/unnecessary_literal_unwrap.rs
@@ -1,7 +1,7 @@
-//run-rustfix
+//@run-rustfix
#![warn(clippy::unnecessary_literal_unwrap)]
-#![allow(clippy::unnecessary_lazy_evaluations)]
#![allow(unreachable_code)]
+#![allow(clippy::unnecessary_lazy_evaluations)]
fn unwrap_option_some() {
let _val = Some(1).unwrap();
@@ -30,13 +30,13 @@ fn unwrap_result_err() {
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(|| _val);
+ let _val = Some(1).unwrap_or_else(|| 2);
}
fn unwrap_methods_result() {
let _val = Ok::(1).unwrap_or(2);
let _val = Ok::(1).unwrap_or_default();
- let _val = Ok::(1).unwrap_or_else(|()| _val);
+ let _val = Ok::(1).unwrap_or_else(|_| 2);
}
fn main() {
diff --git a/tests/ui/unnecessary_literal_unwrap.stderr b/tests/ui/unnecessary_literal_unwrap.stderr
index 1d23bb22bdd2..cf057d7fe5af 100644
--- a/tests/ui/unnecessary_literal_unwrap.stderr
+++ b/tests/ui/unnecessary_literal_unwrap.stderr
@@ -159,12 +159,12 @@ LL + let _val = 1;
error: used `unwrap_or_else()` on `Some` value
--> $DIR/unnecessary_literal_unwrap.rs:33:16
|
-LL | let _val = Some(1).unwrap_or_else(|| _val);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | let _val = Some(1).unwrap_or_else(|| 2);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Some` and `unwrap_or_else()`
|
-LL - let _val = Some(1).unwrap_or_else(|| _val);
+LL - let _val = Some(1).unwrap_or_else(|| 2);
LL + let _val = 1;
|
@@ -195,12 +195,12 @@ LL + let _val = 1;
error: used `unwrap_or_else()` on `Ok` value
--> $DIR/unnecessary_literal_unwrap.rs:39:16
|
-LL | let _val = Ok::(1).unwrap_or_else(|()| _val);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | let _val = Ok::(1).unwrap_or_else(|_| 2);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `unwrap_or_else()`
|
-LL - let _val = Ok::(1).unwrap_or_else(|()| _val);
+LL - let _val = Ok::(1).unwrap_or_else(|_| 2);
LL + let _val = 1;
|
diff --git a/tests/ui/unnecessary_literal_unwrap_unfixable.rs b/tests/ui/unnecessary_literal_unwrap_unfixable.rs
index ac3a84934afe..9ccf6b214470 100644
--- a/tests/ui/unnecessary_literal_unwrap_unfixable.rs
+++ b/tests/ui/unnecessary_literal_unwrap_unfixable.rs
@@ -1,6 +1,54 @@
#![warn(clippy::unnecessary_literal_unwrap)]
+#![allow(clippy::unnecessary_lazy_evaluations)]
+#![allow(unreachable_code)]
-fn main() {
+fn unwrap_option_some() {
let val = Some(1);
let _val2 = val.unwrap();
+ let _val2 = val.expect("this never happens");
+}
+
+fn unwrap_option_none() {
+ let val = None::;
+ val.unwrap();
+ val.expect("this always happens");
+}
+
+fn unwrap_result_ok() {
+ let val = Ok::(1);
+ let _val2 = val.unwrap();
+ let _val2 = val.expect("this never happens");
+ val.unwrap_err();
+ val.expect_err("this always happens");
+}
+
+fn unwrap_result_err() {
+ let val = Err::<(), usize>(1);
+ let _val2 = val.unwrap_err();
+ let _val2 = val.expect_err("this never happens");
+ val.unwrap();
+ val.expect("this always happens");
+}
+
+fn unwrap_methods_option() {
+ let val = Some(1);
+ 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::(1);
+ let _val2 = val.unwrap_or(2);
+ let _val2 = val.unwrap_or_default();
+ let _val2 = val.unwrap_or_else(|_| 2);
+}
+
+fn main() {
+ unwrap_option_some();
+ unwrap_option_none();
+ unwrap_result_ok();
+ unwrap_result_err();
+ unwrap_methods_option();
+ unwrap_methods_result();
}
diff --git a/tests/ui/unnecessary_literal_unwrap_unfixable.stderr b/tests/ui/unnecessary_literal_unwrap_unfixable.stderr
index abc789ccda4b..7931deeca7f7 100644
--- a/tests/ui/unnecessary_literal_unwrap_unfixable.stderr
+++ b/tests/ui/unnecessary_literal_unwrap_unfixable.stderr
@@ -1,15 +1,219 @@
error: used `unwrap()` on `Some` value
- --> $DIR/unnecessary_literal_unwrap_unfixable.rs:5:17
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:7:17
|
LL | let _val2 = val.unwrap();
| ^^^^^^^^^^^^
|
help: remove the `Some` and `unwrap()`
- --> $DIR/unnecessary_literal_unwrap_unfixable.rs:4:15
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:6:15
|
LL | let val = Some(1);
| ^^^^^^^
= note: `-D clippy::unnecessary-literal-unwrap` implied by `-D warnings`
-error: aborting due to previous error
+error: used `expect()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:8:17
+ |
+LL | let _val2 = val.expect("this never happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Some` and `expect()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:6:15
+ |
+LL | let val = Some(1);
+ | ^^^^^^^
+
+error: used `unwrap()` on `None` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:13:5
+ |
+LL | val.unwrap();
+ | ^^^^^^^^^^^^
+ |
+help: remove the `None` and `unwrap()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:12:15
+ |
+LL | let val = None::;
+ | ^^^^^^^^^^^^^
+
+error: used `expect()` on `None` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:14:5
+ |
+LL | val.expect("this always happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `None` and `expect()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:12:15
+ |
+LL | let val = None::;
+ | ^^^^^^^^^^^^^
+
+error: used `unwrap()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:19:17
+ |
+LL | let _val2 = val.unwrap();
+ | ^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:18:15
+ |
+LL | let val = Ok::(1);
+ | ^^^^^^^^^^^^^^^^^^
+
+error: used `expect()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:20:17
+ |
+LL | let _val2 = val.expect("this never happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `expect()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:18:15
+ |
+LL | let val = Ok::(1);
+ | ^^^^^^^^^^^^^^^^^^
+
+error: used `unwrap_err()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:21:5
+ |
+LL | val.unwrap_err();
+ | ^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap_err()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:18:15
+ |
+LL | let val = Ok::(1);
+ | ^^^^^^^^^^^^^^^^^^
+
+error: used `expect_err()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:22:5
+ |
+LL | val.expect_err("this always happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `expect_err()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:18:15
+ |
+LL | let val = Ok::(1);
+ | ^^^^^^^^^^^^^^^^^^
+
+error: used `unwrap_err()` on `Err` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:27:17
+ |
+LL | let _val2 = val.unwrap_err();
+ | ^^^^^^^^^^^^^^^^
+ |
+help: remove the `Err` and `unwrap_err()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:26:15
+ |
+LL | let val = Err::<(), usize>(1);
+ | ^^^^^^^^^^^^^^^^^^^
+
+error: used `expect_err()` on `Err` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:28: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
+ |
+LL | let val = Err::<(), usize>(1);
+ | ^^^^^^^^^^^^^^^^^^^
+
+error: used `unwrap()` on `Err` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:29:5
+ |
+LL | val.unwrap();
+ | ^^^^^^^^^^^^
+ |
+help: remove the `Err` and `unwrap()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:26:15
+ |
+LL | let val = Err::<(), usize>(1);
+ | ^^^^^^^^^^^^^^^^^^^
+
+error: used `expect()` on `Err` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:30:5
+ |
+LL | val.expect("this always happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Err` and `expect()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:26:15
+ |
+LL | let val = Err::<(), usize>(1);
+ | ^^^^^^^^^^^^^^^^^^^
+
+error: used `unwrap_or()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:35:17
+ |
+LL | let _val2 = val.unwrap_or(2);
+ | ^^^^^^^^^^^^^^^^
+ |
+help: remove the `Some` and `unwrap_or()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:34:15
+ |
+LL | let val = Some(1);
+ | ^^^^^^^
+
+error: used `unwrap_or_default()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:36:17
+ |
+LL | let _val2 = val.unwrap_or_default();
+ | ^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Some` and `unwrap_or_default()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:34:15
+ |
+LL | let val = Some(1);
+ | ^^^^^^^
+
+error: used `unwrap_or_else()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:37: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
+ |
+LL | let val = Some(1);
+ | ^^^^^^^
+
+error: used `unwrap_or()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:42:17
+ |
+LL | let _val2 = val.unwrap_or(2);
+ | ^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap_or()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:41:15
+ |
+LL | let val = Ok::(1);
+ | ^^^^^^^^^^^^^^^^^^
+
+error: used `unwrap_or_default()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:43:17
+ |
+LL | let _val2 = val.unwrap_or_default();
+ | ^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap_or_default()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:41:15
+ |
+LL | let val = Ok::(1);
+ | ^^^^^^^^^^^^^^^^^^
+
+error: used `unwrap_or_else()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:44: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
+ |
+LL | let val = Ok::(1);
+ | ^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 18 previous errors
From 6e4c5561be566c164c7519e6e3c6772f2da17cb4 Mon Sep 17 00:00:00 2001
From: Pavan Kumar Sunkara
Date: Wed, 31 May 2023 20:09:12 +0100
Subject: [PATCH 15/16] Preserve type annotations when present
---
clippy_lints/src/methods/mod.rs | 42 +-
.../src/methods/unnecessary_literal_unwrap.rs | 109 ++--
tests/ui/unnecessary_literal_unwrap.fixed | 31 +-
tests/ui/unnecessary_literal_unwrap.rs | 57 +-
tests/ui/unnecessary_literal_unwrap.stderr | 307 ++++++++--
.../unnecessary_literal_unwrap_unfixable.rs | 84 ++-
...nnecessary_literal_unwrap_unfixable.stderr | 526 +++++++++++++++---
7 files changed, 932 insertions(+), 224 deletions(-)
diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs
index 912cce39e2ea..183bd582a483 100644
--- a/clippy_lints/src/methods/mod.rs
+++ b/clippy_lints/src/methods/mod.rs
@@ -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 = 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 = 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 = 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! {
diff --git a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
index fe6b86b34f5e..7877f6a386cb 100644
--- a/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
+++ b/clippy_lints/src/methods/unnecessary_literal_unwrap.rs
@@ -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);
+ },
+ }
+ });
}
diff --git a/tests/ui/unnecessary_literal_unwrap.fixed b/tests/ui/unnecessary_literal_unwrap.fixed
index 41c4dfda47fb..630a1bea3c87 100644
--- a/tests/ui/unnecessary_literal_unwrap.fixed
+++ b/tests/ui/unnecessary_literal_unwrap.fixed
@@ -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() {
diff --git a/tests/ui/unnecessary_literal_unwrap.rs b/tests/ui/unnecessary_literal_unwrap.rs
index f15c063fe542..14f92cb370f6 100644
--- a/tests/ui/unnecessary_literal_unwrap.rs
+++ b/tests/ui/unnecessary_literal_unwrap.rs
@@ -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::.unwrap();
- None::.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::(1).unwrap();
- let _val = Ok::(1).expect("this never happens");
- Ok::(1).unwrap_err();
- Ok::(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::(1).unwrap_or(2);
- let _val = Ok::(1).unwrap_or_default();
- let _val = Ok::(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() {
diff --git a/tests/ui/unnecessary_literal_unwrap.stderr b/tests/ui/unnecessary_literal_unwrap.stderr
index cf057d7fe5af..0c71ee053231 100644
--- a/tests/ui/unnecessary_literal_unwrap.stderr
+++ b/tests/ui/unnecessary_literal_unwrap.stderr
@@ -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 `Some` value
+ --> $DIR/unnecessary_literal_unwrap.rs:15:5
+ |
+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:12:5
+ --> $DIR/unnecessary_literal_unwrap.rs:20:16
|
-LL | None::.unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap()`: `panic!()`
+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::.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::(1).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | let _val = Ok::<_, ()>(1).unwrap();
+ | ^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `unwrap()`
|
-LL - let _val = Ok::(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::(1).expect("this never happens");
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | let _val = Ok::<_, ()>(1).expect("this never happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `expect()`
|
-LL - let _val = Ok::(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::(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::(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 | 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 | Err::<(), usize>(1).unwrap();
+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 `Some` value
+ --> $DIR/unnecessary_literal_unwrap.rs:56:5
+ |
+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:37:16
+ --> $DIR/unnecessary_literal_unwrap.rs:62:16
|
-LL | let _val = Ok::(1).unwrap_or(2);
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | let _val = Ok::<_, ()>(1).unwrap_or(2);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `unwrap_or()`
|
-LL - let _val = Ok::(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::(1).unwrap_or_default();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | let _val = Ok::<_, ()>(1).unwrap_or_default();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove the `Ok` and `unwrap_or_default()`
|
-LL - let _val = Ok::(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::(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::(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
diff --git a/tests/ui/unnecessary_literal_unwrap_unfixable.rs b/tests/ui/unnecessary_literal_unwrap_unfixable.rs
index 9ccf6b214470..711fdce39624 100644
--- a/tests/ui/unnecessary_literal_unwrap_unfixable.rs
+++ b/tests/ui/unnecessary_literal_unwrap_unfixable.rs
@@ -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::([1, 2, 3].iter().sum()).unwrap();
+ let _val = Some::([1, 2, 3].iter().sum()).expect("this never happens");
+
+ let val = Some::([1, 2, 3].iter().sum());
+ let _val2 = val.unwrap();
+ let _val2 = val.expect("this never happens");
+}
+
fn unwrap_option_none() {
- let val = None::;
- 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::(1);
+ let val = Ok::<_, ()>(1);
+ 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_ok_context() {
+ let _val = Ok::([1, 2, 3].iter().sum()).unwrap();
+ let _val = Ok::([1, 2, 3].iter().sum()).expect("this never happens");
+ let _val = Ok::([1, 2, 3].iter().sum()).unwrap_err();
+ let _val = Ok::([1, 2, 3].iter().sum()).expect_err("this always happens");
+
+ let val = Ok::([1, 2, 3].iter().sum());
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_err() {
- let val = Err::<(), usize>(1);
+ let val = Err::<(), _>(1);
+ 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_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");
- val.unwrap();
- val.expect("this always 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::([1, 2, 3].iter().sum()).unwrap_or(2);
+ let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_default();
+ let _val = Some::([1, 2, 3].iter().sum()).unwrap_or_else(|| 2);
+
+ let val = Some::([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::(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::([1, 2, 3].iter().sum()).unwrap_or(2);
+ let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_default();
+ let _val = Ok::([1, 2, 3].iter().sum()).unwrap_or_else(|_| 2);
+
+ let val = Ok::([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();
}
diff --git a/tests/ui/unnecessary_literal_unwrap_unfixable.stderr b/tests/ui/unnecessary_literal_unwrap_unfixable.stderr
index 7931deeca7f7..feb9325b77a6 100644
--- a/tests/ui/unnecessary_literal_unwrap_unfixable.stderr
+++ b/tests/ui/unnecessary_literal_unwrap_unfixable.stderr
@@ -23,197 +23,581 @@ help: remove the `Some` and `expect()`
LL | let val = Some(1);
| ^^^^^^^
+error: used `unwrap()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:12:16
+ |
+LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Some` and `unwrap()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:12:16
+ |
+LL | let _val = Some::([1, 2, 3].iter().sum()).unwrap();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: used `expect()` on `Some` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:13:16
+ |
+LL | let _val = Some::([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::([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::([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::([1, 2, 3].iter().sum());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
error: used `unwrap()` on `None` value
- --> $DIR/unnecessary_literal_unwrap_unfixable.rs:13:5
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:22:17
|
-LL | val.unwrap();
- | ^^^^^^^^^^^^
+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::;
- | ^^^^^^^^^^^^^
+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::;
- | ^^^^^^^^^^^^^
+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::(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::(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::(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::<_, ()>(1);
+ | ^^^^^^^^^^^^^^
+
+error: used `unwrap()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:35:16
+ |
+LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Ok` and `unwrap()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:35:16
+ |
+LL | let _val = Ok::([1, 2, 3].iter().sum()).unwrap();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: used `expect()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:36:16
+ |
+LL | let _val = Ok::([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::(1);
- | ^^^^^^^^^^^^^^^^^^
+LL | let _val = Ok::([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::([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::([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::([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::([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::([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::([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::([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::([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:48:15
+ |
+LL | let val = Err::<(), _>(1);
+ | ^^^^^^^^^^^^^^^
+
+error: used `unwrap()` on `Err` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:51:17
+ |
+LL | let _val2 = val.unwrap();
+ | ^^^^^^^^^^^^
+ |
+help: remove the `Err` and `unwrap()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:48:15
+ |
+LL | let val = Err::<(), _>(1);
+ | ^^^^^^^^^^^^^^^
+
+error: used `expect()` on `Err` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:52:17
+ |
+LL | let _val2 = val.expect("this always happens");
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+help: remove the `Err` and `expect()`
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:48:15
+ |
+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:26:15
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:61:15
|
-LL | let val = Err::<(), usize>(1);
- | ^^^^^^^^^^^^^^^^^^^
+LL | let val = Err::<(), usize>([1, 2, 3].iter().sum());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `unwrap()` on `Err` value
- --> $DIR/unnecessary_literal_unwrap_unfixable.rs:29:5
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:64: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:61:15
|
-LL | let val = Err::<(), usize>(1);
- | ^^^^^^^^^^^^^^^^^^^
+LL | let val = Err::<(), usize>([1, 2, 3].iter().sum());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: used `expect()` on `Err` value
- --> $DIR/unnecessary_literal_unwrap_unfixable.rs:30:5
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:65: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:61:15
|
-LL | let val = Err::<(), usize>(1);
- | ^^^^^^^^^^^^^^^^^^^
+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::([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::([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::([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::([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::([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::([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::([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::([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::([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::(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::(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:87:15
+ |
+LL | let val = Ok::<_, ()>(1);
+ | ^^^^^^^^^^^^^^
+
+error: used `unwrap_or()` on `Ok` value
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:94:16
+ |
+LL | let _val = Ok::([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::([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::([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::([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::([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::([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::([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::([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:41:15
+ --> $DIR/unnecessary_literal_unwrap_unfixable.rs:98:15
|
-LL | let val = Ok::(1);
- | ^^^^^^^^^^^^^^^^^^
+LL | let val = Ok::([1, 2, 3].iter().sum());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: aborting due to 18 previous errors
+error: aborting due to 50 previous errors
From bfd5abad4b1b93133796a07a52ece3f7aa053062 Mon Sep 17 00:00:00 2001
From: Pavan Kumar Sunkara
Date: Wed, 31 May 2023 18:47:10 +0100
Subject: [PATCH 16/16] Fix all the other tests
---
.../uninlined_format_args.fixed | 1 +
.../uninlined_format_args.rs | 1 +
.../uninlined_format_args.stderr | 12 +-
.../arithmetic_side_effects_allowed.rs | 1 +
.../arithmetic_side_effects_allowed.stderr | 18 +--
tests/ui-toml/expect_used/expect_used.rs | 1 +
tests/ui-toml/expect_used/expect_used.stderr | 4 +-
tests/ui/assertions_on_result_states.fixed | 1 +
tests/ui/assertions_on_result_states.rs | 1 +
tests/ui/assertions_on_result_states.stderr | 14 +-
tests/ui/blocks_in_if_conditions_closure.rs | 7 +-
.../ui/blocks_in_if_conditions_closure.stderr | 4 +-
.../ui/checked_unwrap/complex_conditionals.rs | 6 +-
.../complex_conditionals.stderr | 40 ++---
.../complex_conditionals_nested.rs | 6 +-
.../complex_conditionals_nested.stderr | 4 +-
.../ui/checked_unwrap/simple_conditionals.rs | 6 +-
.../checked_unwrap/simple_conditionals.stderr | 34 ++---
tests/ui/crashes/ice-5579.rs | 2 +
tests/ui/err_expect.fixed | 2 +-
tests/ui/err_expect.rs | 2 +-
tests/ui/expect.rs | 1 +
tests/ui/expect.stderr | 6 +-
tests/ui/expect_fun_call.fixed | 6 +-
tests/ui/expect_fun_call.rs | 6 +-
tests/ui/expect_fun_call.stderr | 30 ++--
tests/ui/explicit_deref_methods.fixed | 3 +-
tests/ui/explicit_deref_methods.rs | 3 +-
tests/ui/explicit_deref_methods.stderr | 24 +--
tests/ui/manual_unwrap_or.fixed | 2 +-
tests/ui/manual_unwrap_or.rs | 2 +-
tests/ui/missing_panics_doc.rs | 2 +-
tests/ui/needless_borrow.fixed | 3 +-
tests/ui/needless_borrow.rs | 3 +-
tests/ui/needless_borrow.stderr | 72 ++++-----
tests/ui/needless_range_loop.rs | 6 +-
tests/ui/needless_range_loop.stderr | 28 ++--
tests/ui/ok_expect.rs | 2 +
tests/ui/ok_expect.stderr | 10 +-
tests/ui/or_fun_call.fixed | 1 +
tests/ui/or_fun_call.rs | 1 +
tests/ui/or_fun_call.stderr | 56 +++----
tests/ui/or_then_unwrap.fixed | 2 +-
tests/ui/or_then_unwrap.rs | 2 +-
tests/ui/redundant_clone.fixed | 7 +-
tests/ui/redundant_clone.rs | 7 +-
tests/ui/redundant_clone.stderr | 60 ++++----
tests/ui/uninlined_format_args.fixed | 7 +-
tests/ui/uninlined_format_args.rs | 7 +-
tests/ui/uninlined_format_args.stderr | 142 +++++++++---------
tests/ui/unnecessary_lazy_eval.fixed | 1 +
tests/ui/unnecessary_lazy_eval.rs | 1 +
tests/ui/unnecessary_lazy_eval.stderr | 76 +++++-----
tests/ui/unnecessary_lazy_eval_unfixable.rs | 1 +
.../ui/unnecessary_lazy_eval_unfixable.stderr | 6 +-
tests/ui/unwrap.rs | 1 +
tests/ui/unwrap.stderr | 6 +-
tests/ui/unwrap_expect_used.rs | 1 +
tests/ui/unwrap_expect_used.stderr | 12 +-
tests/ui/unwrap_or.rs | 1 +
tests/ui/unwrap_or.stderr | 4 +-
tests/ui/unwrap_or_else_default.fixed | 2 +-
tests/ui/unwrap_or_else_default.rs | 2 +-
63 files changed, 427 insertions(+), 355 deletions(-)
diff --git a/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.fixed b/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.fixed
index 23e7bc16d239..c90856845280 100644
--- a/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.fixed
+++ b/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.fixed
@@ -1,5 +1,6 @@
//@run-rustfix
#![warn(clippy::uninlined_format_args)]
+#![allow(clippy::unnecessary_literal_unwrap)]
fn main() {
let local_i32 = 1;
diff --git a/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs b/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs
index d66b2b8ff6a0..661350c5c6d5 100644
--- a/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs
+++ b/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.rs
@@ -1,5 +1,6 @@
//@run-rustfix
#![warn(clippy::uninlined_format_args)]
+#![allow(clippy::unnecessary_literal_unwrap)]
fn main() {
let local_i32 = 1;
diff --git a/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.stderr b/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.stderr
index 1be0cda12fc1..6ec79a618de1 100644
--- a/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.stderr
+++ b/tests/ui-toml/allow_mixed_uninlined_format_args/uninlined_format_args.stderr
@@ -1,5 +1,5 @@
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:9:5
+ --> $DIR/uninlined_format_args.rs:10:5
|
LL | println!("val='{}'", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -12,7 +12,7 @@ LL + println!("val='{local_i32}'");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:10:5
+ --> $DIR/uninlined_format_args.rs:11:5
|
LL | println!("Hello {} is {:.*}", "x", local_i32, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -24,7 +24,7 @@ LL + println!("Hello {} is {local_f64:.local_i32$}", "x");
|
error: literal with an empty format string
- --> $DIR/uninlined_format_args.rs:10:35
+ --> $DIR/uninlined_format_args.rs:11:35
|
LL | println!("Hello {} is {:.*}", "x", local_i32, local_f64);
| ^^^
@@ -37,7 +37,7 @@ LL + println!("Hello x is {:.*}", local_i32, local_f64);
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:11:5
+ --> $DIR/uninlined_format_args.rs:12:5
|
LL | println!("Hello {} is {:.*}", local_i32, 5, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -49,7 +49,7 @@ LL + println!("Hello {local_i32} is {local_f64:.*}", 5);
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:12:5
+ --> $DIR/uninlined_format_args.rs:13:5
|
LL | println!("Hello {} is {2:.*}", local_i32, 5, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -61,7 +61,7 @@ LL + println!("Hello {local_i32} is {local_f64:.*}", 5);
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:13:5
+ --> $DIR/uninlined_format_args.rs:14:5
|
LL | println!("{}, {}", local_i32, local_opt.unwrap());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs b/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs
index fb5b1b193f84..33f7c8ba8042 100644
--- a/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs
+++ b/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.rs
@@ -1,4 +1,5 @@
#![warn(clippy::arithmetic_side_effects)]
+#![allow(clippy::unnecessary_literal_unwrap)]
use core::ops::{Add, Neg};
diff --git a/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.stderr b/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.stderr
index ad89534aa1b0..4f98ca192311 100644
--- a/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.stderr
+++ b/tests/ui-toml/arithmetic_side_effects_allowed/arithmetic_side_effects_allowed.stderr
@@ -1,5 +1,5 @@
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects_allowed.rs:68:13
+ --> $DIR/arithmetic_side_effects_allowed.rs:69:13
|
LL | let _ = Baz + Baz;
| ^^^^^^^^^
@@ -7,49 +7,49 @@ LL | let _ = Baz + Baz;
= note: `-D clippy::arithmetic-side-effects` implied by `-D warnings`
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects_allowed.rs:79:13
+ --> $DIR/arithmetic_side_effects_allowed.rs:80:13
|
LL | let _ = 1i32 + Baz;
| ^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects_allowed.rs:82:13
+ --> $DIR/arithmetic_side_effects_allowed.rs:83:13
|
LL | let _ = 1i64 + Foo;
| ^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects_allowed.rs:86:13
+ --> $DIR/arithmetic_side_effects_allowed.rs:87:13
|
LL | let _ = 1i64 + Baz;
| ^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects_allowed.rs:97:13
+ --> $DIR/arithmetic_side_effects_allowed.rs:98:13
|
LL | let _ = Baz + 1i32;
| ^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects_allowed.rs:100:13
+ --> $DIR/arithmetic_side_effects_allowed.rs:101:13
|
LL | let _ = Foo + 1i64;
| ^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects_allowed.rs:104:13
+ --> $DIR/arithmetic_side_effects_allowed.rs:105:13
|
LL | let _ = Baz + 1i64;
| ^^^^^^^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects_allowed.rs:113:13
+ --> $DIR/arithmetic_side_effects_allowed.rs:114:13
|
LL | let _ = -Bar;
| ^^^^
error: arithmetic operation that can potentially result in unexpected side-effects
- --> $DIR/arithmetic_side_effects_allowed.rs:115:13
+ --> $DIR/arithmetic_side_effects_allowed.rs:116:13
|
LL | let _ = -Baz;
| ^^^^
diff --git a/tests/ui-toml/expect_used/expect_used.rs b/tests/ui-toml/expect_used/expect_used.rs
index 9e267c893005..206788e19f02 100644
--- a/tests/ui-toml/expect_used/expect_used.rs
+++ b/tests/ui-toml/expect_used/expect_used.rs
@@ -1,5 +1,6 @@
//@compile-flags: --test
#![warn(clippy::expect_used)]
+#![allow(clippy::unnecessary_literal_unwrap)]
fn expect_option() {
let opt = Some(0);
diff --git a/tests/ui-toml/expect_used/expect_used.stderr b/tests/ui-toml/expect_used/expect_used.stderr
index 1e9bb48c333c..9eef0e1bfaa1 100644
--- a/tests/ui-toml/expect_used/expect_used.stderr
+++ b/tests/ui-toml/expect_used/expect_used.stderr
@@ -1,5 +1,5 @@
error: used `expect()` on an `Option` value
- --> $DIR/expect_used.rs:6:13
+ --> $DIR/expect_used.rs:7:13
|
LL | let _ = opt.expect("");
| ^^^^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL | let _ = opt.expect("");
= note: `-D clippy::expect-used` implied by `-D warnings`
error: used `expect()` on a `Result` value
- --> $DIR/expect_used.rs:11:13
+ --> $DIR/expect_used.rs:12:13
|
LL | let _ = res.expect("");
| ^^^^^^^^^^^^^^
diff --git a/tests/ui/assertions_on_result_states.fixed b/tests/ui/assertions_on_result_states.fixed
index ea8b895664c4..3152bd3cae1a 100644
--- a/tests/ui/assertions_on_result_states.fixed
+++ b/tests/ui/assertions_on_result_states.fixed
@@ -1,5 +1,6 @@
//@run-rustfix
#![warn(clippy::assertions_on_result_states)]
+#![allow(clippy::unnecessary_literal_unwrap)]
use std::result::Result;
diff --git a/tests/ui/assertions_on_result_states.rs b/tests/ui/assertions_on_result_states.rs
index 6fc20f859887..42755e935aa4 100644
--- a/tests/ui/assertions_on_result_states.rs
+++ b/tests/ui/assertions_on_result_states.rs
@@ -1,5 +1,6 @@
//@run-rustfix
#![warn(clippy::assertions_on_result_states)]
+#![allow(clippy::unnecessary_literal_unwrap)]
use std::result::Result;
diff --git a/tests/ui/assertions_on_result_states.stderr b/tests/ui/assertions_on_result_states.stderr
index 298d63c9c34f..be581030cb67 100644
--- a/tests/ui/assertions_on_result_states.stderr
+++ b/tests/ui/assertions_on_result_states.stderr
@@ -1,5 +1,5 @@
error: called `assert!` with `Result::is_ok`
- --> $DIR/assertions_on_result_states.rs:24:5
+ --> $DIR/assertions_on_result_states.rs:25:5
|
LL | assert!(r.is_ok());
| ^^^^^^^^^^^^^^^^^^ help: replace with: `r.unwrap()`
@@ -7,37 +7,37 @@ LL | assert!(r.is_ok());
= note: `-D clippy::assertions-on-result-states` implied by `-D warnings`
error: called `assert!` with `Result::is_ok`
- --> $DIR/assertions_on_result_states.rs:42:5
+ --> $DIR/assertions_on_result_states.rs:43:5
|
LL | assert!(get_ok().is_ok());
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `get_ok().unwrap()`
error: called `assert!` with `Result::is_ok`
- --> $DIR/assertions_on_result_states.rs:45:5
+ --> $DIR/assertions_on_result_states.rs:46:5
|
LL | assert!(get_ok_macro!().is_ok());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `get_ok_macro!().unwrap()`
error: called `assert!` with `Result::is_ok`
- --> $DIR/assertions_on_result_states.rs:58:5
+ --> $DIR/assertions_on_result_states.rs:59:5
|
LL | assert!(r.is_ok());
| ^^^^^^^^^^^^^^^^^^ help: replace with: `r.unwrap()`
error: called `assert!` with `Result::is_ok`
- --> $DIR/assertions_on_result_states.rs:64:9
+ --> $DIR/assertions_on_result_states.rs:65:9
|
LL | assert!(r.is_ok());
| ^^^^^^^^^^^^^^^^^^ help: replace with: `r.unwrap()`
error: called `assert!` with `Result::is_err`
- --> $DIR/assertions_on_result_states.rs:72:5
+ --> $DIR/assertions_on_result_states.rs:73:5
|
LL | assert!(r.is_err());
| ^^^^^^^^^^^^^^^^^^^ help: replace with: `r.unwrap_err()`
error: called `assert!` with `Result::is_err`
- --> $DIR/assertions_on_result_states.rs:82:5
+ --> $DIR/assertions_on_result_states.rs:83:5
|
LL | assert!(res.is_err())
| ^^^^^^^^^^^^^^^^^^^^^ help: replace with: `res.unwrap_err();`
diff --git a/tests/ui/blocks_in_if_conditions_closure.rs b/tests/ui/blocks_in_if_conditions_closure.rs
index 7da12d89a610..d6d085d7fd14 100644
--- a/tests/ui/blocks_in_if_conditions_closure.rs
+++ b/tests/ui/blocks_in_if_conditions_closure.rs
@@ -1,5 +1,10 @@
#![warn(clippy::blocks_in_if_conditions)]
-#![allow(unused, clippy::let_and_return, clippy::needless_if)]
+#![allow(
+ unused,
+ clippy::let_and_return,
+ clippy::needless_if,
+ clippy::unnecessary_literal_unwrap
+)]
fn predicate bool, T>(pfn: F, val: T) -> bool {
pfn(val)
diff --git a/tests/ui/blocks_in_if_conditions_closure.stderr b/tests/ui/blocks_in_if_conditions_closure.stderr
index 941d604dd5f9..5ac02e7504e8 100644
--- a/tests/ui/blocks_in_if_conditions_closure.stderr
+++ b/tests/ui/blocks_in_if_conditions_closure.stderr
@@ -1,5 +1,5 @@
error: in an `if` condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let`
- --> $DIR/blocks_in_if_conditions_closure.rs:18:17
+ --> $DIR/blocks_in_if_conditions_closure.rs:23:17
|
LL | |x| {
| _________________^
@@ -11,7 +11,7 @@ LL | | },
= note: `-D clippy::blocks-in-if-conditions` implied by `-D warnings`
error: in an `if` condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let`
- --> $DIR/blocks_in_if_conditions_closure.rs:27:13
+ --> $DIR/blocks_in_if_conditions_closure.rs:32:13
|
LL | |x| {
| _____________^
diff --git a/tests/ui/checked_unwrap/complex_conditionals.rs b/tests/ui/checked_unwrap/complex_conditionals.rs
index ec082c73b44c..16e54a7d969e 100644
--- a/tests/ui/checked_unwrap/complex_conditionals.rs
+++ b/tests/ui/checked_unwrap/complex_conditionals.rs
@@ -1,5 +1,9 @@
#![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
-#![allow(clippy::if_same_then_else, clippy::branches_sharing_code)]
+#![allow(
+ clippy::if_same_then_else,
+ clippy::branches_sharing_code,
+ clippy::unnecessary_literal_unwrap
+)]
fn test_complex_conditions() {
let x: Result<(), ()> = Ok(());
diff --git a/tests/ui/checked_unwrap/complex_conditionals.stderr b/tests/ui/checked_unwrap/complex_conditionals.stderr
index d44d5072e485..c395c5ba06f2 100644
--- a/tests/ui/checked_unwrap/complex_conditionals.stderr
+++ b/tests/ui/checked_unwrap/complex_conditionals.stderr
@@ -1,5 +1,5 @@
error: called `unwrap` on `x` after checking its variant with `is_ok`
- --> $DIR/complex_conditionals.rs:8:9
+ --> $DIR/complex_conditionals.rs:12:9
|
LL | if x.is_ok() && y.is_err() {
| --------- the check is happening here
@@ -14,7 +14,7 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: this call to `unwrap_err()` will always panic
- --> $DIR/complex_conditionals.rs:9:9
+ --> $DIR/complex_conditionals.rs:13:9
|
LL | if x.is_ok() && y.is_err() {
| --------- because of this check
@@ -29,7 +29,7 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: this call to `unwrap()` will always panic
- --> $DIR/complex_conditionals.rs:10:9
+ --> $DIR/complex_conditionals.rs:14:9
|
LL | if x.is_ok() && y.is_err() {
| ---------- because of this check
@@ -38,7 +38,7 @@ LL | y.unwrap(); // will panic
| ^^^^^^^^^^
error: called `unwrap_err` on `y` after checking its variant with `is_err`
- --> $DIR/complex_conditionals.rs:11:9
+ --> $DIR/complex_conditionals.rs:15:9
|
LL | if x.is_ok() && y.is_err() {
| ---------- the check is happening here
@@ -49,7 +49,7 @@ LL | y.unwrap_err(); // unnecessary
= help: try using `if let` or `match`
error: this call to `unwrap()` will always panic
- --> $DIR/complex_conditionals.rs:25:9
+ --> $DIR/complex_conditionals.rs:29:9
|
LL | if x.is_ok() || y.is_ok() {
| --------- because of this check
@@ -58,7 +58,7 @@ LL | x.unwrap(); // will panic
| ^^^^^^^^^^
error: called `unwrap_err` on `x` after checking its variant with `is_ok`
- --> $DIR/complex_conditionals.rs:26:9
+ --> $DIR/complex_conditionals.rs:30:9
|
LL | if x.is_ok() || y.is_ok() {
| --------- the check is happening here
@@ -69,7 +69,7 @@ LL | x.unwrap_err(); // unnecessary
= help: try using `if let` or `match`
error: this call to `unwrap()` will always panic
- --> $DIR/complex_conditionals.rs:27:9
+ --> $DIR/complex_conditionals.rs:31:9
|
LL | if x.is_ok() || y.is_ok() {
| --------- because of this check
@@ -78,7 +78,7 @@ LL | y.unwrap(); // will panic
| ^^^^^^^^^^
error: called `unwrap_err` on `y` after checking its variant with `is_ok`
- --> $DIR/complex_conditionals.rs:28:9
+ --> $DIR/complex_conditionals.rs:32:9
|
LL | if x.is_ok() || y.is_ok() {
| --------- the check is happening here
@@ -89,7 +89,7 @@ LL | y.unwrap_err(); // unnecessary
= help: try using `if let` or `match`
error: called `unwrap` on `x` after checking its variant with `is_ok`
- --> $DIR/complex_conditionals.rs:32:9
+ --> $DIR/complex_conditionals.rs:36:9
|
LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
| --------- the check is happening here
@@ -99,7 +99,7 @@ LL | x.unwrap(); // unnecessary
= help: try using `if let` or `match`
error: this call to `unwrap_err()` will always panic
- --> $DIR/complex_conditionals.rs:33:9
+ --> $DIR/complex_conditionals.rs:37:9
|
LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
| --------- because of this check
@@ -108,7 +108,7 @@ LL | x.unwrap_err(); // will panic
| ^^^^^^^^^^^^^^
error: this call to `unwrap()` will always panic
- --> $DIR/complex_conditionals.rs:34:9
+ --> $DIR/complex_conditionals.rs:38:9
|
LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
| --------- because of this check
@@ -117,7 +117,7 @@ LL | y.unwrap(); // will panic
| ^^^^^^^^^^
error: called `unwrap_err` on `y` after checking its variant with `is_ok`
- --> $DIR/complex_conditionals.rs:35:9
+ --> $DIR/complex_conditionals.rs:39:9
|
LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
| --------- the check is happening here
@@ -128,7 +128,7 @@ LL | y.unwrap_err(); // unnecessary
= help: try using `if let` or `match`
error: called `unwrap` on `z` after checking its variant with `is_err`
- --> $DIR/complex_conditionals.rs:36:9
+ --> $DIR/complex_conditionals.rs:40:9
|
LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
| ---------- the check is happening here
@@ -139,7 +139,7 @@ LL | z.unwrap(); // unnecessary
= help: try using `if let` or `match`
error: this call to `unwrap_err()` will always panic
- --> $DIR/complex_conditionals.rs:37:9
+ --> $DIR/complex_conditionals.rs:41:9
|
LL | if x.is_ok() && !(y.is_ok() || z.is_err()) {
| ---------- because of this check
@@ -148,7 +148,7 @@ LL | z.unwrap_err(); // will panic
| ^^^^^^^^^^^^^^
error: this call to `unwrap()` will always panic
- --> $DIR/complex_conditionals.rs:45:9
+ --> $DIR/complex_conditionals.rs:49:9
|
LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
| --------- because of this check
@@ -157,7 +157,7 @@ LL | x.unwrap(); // will panic
| ^^^^^^^^^^
error: called `unwrap_err` on `x` after checking its variant with `is_ok`
- --> $DIR/complex_conditionals.rs:46:9
+ --> $DIR/complex_conditionals.rs:50:9
|
LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
| --------- the check is happening here
@@ -168,7 +168,7 @@ LL | x.unwrap_err(); // unnecessary
= help: try using `if let` or `match`
error: called `unwrap` on `y` after checking its variant with `is_ok`
- --> $DIR/complex_conditionals.rs:47:9
+ --> $DIR/complex_conditionals.rs:51:9
|
LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
| --------- the check is happening here
@@ -179,7 +179,7 @@ LL | y.unwrap(); // unnecessary
= help: try using `if let` or `match`
error: this call to `unwrap_err()` will always panic
- --> $DIR/complex_conditionals.rs:48:9
+ --> $DIR/complex_conditionals.rs:52:9
|
LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
| --------- because of this check
@@ -188,7 +188,7 @@ LL | y.unwrap_err(); // will panic
| ^^^^^^^^^^^^^^
error: this call to `unwrap()` will always panic
- --> $DIR/complex_conditionals.rs:49:9
+ --> $DIR/complex_conditionals.rs:53:9
|
LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
| ---------- because of this check
@@ -197,7 +197,7 @@ LL | z.unwrap(); // will panic
| ^^^^^^^^^^
error: called `unwrap_err` on `z` after checking its variant with `is_err`
- --> $DIR/complex_conditionals.rs:50:9
+ --> $DIR/complex_conditionals.rs:54:9
|
LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
| ---------- the check is happening here
diff --git a/tests/ui/checked_unwrap/complex_conditionals_nested.rs b/tests/ui/checked_unwrap/complex_conditionals_nested.rs
index 043ea4148dc5..e417cf833cbb 100644
--- a/tests/ui/checked_unwrap/complex_conditionals_nested.rs
+++ b/tests/ui/checked_unwrap/complex_conditionals_nested.rs
@@ -1,5 +1,9 @@
#![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
-#![allow(clippy::if_same_then_else, clippy::branches_sharing_code)]
+#![allow(
+ clippy::if_same_then_else,
+ clippy::branches_sharing_code,
+ clippy::unnecessary_literal_unwrap
+)]
fn test_nested() {
fn nested() {
diff --git a/tests/ui/checked_unwrap/complex_conditionals_nested.stderr b/tests/ui/checked_unwrap/complex_conditionals_nested.stderr
index 542ab53300c0..049a69d93bfe 100644
--- a/tests/ui/checked_unwrap/complex_conditionals_nested.stderr
+++ b/tests/ui/checked_unwrap/complex_conditionals_nested.stderr
@@ -1,5 +1,5 @@
error: called `unwrap` on `x` after checking its variant with `is_some`
- --> $DIR/complex_conditionals_nested.rs:8:13
+ --> $DIR/complex_conditionals_nested.rs:12:13
|
LL | if x.is_some() {
| -------------- help: try: `if let Some(..) = x`
@@ -13,7 +13,7 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: this call to `unwrap()` will always panic
- --> $DIR/complex_conditionals_nested.rs:10:13
+ --> $DIR/complex_conditionals_nested.rs:14:13
|
LL | if x.is_some() {
| ----------- because of this check
diff --git a/tests/ui/checked_unwrap/simple_conditionals.rs b/tests/ui/checked_unwrap/simple_conditionals.rs
index 82dce81979fd..61042bb90d27 100644
--- a/tests/ui/checked_unwrap/simple_conditionals.rs
+++ b/tests/ui/checked_unwrap/simple_conditionals.rs
@@ -1,6 +1,10 @@
#![feature(lint_reasons)]
#![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
-#![allow(clippy::if_same_then_else, clippy::branches_sharing_code)]
+#![allow(
+ clippy::if_same_then_else,
+ clippy::branches_sharing_code,
+ clippy::unnecessary_literal_unwrap
+)]
macro_rules! m {
($a:expr) => {
diff --git a/tests/ui/checked_unwrap/simple_conditionals.stderr b/tests/ui/checked_unwrap/simple_conditionals.stderr
index ef6882742223..93809f6551ad 100644
--- a/tests/ui/checked_unwrap/simple_conditionals.stderr
+++ b/tests/ui/checked_unwrap/simple_conditionals.stderr
@@ -1,5 +1,5 @@
error: called `unwrap` on `x` after checking its variant with `is_some`
- --> $DIR/simple_conditionals.rs:40:9
+ --> $DIR/simple_conditionals.rs:44:9
|
LL | if x.is_some() {
| -------------- help: try: `if let Some(..) = x`
@@ -13,7 +13,7 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: called `expect` on `x` after checking its variant with `is_some`
- --> $DIR/simple_conditionals.rs:41:9
+ --> $DIR/simple_conditionals.rs:45:9
|
LL | if x.is_some() {
| -------------- help: try: `if let Some(..) = x`
@@ -22,7 +22,7 @@ LL | x.expect("an error message"); // unnecessary
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: this call to `unwrap()` will always panic
- --> $DIR/simple_conditionals.rs:43:9
+ --> $DIR/simple_conditionals.rs:47:9
|
LL | if x.is_some() {
| ----------- because of this check
@@ -37,7 +37,7 @@ LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: this call to `expect()` will always panic
- --> $DIR/simple_conditionals.rs:44:9
+ --> $DIR/simple_conditionals.rs:48:9
|
LL | if x.is_some() {
| ----------- because of this check
@@ -46,7 +46,7 @@ LL | x.expect("an error message"); // will panic
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: this call to `unwrap()` will always panic
- --> $DIR/simple_conditionals.rs:47:9
+ --> $DIR/simple_conditionals.rs:51:9
|
LL | if x.is_none() {
| ----------- because of this check
@@ -54,7 +54,7 @@ LL | x.unwrap(); // will panic
| ^^^^^^^^^^
error: called `unwrap` on `x` after checking its variant with `is_none`
- --> $DIR/simple_conditionals.rs:49:9
+ --> $DIR/simple_conditionals.rs:53:9
|
LL | if x.is_none() {
| -------------- help: try: `if let Some(..) = x`
@@ -63,7 +63,7 @@ LL | x.unwrap(); // unnecessary
| ^^^^^^^^^^
error: called `unwrap` on `x` after checking its variant with `is_some`
- --> $DIR/simple_conditionals.rs:8:13
+ --> $DIR/simple_conditionals.rs:12:13
|
LL | if $a.is_some() {
| --------------- help: try: `if let Some(..) = x`
@@ -76,7 +76,7 @@ LL | m!(x);
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
error: called `unwrap` on `x` after checking its variant with `is_ok`
- --> $DIR/simple_conditionals.rs:57:9
+ --> $DIR/simple_conditionals.rs:61:9
|
LL | if x.is_ok() {
| ------------ help: try: `if let Ok(..) = x`
@@ -84,7 +84,7 @@ LL | x.unwrap(); // unnecessary
| ^^^^^^^^^^
error: called `expect` on `x` after checking its variant with `is_ok`
- --> $DIR/simple_conditionals.rs:58:9
+ --> $DIR/simple_conditionals.rs:62:9
|
LL | if x.is_ok() {
| ------------ help: try: `if let Ok(..) = x`
@@ -93,7 +93,7 @@ LL | x.expect("an error message"); // unnecessary
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: this call to `unwrap_err()` will always panic
- --> $DIR/simple_conditionals.rs:59:9
+ --> $DIR/simple_conditionals.rs:63:9
|
LL | if x.is_ok() {
| --------- because of this check
@@ -102,7 +102,7 @@ LL | x.unwrap_err(); // will panic
| ^^^^^^^^^^^^^^
error: this call to `unwrap()` will always panic
- --> $DIR/simple_conditionals.rs:61:9
+ --> $DIR/simple_conditionals.rs:65:9
|
LL | if x.is_ok() {
| --------- because of this check
@@ -111,7 +111,7 @@ LL | x.unwrap(); // will panic
| ^^^^^^^^^^
error: this call to `expect()` will always panic
- --> $DIR/simple_conditionals.rs:62:9
+ --> $DIR/simple_conditionals.rs:66:9
|
LL | if x.is_ok() {
| --------- because of this check
@@ -120,7 +120,7 @@ LL | x.expect("an error message"); // will panic
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: called `unwrap_err` on `x` after checking its variant with `is_ok`
- --> $DIR/simple_conditionals.rs:63:9
+ --> $DIR/simple_conditionals.rs:67:9
|
LL | if x.is_ok() {
| ------------ help: try: `if let Err(..) = x`
@@ -129,7 +129,7 @@ LL | x.unwrap_err(); // unnecessary
| ^^^^^^^^^^^^^^
error: this call to `unwrap()` will always panic
- --> $DIR/simple_conditionals.rs:66:9
+ --> $DIR/simple_conditionals.rs:70:9
|
LL | if x.is_err() {
| ---------- because of this check
@@ -137,7 +137,7 @@ LL | x.unwrap(); // will panic
| ^^^^^^^^^^
error: called `unwrap_err` on `x` after checking its variant with `is_err`
- --> $DIR/simple_conditionals.rs:67:9
+ --> $DIR/simple_conditionals.rs:71:9
|
LL | if x.is_err() {
| ------------- help: try: `if let Err(..) = x`
@@ -146,7 +146,7 @@ LL | x.unwrap_err(); // unnecessary
| ^^^^^^^^^^^^^^
error: called `unwrap` on `x` after checking its variant with `is_err`
- --> $DIR/simple_conditionals.rs:69:9
+ --> $DIR/simple_conditionals.rs:73:9
|
LL | if x.is_err() {
| ------------- help: try: `if let Ok(..) = x`
@@ -155,7 +155,7 @@ LL | x.unwrap(); // unnecessary
| ^^^^^^^^^^
error: this call to `unwrap_err()` will always panic
- --> $DIR/simple_conditionals.rs:70:9
+ --> $DIR/simple_conditionals.rs:74:9
|
LL | if x.is_err() {
| ---------- because of this check
diff --git a/tests/ui/crashes/ice-5579.rs b/tests/ui/crashes/ice-5579.rs
index e1842c73f0e3..8ab36bbf93cb 100644
--- a/tests/ui/crashes/ice-5579.rs
+++ b/tests/ui/crashes/ice-5579.rs
@@ -1,3 +1,5 @@
+#![allow(clippy::unnecessary_literal_unwrap)]
+
trait IsErr {
fn is_err(&self, err: &str) -> bool;
}
diff --git a/tests/ui/err_expect.fixed b/tests/ui/err_expect.fixed
index 6ade6f546891..46e2816da522 100644
--- a/tests/ui/err_expect.fixed
+++ b/tests/ui/err_expect.fixed
@@ -1,6 +1,6 @@
//@run-rustfix
-#![allow(unused)]
+#![allow(unused, clippy::unnecessary_literal_unwrap)]
struct MyTypeNonDebug;
diff --git a/tests/ui/err_expect.rs b/tests/ui/err_expect.rs
index a93fb59493fe..b9446034d50a 100644
--- a/tests/ui/err_expect.rs
+++ b/tests/ui/err_expect.rs
@@ -1,6 +1,6 @@
//@run-rustfix
-#![allow(unused)]
+#![allow(unused, clippy::unnecessary_literal_unwrap)]
struct MyTypeNonDebug;
diff --git a/tests/ui/expect.rs b/tests/ui/expect.rs
index d742595e14d4..1588579bb0f2 100644
--- a/tests/ui/expect.rs
+++ b/tests/ui/expect.rs
@@ -1,4 +1,5 @@
#![warn(clippy::expect_used)]
+#![allow(clippy::unnecessary_literal_unwrap)]
fn expect_option() {
let opt = Some(0);
diff --git a/tests/ui/expect.stderr b/tests/ui/expect.stderr
index c08e0dbbf744..be340340d477 100644
--- a/tests/ui/expect.stderr
+++ b/tests/ui/expect.stderr
@@ -1,5 +1,5 @@
error: used `expect()` on an `Option` value
- --> $DIR/expect.rs:5:13
+ --> $DIR/expect.rs:6:13
|
LL | let _ = opt.expect("");
| ^^^^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL | let _ = opt.expect("");
= note: `-D clippy::expect-used` implied by `-D warnings`
error: used `expect()` on a `Result` value
- --> $DIR/expect.rs:10:13
+ --> $DIR/expect.rs:11:13
|
LL | let _ = res.expect("");
| ^^^^^^^^^^^^^^
@@ -16,7 +16,7 @@ LL | let _ = res.expect("");
= help: if this value is an `Err`, it will panic
error: used `expect_err()` on a `Result` value
- --> $DIR/expect.rs:11:13
+ --> $DIR/expect.rs:12:13
|
LL | let _ = res.expect_err("");
| ^^^^^^^^^^^^^^^^^^
diff --git a/tests/ui/expect_fun_call.fixed b/tests/ui/expect_fun_call.fixed
index 8e97054fb6bc..73c6c97de84b 100644
--- a/tests/ui/expect_fun_call.fixed
+++ b/tests/ui/expect_fun_call.fixed
@@ -1,6 +1,10 @@
//@run-rustfix
#![warn(clippy::expect_fun_call)]
-#![allow(clippy::to_string_in_format_args, clippy::uninlined_format_args)]
+#![allow(
+ clippy::to_string_in_format_args,
+ clippy::uninlined_format_args,
+ clippy::unnecessary_literal_unwrap
+)]
/// Checks implementation of the `EXPECT_FUN_CALL` lint
diff --git a/tests/ui/expect_fun_call.rs b/tests/ui/expect_fun_call.rs
index 31e6bcc7ff64..a786138631c8 100644
--- a/tests/ui/expect_fun_call.rs
+++ b/tests/ui/expect_fun_call.rs
@@ -1,6 +1,10 @@
//@run-rustfix
#![warn(clippy::expect_fun_call)]
-#![allow(clippy::to_string_in_format_args, clippy::uninlined_format_args)]
+#![allow(
+ clippy::to_string_in_format_args,
+ clippy::uninlined_format_args,
+ clippy::unnecessary_literal_unwrap
+)]
/// Checks implementation of the `EXPECT_FUN_CALL` lint
diff --git a/tests/ui/expect_fun_call.stderr b/tests/ui/expect_fun_call.stderr
index cb55e32aee02..36fb0e5de156 100644
--- a/tests/ui/expect_fun_call.stderr
+++ b/tests/ui/expect_fun_call.stderr
@@ -1,5 +1,5 @@
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:34:26
+ --> $DIR/expect_fun_call.rs:38:26
|
LL | with_none_and_format.expect(&format!("Error {}: fake error", error_code));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("Error {}: fake error", error_code))`
@@ -7,85 +7,85 @@ LL | with_none_and_format.expect(&format!("Error {}: fake error", error_code
= note: `-D clippy::expect-fun-call` implied by `-D warnings`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:37:26
+ --> $DIR/expect_fun_call.rs:41:26
|
LL | with_none_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("Error {}: fake error", error_code))`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:40:37
+ --> $DIR/expect_fun_call.rs:44:37
|
LL | with_none_and_format_with_macro.expect(format!("Error {}: fake error", one!()).as_str());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("Error {}: fake error", one!()))`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:50:25
+ --> $DIR/expect_fun_call.rs:54:25
|
LL | with_err_and_format.expect(&format!("Error {}: fake error", error_code));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| panic!("Error {}: fake error", error_code))`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:53:25
+ --> $DIR/expect_fun_call.rs:57:25
|
LL | with_err_and_as_str.expect(format!("Error {}: fake error", error_code).as_str());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| panic!("Error {}: fake error", error_code))`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:65:17
+ --> $DIR/expect_fun_call.rs:69:17
|
LL | Some("foo").expect(format!("{} {}", 1, 2).as_ref());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("{} {}", 1, 2))`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:86:21
+ --> $DIR/expect_fun_call.rs:90:21
|
LL | Some("foo").expect(&get_string());
| ^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_string()) })`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:87:21
+ --> $DIR/expect_fun_call.rs:91:21
|
LL | Some("foo").expect(get_string().as_ref());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_string()) })`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:88:21
+ --> $DIR/expect_fun_call.rs:92:21
|
LL | Some("foo").expect(get_string().as_str());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_string()) })`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:90:21
+ --> $DIR/expect_fun_call.rs:94:21
|
LL | Some("foo").expect(get_static_str());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_static_str()) })`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:91:21
+ --> $DIR/expect_fun_call.rs:95:21
|
LL | Some("foo").expect(get_non_static_str(&0));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| { panic!("{}", get_non_static_str(&0).to_string()) })`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:95:16
+ --> $DIR/expect_fun_call.rs:99:16
|
LL | Some(true).expect(&format!("key {}, {}", 1, 2));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("key {}, {}", 1, 2))`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:101:17
+ --> $DIR/expect_fun_call.rs:105:17
|
LL | opt_ref.expect(&format!("{:?}", opt_ref));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("{:?}", opt_ref))`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:105:20
+ --> $DIR/expect_fun_call.rs:109:20
|
LL | format_capture.expect(&format!("{error_code}"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("{error_code}"))`
error: use of `expect` followed by a function call
- --> $DIR/expect_fun_call.rs:108:30
+ --> $DIR/expect_fun_call.rs:112:30
|
LL | format_capture_and_value.expect(&format!("{error_code}, {}", 1));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("{error_code}, {}", 1))`
diff --git a/tests/ui/explicit_deref_methods.fixed b/tests/ui/explicit_deref_methods.fixed
index 1710b170fb81..4d72b58cdf86 100644
--- a/tests/ui/explicit_deref_methods.fixed
+++ b/tests/ui/explicit_deref_methods.fixed
@@ -7,7 +7,8 @@
clippy::explicit_auto_deref,
clippy::needless_borrow,
clippy::no_effect,
- clippy::uninlined_format_args
+ clippy::uninlined_format_args,
+ clippy::unnecessary_literal_unwrap
)]
use std::ops::{Deref, DerefMut};
diff --git a/tests/ui/explicit_deref_methods.rs b/tests/ui/explicit_deref_methods.rs
index 85147e1cb697..fcd945de3386 100644
--- a/tests/ui/explicit_deref_methods.rs
+++ b/tests/ui/explicit_deref_methods.rs
@@ -7,7 +7,8 @@
clippy::explicit_auto_deref,
clippy::needless_borrow,
clippy::no_effect,
- clippy::uninlined_format_args
+ clippy::uninlined_format_args,
+ clippy::unnecessary_literal_unwrap
)]
use std::ops::{Deref, DerefMut};
diff --git a/tests/ui/explicit_deref_methods.stderr b/tests/ui/explicit_deref_methods.stderr
index 592563ffa8c8..d025035b7894 100644
--- a/tests/ui/explicit_deref_methods.stderr
+++ b/tests/ui/explicit_deref_methods.stderr
@@ -1,5 +1,5 @@
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:53:19
+ --> $DIR/explicit_deref_methods.rs:54:19
|
LL | let b: &str = a.deref();
| ^^^^^^^^^ help: try this: `&*a`
@@ -7,67 +7,67 @@ LL | let b: &str = a.deref();
= note: `-D clippy::explicit-deref-methods` implied by `-D warnings`
error: explicit `deref_mut` method call
- --> $DIR/explicit_deref_methods.rs:55:23
+ --> $DIR/explicit_deref_methods.rs:56:23
|
LL | let b: &mut str = a.deref_mut();
| ^^^^^^^^^^^^^ help: try this: `&mut **a`
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:58:39
+ --> $DIR/explicit_deref_methods.rs:59:39
|
LL | let b: String = format!("{}, {}", a.deref(), a.deref());
| ^^^^^^^^^ help: try this: `&*a`
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:58:50
+ --> $DIR/explicit_deref_methods.rs:59:50
|
LL | let b: String = format!("{}, {}", a.deref(), a.deref());
| ^^^^^^^^^ help: try this: `&*a`
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:60:20
+ --> $DIR/explicit_deref_methods.rs:61:20
|
LL | println!("{}", a.deref());
| ^^^^^^^^^ help: try this: `&*a`
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:63:11
+ --> $DIR/explicit_deref_methods.rs:64:11
|
LL | match a.deref() {
| ^^^^^^^^^ help: try this: `&*a`
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:67:28
+ --> $DIR/explicit_deref_methods.rs:68:28
|
LL | let b: String = concat(a.deref());
| ^^^^^^^^^ help: try this: `&*a`
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:69:13
+ --> $DIR/explicit_deref_methods.rs:70:13
|
LL | let b = just_return(a).deref();
| ^^^^^^^^^^^^^^^^^^^^^^ help: try this: `just_return(a)`
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:71:28
+ --> $DIR/explicit_deref_methods.rs:72:28
|
LL | let b: String = concat(just_return(a).deref());
| ^^^^^^^^^^^^^^^^^^^^^^ help: try this: `just_return(a)`
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:73:19
+ --> $DIR/explicit_deref_methods.rs:74:19
|
LL | let b: &str = a.deref().deref();
| ^^^^^^^^^^^^^^^^^ help: try this: `&**a`
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:76:13
+ --> $DIR/explicit_deref_methods.rs:77:13
|
LL | let b = opt_a.unwrap().deref();
| ^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&*opt_a.unwrap()`
error: explicit `deref` method call
- --> $DIR/explicit_deref_methods.rs:113:31
+ --> $DIR/explicit_deref_methods.rs:114:31
|
LL | let b: &str = expr_deref!(a.deref());
| ^^^^^^^^^ help: try this: `&*a`
diff --git a/tests/ui/manual_unwrap_or.fixed b/tests/ui/manual_unwrap_or.fixed
index c17634bffe30..20560b87c1a5 100644
--- a/tests/ui/manual_unwrap_or.fixed
+++ b/tests/ui/manual_unwrap_or.fixed
@@ -1,6 +1,6 @@
//@run-rustfix
#![allow(dead_code)]
-#![allow(unused_variables, clippy::unnecessary_wraps)]
+#![allow(unused_variables, clippy::unnecessary_wraps, clippy::unnecessary_literal_unwrap)]
fn option_unwrap_or() {
// int case
diff --git a/tests/ui/manual_unwrap_or.rs b/tests/ui/manual_unwrap_or.rs
index 6d49a6949fa9..5dbc57565bff 100644
--- a/tests/ui/manual_unwrap_or.rs
+++ b/tests/ui/manual_unwrap_or.rs
@@ -1,6 +1,6 @@
//@run-rustfix
#![allow(dead_code)]
-#![allow(unused_variables, clippy::unnecessary_wraps)]
+#![allow(unused_variables, clippy::unnecessary_wraps, clippy::unnecessary_literal_unwrap)]
fn option_unwrap_or() {
// int case
diff --git a/tests/ui/missing_panics_doc.rs b/tests/ui/missing_panics_doc.rs
index 7dc44529206d..10aa436d6cdc 100644
--- a/tests/ui/missing_panics_doc.rs
+++ b/tests/ui/missing_panics_doc.rs
@@ -1,5 +1,5 @@
#![warn(clippy::missing_panics_doc)]
-#![allow(clippy::option_map_unit_fn)]
+#![allow(clippy::option_map_unit_fn, clippy::unnecessary_literal_unwrap)]
fn main() {}
/// This needs to be documented
diff --git a/tests/ui/needless_borrow.fixed b/tests/ui/needless_borrow.fixed
index 425e6eb6200e..80cdb4e472d4 100644
--- a/tests/ui/needless_borrow.fixed
+++ b/tests/ui/needless_borrow.fixed
@@ -4,7 +4,8 @@
unused,
clippy::uninlined_format_args,
clippy::unnecessary_mut_passed,
- clippy::unnecessary_to_owned
+ clippy::unnecessary_to_owned,
+ clippy::unnecessary_literal_unwrap
)]
#![warn(clippy::needless_borrow)]
diff --git a/tests/ui/needless_borrow.rs b/tests/ui/needless_borrow.rs
index 3f7fa4a9d7dc..99f735127eb8 100644
--- a/tests/ui/needless_borrow.rs
+++ b/tests/ui/needless_borrow.rs
@@ -4,7 +4,8 @@
unused,
clippy::uninlined_format_args,
clippy::unnecessary_mut_passed,
- clippy::unnecessary_to_owned
+ clippy::unnecessary_to_owned,
+ clippy::unnecessary_literal_unwrap
)]
#![warn(clippy::needless_borrow)]
diff --git a/tests/ui/needless_borrow.stderr b/tests/ui/needless_borrow.stderr
index d26c317124b8..f85b4fb46a65 100644
--- a/tests/ui/needless_borrow.stderr
+++ b/tests/ui/needless_borrow.stderr
@@ -1,5 +1,5 @@
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:15:15
+ --> $DIR/needless_borrow.rs:16:15
|
LL | let _ = x(&&a); // warn
| ^^^ help: change this to: `&a`
@@ -7,211 +7,211 @@ LL | let _ = x(&&a); // warn
= note: `-D clippy::needless-borrow` implied by `-D warnings`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:19:13
+ --> $DIR/needless_borrow.rs:20:13
|
LL | mut_ref(&mut &mut b); // warn
| ^^^^^^^^^^^ help: change this to: `&mut b`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:31:13
+ --> $DIR/needless_borrow.rs:32:13
|
LL | &&a
| ^^^ help: change this to: `&a`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:33:15
+ --> $DIR/needless_borrow.rs:34:15
|
LL | 46 => &&a,
| ^^^ help: change this to: `&a`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:39:27
+ --> $DIR/needless_borrow.rs:40:27
|
LL | break &ref_a;
| ^^^^^^ help: change this to: `ref_a`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:46:15
+ --> $DIR/needless_borrow.rs:47:15
|
LL | let _ = x(&&&a);
| ^^^^ help: change this to: `&a`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:47:15
+ --> $DIR/needless_borrow.rs:48:15
|
LL | let _ = x(&mut &&a);
| ^^^^^^^^ help: change this to: `&a`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:48:15
+ --> $DIR/needless_borrow.rs:49:15
|
LL | let _ = x(&&&mut b);
| ^^^^^^^^ help: change this to: `&mut b`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:49:15
+ --> $DIR/needless_borrow.rs:50:15
|
LL | let _ = x(&&ref_a);
| ^^^^^^^ help: change this to: `ref_a`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:52:11
+ --> $DIR/needless_borrow.rs:53:11
|
LL | x(&b);
| ^^ help: change this to: `b`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:59:13
+ --> $DIR/needless_borrow.rs:60:13
|
LL | mut_ref(&mut x);
| ^^^^^^ help: change this to: `x`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:60:13
+ --> $DIR/needless_borrow.rs:61:13
|
LL | mut_ref(&mut &mut x);
| ^^^^^^^^^^^ help: change this to: `x`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:61:23
+ --> $DIR/needless_borrow.rs:62:23
|
LL | let y: &mut i32 = &mut x;
| ^^^^^^ help: change this to: `x`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:62:23
+ --> $DIR/needless_borrow.rs:63:23
|
LL | let y: &mut i32 = &mut &mut x;
| ^^^^^^^^^^^ help: change this to: `x`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:71:14
+ --> $DIR/needless_borrow.rs:72:14
|
LL | 0 => &mut x,
| ^^^^^^ help: change this to: `x`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:77:14
+ --> $DIR/needless_borrow.rs:78:14
|
LL | 0 => &mut x,
| ^^^^^^ help: change this to: `x`
error: this expression borrows a value the compiler would automatically borrow
- --> $DIR/needless_borrow.rs:89:13
+ --> $DIR/needless_borrow.rs:90:13
|
LL | let _ = (&x).0;
| ^^^^ help: change this to: `x`
error: this expression borrows a value the compiler would automatically borrow
- --> $DIR/needless_borrow.rs:91:22
+ --> $DIR/needless_borrow.rs:92:22
|
LL | let _ = unsafe { (&*x).0 };
| ^^^^^ help: change this to: `(*x)`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:101:5
+ --> $DIR/needless_borrow.rs:102:5
|
LL | (&&()).foo();
| ^^^^^^ help: change this to: `(&())`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:110:5
+ --> $DIR/needless_borrow.rs:111:5
|
LL | (&&5).foo();
| ^^^^^ help: change this to: `(&5)`
error: the borrowed expression implements the required traits
- --> $DIR/needless_borrow.rs:135:51
+ --> $DIR/needless_borrow.rs:136:51
|
LL | let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap();
| ^^^^^^^^^^^^^ help: change this to: `["-a", "-l"]`
error: the borrowed expression implements the required traits
- --> $DIR/needless_borrow.rs:136:44
+ --> $DIR/needless_borrow.rs:137:44
|
LL | let _ = std::path::Path::new(".").join(&&".");
| ^^^^^ help: change this to: `"."`
error: the borrowed expression implements the required traits
- --> $DIR/needless_borrow.rs:137:23
+ --> $DIR/needless_borrow.rs:138:23
|
LL | deref_target_is_x(&X);
| ^^ help: change this to: `X`
error: the borrowed expression implements the required traits
- --> $DIR/needless_borrow.rs:138:26
+ --> $DIR/needless_borrow.rs:139:26
|
LL | multiple_constraints(&[[""]]);
| ^^^^^^^ help: change this to: `[[""]]`
error: the borrowed expression implements the required traits
- --> $DIR/needless_borrow.rs:139:45
+ --> $DIR/needless_borrow.rs:140:45
|
LL | multiple_constraints_normalizes_to_same(&X, X);
| ^^ help: change this to: `X`
error: this expression creates a reference which is immediately dereferenced by the compiler
- --> $DIR/needless_borrow.rs:140:32
+ --> $DIR/needless_borrow.rs:141:32
|
LL | let _ = Some("").unwrap_or(&"");
| ^^^ help: change this to: `""`
error: the borrowed expression implements the required traits
- --> $DIR/needless_borrow.rs:141:33
+ --> $DIR/needless_borrow.rs:142:33
|
LL | let _ = std::fs::write("x", &"".to_string());
| ^^^^^^^^^^^^^^^ help: change this to: `"".to_string()`
error: this expression borrows a value the compiler would automatically borrow
- --> $DIR/needless_borrow.rs:190:13
+ --> $DIR/needless_borrow.rs:191:13
|
LL | (&self.f)()
| ^^^^^^^^^ help: change this to: `(self.f)`
error: this expression borrows a value the compiler would automatically borrow
- --> $DIR/needless_borrow.rs:199:13
+ --> $DIR/needless_borrow.rs:200:13
|
LL | (&mut self.f)()
| ^^^^^^^^^^^^^ help: change this to: `(self.f)`
error: the borrowed expression implements the required traits
- --> $DIR/needless_borrow.rs:283:20
+ --> $DIR/needless_borrow.rs:284:20
|
LL | takes_iter(&mut x)
| ^^^^^^ help: change this to: `x`
error: the borrowed expression implements the required traits
- --> $DIR/needless_borrow.rs:297:55
+ --> $DIR/needless_borrow.rs:298:55
|
LL | let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap();
| ^^^^^^^^^^^^^ help: change this to: `["-a", "-l"]`
error: the borrowed expression implements the required traits
- --> $DIR/needless_borrow.rs:335:37
+ --> $DIR/needless_borrow.rs:336:37
|
LL | let _ = std::fs::write("x", &arg);
| ^^^^ help: change this to: `arg`
error: the borrowed expression implements the required traits
- --> $DIR/needless_borrow.rs:336:37
+ --> $DIR/needless_borrow.rs:337:37
|
LL | let _ = std::fs::write("x", &loc);
| ^^^^ help: change this to: `loc`
error: the borrowed expression implements the required traits
- --> $DIR/needless_borrow.rs:354:15
+ --> $DIR/needless_borrow.rs:355:15
|
LL | debug(&x);
| ^^ help: change this to: `x`
error: the borrowed expression implements the required traits
- --> $DIR/needless_borrow.rs:363:15
+ --> $DIR/needless_borrow.rs:364:15
|
LL | use_x(&x);
| ^^ help: change this to: `x`
error: the borrowed expression implements the required traits
- --> $DIR/needless_borrow.rs:457:13
+ --> $DIR/needless_borrow.rs:458:13
|
LL | foo(&a);
| ^^ help: change this to: `a`
diff --git a/tests/ui/needless_range_loop.rs b/tests/ui/needless_range_loop.rs
index 1935ccb94bd5..a16ef5a5bca9 100644
--- a/tests/ui/needless_range_loop.rs
+++ b/tests/ui/needless_range_loop.rs
@@ -1,5 +1,9 @@
#![warn(clippy::needless_range_loop)]
-#![allow(clippy::uninlined_format_args, clippy::useless_vec)]
+#![allow(
+ clippy::uninlined_format_args,
+ clippy::unnecessary_literal_unwrap,
+ clippy::useless_vec
+)]
static STATIC: [usize; 4] = [0, 1, 8, 16];
const CONST: [usize; 4] = [0, 1, 8, 16];
diff --git a/tests/ui/needless_range_loop.stderr b/tests/ui/needless_range_loop.stderr
index cffa19bec3a6..8ca6b880ceae 100644
--- a/tests/ui/needless_range_loop.stderr
+++ b/tests/ui/needless_range_loop.stderr
@@ -1,5 +1,5 @@
error: the loop variable `i` is only used to index `vec`
- --> $DIR/needless_range_loop.rs:11:14
+ --> $DIR/needless_range_loop.rs:15:14
|
LL | for i in 0..vec.len() {
| ^^^^^^^^^^^^
@@ -11,7 +11,7 @@ LL | for - in &vec {
| ~~~~~~ ~~~~
error: the loop variable `i` is only used to index `vec`
- --> $DIR/needless_range_loop.rs:20:14
+ --> $DIR/needless_range_loop.rs:24:14
|
LL | for i in 0..vec.len() {
| ^^^^^^^^^^^^
@@ -22,7 +22,7 @@ LL | for
- in &vec {
| ~~~~~~ ~~~~
error: the loop variable `j` is only used to index `STATIC`
- --> $DIR/needless_range_loop.rs:25:14
+ --> $DIR/needless_range_loop.rs:29:14
|
LL | for j in 0..4 {
| ^^^^
@@ -33,7 +33,7 @@ LL | for
- in &STATIC {
| ~~~~~~ ~~~~~~~
error: the loop variable `j` is only used to index `CONST`
- --> $DIR/needless_range_loop.rs:29:14
+ --> $DIR/needless_range_loop.rs:33:14
|
LL | for j in 0..4 {
| ^^^^
@@ -44,7 +44,7 @@ LL | for
- in &CONST {
| ~~~~~~ ~~~~~~
error: the loop variable `i` is used to index `vec`
- --> $DIR/needless_range_loop.rs:33:14
+ --> $DIR/needless_range_loop.rs:37:14
|
LL | for i in 0..vec.len() {
| ^^^^^^^^^^^^
@@ -55,7 +55,7 @@ LL | for (i,
- ) in vec.iter().enumerate() {
| ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~
error: the loop variable `i` is only used to index `vec2`
- --> $DIR/needless_range_loop.rs:41:14
+ --> $DIR/needless_range_loop.rs:45:14
|
LL | for i in 0..vec.len() {
| ^^^^^^^^^^^^
@@ -66,7 +66,7 @@ LL | for
- in vec2.iter().take(vec.len()) {
| ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: the loop variable `i` is only used to index `vec`
- --> $DIR/needless_range_loop.rs:45:14
+ --> $DIR/needless_range_loop.rs:49:14
|
LL | for i in 5..vec.len() {
| ^^^^^^^^^^^^
@@ -77,7 +77,7 @@ LL | for
- in vec.iter().skip(5) {
| ~~~~~~ ~~~~~~~~~~~~~~~~~~
error: the loop variable `i` is only used to index `vec`
- --> $DIR/needless_range_loop.rs:49:14
+ --> $DIR/needless_range_loop.rs:53:14
|
LL | for i in 0..MAX_LEN {
| ^^^^^^^^^^
@@ -88,7 +88,7 @@ LL | for
- in vec.iter().take(MAX_LEN) {
| ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~
error: the loop variable `i` is only used to index `vec`
- --> $DIR/needless_range_loop.rs:53:14
+ --> $DIR/needless_range_loop.rs:57:14
|
LL | for i in 0..=MAX_LEN {
| ^^^^^^^^^^^
@@ -99,7 +99,7 @@ LL | for
- in vec.iter().take(MAX_LEN + 1) {
| ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: the loop variable `i` is only used to index `vec`
- --> $DIR/needless_range_loop.rs:57:14
+ --> $DIR/needless_range_loop.rs:61:14
|
LL | for i in 5..10 {
| ^^^^^
@@ -110,7 +110,7 @@ LL | for
- in vec.iter().take(10).skip(5) {
| ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: the loop variable `i` is only used to index `vec`
- --> $DIR/needless_range_loop.rs:61:14
+ --> $DIR/needless_range_loop.rs:65:14
|
LL | for i in 5..=10 {
| ^^^^^^
@@ -121,7 +121,7 @@ LL | for
- in vec.iter().take(10 + 1).skip(5) {
| ~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: the loop variable `i` is used to index `vec`
- --> $DIR/needless_range_loop.rs:65:14
+ --> $DIR/needless_range_loop.rs:69:14
|
LL | for i in 5..vec.len() {
| ^^^^^^^^^^^^
@@ -132,7 +132,7 @@ LL | for (i,
- ) in vec.iter().enumerate().skip(5) {
| ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: the loop variable `i` is used to index `vec`
- --> $DIR/needless_range_loop.rs:69:14
+ --> $DIR/needless_range_loop.rs:73:14
|
LL | for i in 5..10 {
| ^^^^^
@@ -143,7 +143,7 @@ LL | for (i,
- ) in vec.iter().enumerate().take(10).skip(5) {
| ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: the loop variable `i` is used to index `vec`
- --> $DIR/needless_range_loop.rs:74:14
+ --> $DIR/needless_range_loop.rs:78:14
|
LL | for i in 0..vec.len() {
| ^^^^^^^^^^^^
diff --git a/tests/ui/ok_expect.rs b/tests/ui/ok_expect.rs
index ff68d38c73bf..2047ee689d95 100644
--- a/tests/ui/ok_expect.rs
+++ b/tests/ui/ok_expect.rs
@@ -1,3 +1,5 @@
+#![allow(clippy::unnecessary_literal_unwrap)]
+
use std::io;
struct MyError(()); // doesn't implement Debug
diff --git a/tests/ui/ok_expect.stderr b/tests/ui/ok_expect.stderr
index 6c40adbb53dc..ab9df26ebc37 100644
--- a/tests/ui/ok_expect.stderr
+++ b/tests/ui/ok_expect.stderr
@@ -1,5 +1,5 @@
error: called `ok().expect()` on a `Result` value
- --> $DIR/ok_expect.rs:14:5
+ --> $DIR/ok_expect.rs:16:5
|
LL | res.ok().expect("disaster!");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL | res.ok().expect("disaster!");
= note: `-D clippy::ok-expect` implied by `-D warnings`
error: called `ok().expect()` on a `Result` value
- --> $DIR/ok_expect.rs:20:5
+ --> $DIR/ok_expect.rs:22:5
|
LL | res3.ok().expect("whoof");
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -16,7 +16,7 @@ LL | res3.ok().expect("whoof");
= help: you can call `expect()` directly on the `Result`
error: called `ok().expect()` on a `Result` value
- --> $DIR/ok_expect.rs:22:5
+ --> $DIR/ok_expect.rs:24:5
|
LL | res4.ok().expect("argh");
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -24,7 +24,7 @@ LL | res4.ok().expect("argh");
= help: you can call `expect()` directly on the `Result`
error: called `ok().expect()` on a `Result` value
- --> $DIR/ok_expect.rs:24:5
+ --> $DIR/ok_expect.rs:26:5
|
LL | res5.ok().expect("oops");
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -32,7 +32,7 @@ LL | res5.ok().expect("oops");
= help: you can call `expect()` directly on the `Result`
error: called `ok().expect()` on a `Result` value
- --> $DIR/ok_expect.rs:26:5
+ --> $DIR/ok_expect.rs:28:5
|
LL | res6.ok().expect("meh");
| ^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/tests/ui/or_fun_call.fixed b/tests/ui/or_fun_call.fixed
index 08a536a28443..703debb7a26a 100644
--- a/tests/ui/or_fun_call.fixed
+++ b/tests/ui/or_fun_call.fixed
@@ -5,6 +5,7 @@
clippy::borrow_as_ptr,
clippy::uninlined_format_args,
clippy::unnecessary_wraps,
+ clippy::unnecessary_literal_unwrap,
clippy::useless_vec
)]
diff --git a/tests/ui/or_fun_call.rs b/tests/ui/or_fun_call.rs
index 83ba68382efb..bb86fe0d45fa 100644
--- a/tests/ui/or_fun_call.rs
+++ b/tests/ui/or_fun_call.rs
@@ -5,6 +5,7 @@
clippy::borrow_as_ptr,
clippy::uninlined_format_args,
clippy::unnecessary_wraps,
+ clippy::unnecessary_literal_unwrap,
clippy::useless_vec
)]
diff --git a/tests/ui/or_fun_call.stderr b/tests/ui/or_fun_call.stderr
index ec87674b100f..0b5c686bec0d 100644
--- a/tests/ui/or_fun_call.stderr
+++ b/tests/ui/or_fun_call.stderr
@@ -1,5 +1,5 @@
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:53:22
+ --> $DIR/or_fun_call.rs:54:22
|
LL | with_constructor.unwrap_or(make());
| ^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(make)`
@@ -7,163 +7,163 @@ LL | with_constructor.unwrap_or(make());
= note: `-D clippy::or-fun-call` implied by `-D warnings`
error: use of `unwrap_or` followed by a call to `new`
- --> $DIR/or_fun_call.rs:56:14
+ --> $DIR/or_fun_call.rs:57:14
|
LL | with_new.unwrap_or(Vec::new());
| ^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:59:21
+ --> $DIR/or_fun_call.rs:60:21
|
LL | with_const_args.unwrap_or(Vec::with_capacity(12));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| Vec::with_capacity(12))`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:62:14
+ --> $DIR/or_fun_call.rs:63:14
|
LL | with_err.unwrap_or(make());
| ^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| make())`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:65:19
+ --> $DIR/or_fun_call.rs:66:19
|
LL | with_err_args.unwrap_or(Vec::with_capacity(12));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|_| Vec::with_capacity(12))`
error: use of `unwrap_or` followed by a call to `default`
- --> $DIR/or_fun_call.rs:68:24
+ --> $DIR/or_fun_call.rs:69:24
|
LL | with_default_trait.unwrap_or(Default::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
error: use of `unwrap_or` followed by a call to `default`
- --> $DIR/or_fun_call.rs:71:23
+ --> $DIR/or_fun_call.rs:72:23
|
LL | with_default_type.unwrap_or(u64::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:74:18
+ --> $DIR/or_fun_call.rs:75:18
|
LL | self_default.unwrap_or(::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(::default)`
error: use of `unwrap_or` followed by a call to `default`
- --> $DIR/or_fun_call.rs:77:18
+ --> $DIR/or_fun_call.rs:78:18
|
LL | real_default.unwrap_or(::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
error: use of `unwrap_or` followed by a call to `new`
- --> $DIR/or_fun_call.rs:80:14
+ --> $DIR/or_fun_call.rs:81:14
|
LL | with_vec.unwrap_or(vec![]);
| ^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:83:21
+ --> $DIR/or_fun_call.rs:84:21
|
LL | without_default.unwrap_or(Foo::new());
| ^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(Foo::new)`
error: use of `or_insert` followed by a call to `new`
- --> $DIR/or_fun_call.rs:86:19
+ --> $DIR/or_fun_call.rs:87:19
|
LL | map.entry(42).or_insert(String::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_default()`
error: use of `or_insert` followed by a call to `new`
- --> $DIR/or_fun_call.rs:89:23
+ --> $DIR/or_fun_call.rs:90:23
|
LL | map_vec.entry(42).or_insert(vec![]);
| ^^^^^^^^^^^^^^^^^ help: try this: `or_default()`
error: use of `or_insert` followed by a call to `new`
- --> $DIR/or_fun_call.rs:92:21
+ --> $DIR/or_fun_call.rs:93:21
|
LL | btree.entry(42).or_insert(String::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_default()`
error: use of `or_insert` followed by a call to `new`
- --> $DIR/or_fun_call.rs:95:25
+ --> $DIR/or_fun_call.rs:96:25
|
LL | btree_vec.entry(42).or_insert(vec![]);
| ^^^^^^^^^^^^^^^^^ help: try this: `or_default()`
error: use of `unwrap_or` followed by a call to `new`
- --> $DIR/or_fun_call.rs:98:21
+ --> $DIR/or_fun_call.rs:99:21
|
LL | let _ = stringy.unwrap_or(String::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:106:21
+ --> $DIR/or_fun_call.rs:107:21
|
LL | let _ = Some(1).unwrap_or(map[&1]);
| ^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| map[&1])`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:108:21
+ --> $DIR/or_fun_call.rs:109:21
|
LL | let _ = Some(1).unwrap_or(map[&1]);
| ^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| map[&1])`
error: use of `or` followed by a function call
- --> $DIR/or_fun_call.rs:132:35
+ --> $DIR/or_fun_call.rs:133:35
|
LL | let _ = Some("a".to_string()).or(Some("b".to_string()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_else(|| Some("b".to_string()))`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:171:14
+ --> $DIR/or_fun_call.rs:172:14
|
LL | None.unwrap_or(ptr_to_ref(s));
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| ptr_to_ref(s))`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:177:14
+ --> $DIR/or_fun_call.rs:178:14
|
LL | None.unwrap_or(unsafe { ptr_to_ref(s) });
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| unsafe { ptr_to_ref(s) })`
error: use of `unwrap_or` followed by a function call
- --> $DIR/or_fun_call.rs:179:14
+ --> $DIR/or_fun_call.rs:180:14
|
LL | None.unwrap_or( unsafe { ptr_to_ref(s) } );
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| unsafe { ptr_to_ref(s) })`
error: use of `unwrap_or` followed by a call to `new`
- --> $DIR/or_fun_call.rs:193:14
+ --> $DIR/or_fun_call.rs:194:14
|
LL | .unwrap_or(String::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
error: use of `unwrap_or` followed by a call to `new`
- --> $DIR/or_fun_call.rs:206:14
+ --> $DIR/or_fun_call.rs:207:14
|
LL | .unwrap_or(String::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
error: use of `unwrap_or` followed by a call to `new`
- --> $DIR/or_fun_call.rs:218:14
+ --> $DIR/or_fun_call.rs:219:14
|
LL | .unwrap_or(String::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
error: use of `unwrap_or` followed by a call to `new`
- --> $DIR/or_fun_call.rs:229:10
+ --> $DIR/or_fun_call.rs:230:10
|
LL | .unwrap_or(String::new());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_default()`
error: use of `map_or` followed by a function call
- --> $DIR/or_fun_call.rs:254:25
+ --> $DIR/or_fun_call.rs:255:25
|
LL | let _ = Some(4).map_or(g(), |v| v);
| ^^^^^^^^^^^^^^^^^^ help: try this: `map_or_else(g, |v| v)`
error: use of `map_or` followed by a function call
- --> $DIR/or_fun_call.rs:255:25
+ --> $DIR/or_fun_call.rs:256:25
|
LL | let _ = Some(4).map_or(g(), f);
| ^^^^^^^^^^^^^^ help: try this: `map_or_else(g, f)`
diff --git a/tests/ui/or_then_unwrap.fixed b/tests/ui/or_then_unwrap.fixed
index 40badac4424a..773dfc3c5d14 100644
--- a/tests/ui/or_then_unwrap.fixed
+++ b/tests/ui/or_then_unwrap.fixed
@@ -1,7 +1,7 @@
//@run-rustfix
#![warn(clippy::or_then_unwrap)]
-#![allow(clippy::map_identity, clippy::let_unit_value)]
+#![allow(clippy::map_identity, clippy::let_unit_value, clippy::unnecessary_literal_unwrap)]
struct SomeStruct;
impl SomeStruct {
diff --git a/tests/ui/or_then_unwrap.rs b/tests/ui/or_then_unwrap.rs
index 76c9942fe6c1..5867e014878e 100644
--- a/tests/ui/or_then_unwrap.rs
+++ b/tests/ui/or_then_unwrap.rs
@@ -1,7 +1,7 @@
//@run-rustfix
#![warn(clippy::or_then_unwrap)]
-#![allow(clippy::map_identity, clippy::let_unit_value)]
+#![allow(clippy::map_identity, clippy::let_unit_value, clippy::unnecessary_literal_unwrap)]
struct SomeStruct;
impl SomeStruct {
diff --git a/tests/ui/redundant_clone.fixed b/tests/ui/redundant_clone.fixed
index cb9583aa6ee3..5037c08ebd5f 100644
--- a/tests/ui/redundant_clone.fixed
+++ b/tests/ui/redundant_clone.fixed
@@ -2,7 +2,12 @@
// rustfix-only-machine-applicable
#![feature(lint_reasons)]
#![warn(clippy::redundant_clone)]
-#![allow(clippy::drop_non_drop, clippy::implicit_clone, clippy::uninlined_format_args)]
+#![allow(
+ clippy::drop_non_drop,
+ clippy::implicit_clone,
+ clippy::uninlined_format_args,
+ clippy::unnecessary_literal_unwrap
+)]
use std::ffi::OsString;
use std::path::Path;
diff --git a/tests/ui/redundant_clone.rs b/tests/ui/redundant_clone.rs
index e5aeacbb56ce..501898bf113c 100644
--- a/tests/ui/redundant_clone.rs
+++ b/tests/ui/redundant_clone.rs
@@ -2,7 +2,12 @@
// rustfix-only-machine-applicable
#![feature(lint_reasons)]
#![warn(clippy::redundant_clone)]
-#![allow(clippy::drop_non_drop, clippy::implicit_clone, clippy::uninlined_format_args)]
+#![allow(
+ clippy::drop_non_drop,
+ clippy::implicit_clone,
+ clippy::uninlined_format_args,
+ clippy::unnecessary_literal_unwrap
+)]
use std::ffi::OsString;
use std::path::Path;
diff --git a/tests/ui/redundant_clone.stderr b/tests/ui/redundant_clone.stderr
index bb5c602d63a0..8660c0e1f6a0 100644
--- a/tests/ui/redundant_clone.stderr
+++ b/tests/ui/redundant_clone.stderr
@@ -1,180 +1,180 @@
error: redundant clone
- --> $DIR/redundant_clone.rs:11:42
+ --> $DIR/redundant_clone.rs:16:42
|
LL | let _s = ["lorem", "ipsum"].join(" ").to_string();
| ^^^^^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:11:14
+ --> $DIR/redundant_clone.rs:16:14
|
LL | let _s = ["lorem", "ipsum"].join(" ").to_string();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: `-D clippy::redundant-clone` implied by `-D warnings`
error: redundant clone
- --> $DIR/redundant_clone.rs:14:15
+ --> $DIR/redundant_clone.rs:19:15
|
LL | let _s = s.clone();
| ^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:14:14
+ --> $DIR/redundant_clone.rs:19:14
|
LL | let _s = s.clone();
| ^
error: redundant clone
- --> $DIR/redundant_clone.rs:17:15
+ --> $DIR/redundant_clone.rs:22:15
|
LL | let _s = s.to_string();
| ^^^^^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:17:14
+ --> $DIR/redundant_clone.rs:22:14
|
LL | let _s = s.to_string();
| ^
error: redundant clone
- --> $DIR/redundant_clone.rs:20:15
+ --> $DIR/redundant_clone.rs:25:15
|
LL | let _s = s.to_owned();
| ^^^^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:20:14
+ --> $DIR/redundant_clone.rs:25:14
|
LL | let _s = s.to_owned();
| ^
error: redundant clone
- --> $DIR/redundant_clone.rs:22:42
+ --> $DIR/redundant_clone.rs:27:42
|
LL | let _s = Path::new("/a/b/").join("c").to_owned();
| ^^^^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:22:14
+ --> $DIR/redundant_clone.rs:27:14
|
LL | let _s = Path::new("/a/b/").join("c").to_owned();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: redundant clone
- --> $DIR/redundant_clone.rs:24:42
+ --> $DIR/redundant_clone.rs:29:42
|
LL | let _s = Path::new("/a/b/").join("c").to_path_buf();
| ^^^^^^^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:24:14
+ --> $DIR/redundant_clone.rs:29:14
|
LL | let _s = Path::new("/a/b/").join("c").to_path_buf();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: redundant clone
- --> $DIR/redundant_clone.rs:26:29
+ --> $DIR/redundant_clone.rs:31:29
|
LL | let _s = OsString::new().to_owned();
| ^^^^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:26:14
+ --> $DIR/redundant_clone.rs:31:14
|
LL | let _s = OsString::new().to_owned();
| ^^^^^^^^^^^^^^^
error: redundant clone
- --> $DIR/redundant_clone.rs:28:29
+ --> $DIR/redundant_clone.rs:33:29
|
LL | let _s = OsString::new().to_os_string();
| ^^^^^^^^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:28:14
+ --> $DIR/redundant_clone.rs:33:14
|
LL | let _s = OsString::new().to_os_string();
| ^^^^^^^^^^^^^^^
error: redundant clone
- --> $DIR/redundant_clone.rs:39:19
+ --> $DIR/redundant_clone.rs:44:19
|
LL | let _t = tup.0.clone();
| ^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:39:14
+ --> $DIR/redundant_clone.rs:44:14
|
LL | let _t = tup.0.clone();
| ^^^^^
error: redundant clone
- --> $DIR/redundant_clone.rs:71:25
+ --> $DIR/redundant_clone.rs:76:25
|
LL | if b { (a.clone(), a.clone()) } else { (Alpha, a) }
| ^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:71:24
+ --> $DIR/redundant_clone.rs:76:24
|
LL | if b { (a.clone(), a.clone()) } else { (Alpha, a) }
| ^
error: redundant clone
- --> $DIR/redundant_clone.rs:128:15
+ --> $DIR/redundant_clone.rs:133:15
|
LL | let _s = s.clone();
| ^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:128:14
+ --> $DIR/redundant_clone.rs:133:14
|
LL | let _s = s.clone();
| ^
error: redundant clone
- --> $DIR/redundant_clone.rs:129:15
+ --> $DIR/redundant_clone.rs:134:15
|
LL | let _t = t.clone();
| ^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:129:14
+ --> $DIR/redundant_clone.rs:134:14
|
LL | let _t = t.clone();
| ^
error: redundant clone
- --> $DIR/redundant_clone.rs:139:19
+ --> $DIR/redundant_clone.rs:144:19
|
LL | let _f = f.clone();
| ^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:139:18
+ --> $DIR/redundant_clone.rs:144:18
|
LL | let _f = f.clone();
| ^
error: redundant clone
- --> $DIR/redundant_clone.rs:151:14
+ --> $DIR/redundant_clone.rs:156:14
|
LL | let y = x.clone().join("matthias");
| ^^^^^^^^ help: remove this
|
note: cloned value is neither consumed nor mutated
- --> $DIR/redundant_clone.rs:151:13
+ --> $DIR/redundant_clone.rs:156:13
|
LL | let y = x.clone().join("matthias");
| ^^^^^^^^^
error: redundant clone
- --> $DIR/redundant_clone.rs:205:11
+ --> $DIR/redundant_clone.rs:210:11
|
LL | foo(&x.clone(), move || {
| ^^^^^^^^ help: remove this
|
note: this value is dropped without further use
- --> $DIR/redundant_clone.rs:205:10
+ --> $DIR/redundant_clone.rs:210:10
|
LL | foo(&x.clone(), move || {
| ^
diff --git a/tests/ui/uninlined_format_args.fixed b/tests/ui/uninlined_format_args.fixed
index e25d123dd51f..972e0356b62a 100644
--- a/tests/ui/uninlined_format_args.fixed
+++ b/tests/ui/uninlined_format_args.fixed
@@ -2,7 +2,12 @@
//@run-rustfix
#![warn(clippy::uninlined_format_args)]
#![allow(named_arguments_used_positionally, unused)]
-#![allow(clippy::eq_op, clippy::format_in_format_args, clippy::print_literal)]
+#![allow(
+ clippy::eq_op,
+ clippy::format_in_format_args,
+ clippy::print_literal,
+ clippy::unnecessary_literal_unwrap
+)]
extern crate proc_macros;
use proc_macros::with_span;
diff --git a/tests/ui/uninlined_format_args.rs b/tests/ui/uninlined_format_args.rs
index 6793ec24441c..7614ffb38e63 100644
--- a/tests/ui/uninlined_format_args.rs
+++ b/tests/ui/uninlined_format_args.rs
@@ -2,7 +2,12 @@
//@run-rustfix
#![warn(clippy::uninlined_format_args)]
#![allow(named_arguments_used_positionally, unused)]
-#![allow(clippy::eq_op, clippy::format_in_format_args, clippy::print_literal)]
+#![allow(
+ clippy::eq_op,
+ clippy::format_in_format_args,
+ clippy::print_literal,
+ clippy::unnecessary_literal_unwrap
+)]
extern crate proc_macros;
use proc_macros::with_span;
diff --git a/tests/ui/uninlined_format_args.stderr b/tests/ui/uninlined_format_args.stderr
index dc4af6ef42ec..44ca61f008c5 100644
--- a/tests/ui/uninlined_format_args.stderr
+++ b/tests/ui/uninlined_format_args.stderr
@@ -1,5 +1,5 @@
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:40:5
+ --> $DIR/uninlined_format_args.rs:45:5
|
LL | println!("val='{}'", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -12,7 +12,7 @@ LL + println!("val='{local_i32}'");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:41:5
+ --> $DIR/uninlined_format_args.rs:46:5
|
LL | println!("val='{ }'", local_i32); // 3 spaces
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -24,7 +24,7 @@ LL + println!("val='{local_i32}'"); // 3 spaces
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:42:5
+ --> $DIR/uninlined_format_args.rs:47:5
|
LL | println!("val='{ }'", local_i32); // tab
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -36,7 +36,7 @@ LL + println!("val='{local_i32}'"); // tab
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:43:5
+ --> $DIR/uninlined_format_args.rs:48:5
|
LL | println!("val='{ }'", local_i32); // space+tab
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -48,7 +48,7 @@ LL + println!("val='{local_i32}'"); // space+tab
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:44:5
+ --> $DIR/uninlined_format_args.rs:49:5
|
LL | println!("val='{ }'", local_i32); // tab+space
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -60,7 +60,7 @@ LL + println!("val='{local_i32}'"); // tab+space
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:45:5
+ --> $DIR/uninlined_format_args.rs:50:5
|
LL | / println!(
LL | | "val='{
@@ -70,7 +70,7 @@ LL | | );
| |_____^
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:50:5
+ --> $DIR/uninlined_format_args.rs:55:5
|
LL | println!("{}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -82,7 +82,7 @@ LL + println!("{local_i32}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:51:5
+ --> $DIR/uninlined_format_args.rs:56:5
|
LL | println!("{}", fn_arg);
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -94,7 +94,7 @@ LL + println!("{fn_arg}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:52:5
+ --> $DIR/uninlined_format_args.rs:57:5
|
LL | println!("{:?}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -106,7 +106,7 @@ LL + println!("{local_i32:?}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:53:5
+ --> $DIR/uninlined_format_args.rs:58:5
|
LL | println!("{:#?}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -118,7 +118,7 @@ LL + println!("{local_i32:#?}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:54:5
+ --> $DIR/uninlined_format_args.rs:59:5
|
LL | println!("{:4}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -130,7 +130,7 @@ LL + println!("{local_i32:4}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:55:5
+ --> $DIR/uninlined_format_args.rs:60:5
|
LL | println!("{:04}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -142,7 +142,7 @@ LL + println!("{local_i32:04}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:56:5
+ --> $DIR/uninlined_format_args.rs:61:5
|
LL | println!("{:<3}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -154,7 +154,7 @@ LL + println!("{local_i32:<3}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:57:5
+ --> $DIR/uninlined_format_args.rs:62:5
|
LL | println!("{:#010x}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -166,7 +166,7 @@ LL + println!("{local_i32:#010x}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:58:5
+ --> $DIR/uninlined_format_args.rs:63:5
|
LL | println!("{:.1}", local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -178,7 +178,7 @@ LL + println!("{local_f64:.1}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:62:5
+ --> $DIR/uninlined_format_args.rs:67:5
|
LL | println!("{} {}", local_i32, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -190,7 +190,7 @@ LL + println!("{local_i32} {local_f64}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:64:5
+ --> $DIR/uninlined_format_args.rs:69:5
|
LL | println!("{}", val);
| ^^^^^^^^^^^^^^^^^^^
@@ -202,7 +202,7 @@ LL + println!("{val}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:65:5
+ --> $DIR/uninlined_format_args.rs:70:5
|
LL | println!("{}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -214,7 +214,7 @@ LL + println!("{val}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:67:5
+ --> $DIR/uninlined_format_args.rs:72:5
|
LL | println!("val='{/t }'", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -226,7 +226,7 @@ LL + println!("val='{local_i32}'");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:68:5
+ --> $DIR/uninlined_format_args.rs:73:5
|
LL | println!("val='{/n }'", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -238,7 +238,7 @@ LL + println!("val='{local_i32}'");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:69:5
+ --> $DIR/uninlined_format_args.rs:74:5
|
LL | println!("val='{local_i32}'", local_i32 = local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -250,7 +250,7 @@ LL + println!("val='{local_i32}'");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:70:5
+ --> $DIR/uninlined_format_args.rs:75:5
|
LL | println!("val='{local_i32}'", local_i32 = fn_arg);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -262,7 +262,7 @@ LL + println!("val='{fn_arg}'");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:71:5
+ --> $DIR/uninlined_format_args.rs:76:5
|
LL | println!("{0}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -274,7 +274,7 @@ LL + println!("{local_i32}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:72:5
+ --> $DIR/uninlined_format_args.rs:77:5
|
LL | println!("{0:?}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -286,7 +286,7 @@ LL + println!("{local_i32:?}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:73:5
+ --> $DIR/uninlined_format_args.rs:78:5
|
LL | println!("{0:#?}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -298,7 +298,7 @@ LL + println!("{local_i32:#?}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:74:5
+ --> $DIR/uninlined_format_args.rs:79:5
|
LL | println!("{0:04}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -310,7 +310,7 @@ LL + println!("{local_i32:04}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:75:5
+ --> $DIR/uninlined_format_args.rs:80:5
|
LL | println!("{0:<3}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -322,7 +322,7 @@ LL + println!("{local_i32:<3}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:76:5
+ --> $DIR/uninlined_format_args.rs:81:5
|
LL | println!("{0:#010x}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -334,7 +334,7 @@ LL + println!("{local_i32:#010x}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:77:5
+ --> $DIR/uninlined_format_args.rs:82:5
|
LL | println!("{0:.1}", local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -346,7 +346,7 @@ LL + println!("{local_f64:.1}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:78:5
+ --> $DIR/uninlined_format_args.rs:83:5
|
LL | println!("{0} {0}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -358,7 +358,7 @@ LL + println!("{local_i32} {local_i32}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:79:5
+ --> $DIR/uninlined_format_args.rs:84:5
|
LL | println!("{1} {} {0} {}", local_i32, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -370,7 +370,7 @@ LL + println!("{local_f64} {local_i32} {local_i32} {local_f64}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:80:5
+ --> $DIR/uninlined_format_args.rs:85:5
|
LL | println!("{0} {1}", local_i32, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -382,7 +382,7 @@ LL + println!("{local_i32} {local_f64}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:81:5
+ --> $DIR/uninlined_format_args.rs:86:5
|
LL | println!("{1} {0}", local_i32, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -394,7 +394,7 @@ LL + println!("{local_f64} {local_i32}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:82:5
+ --> $DIR/uninlined_format_args.rs:87:5
|
LL | println!("{1} {0} {1} {0}", local_i32, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -406,7 +406,7 @@ LL + println!("{local_f64} {local_i32} {local_f64} {local_i32}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:84:5
+ --> $DIR/uninlined_format_args.rs:89:5
|
LL | println!("{v}", v = local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -418,7 +418,7 @@ LL + println!("{local_i32}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:85:5
+ --> $DIR/uninlined_format_args.rs:90:5
|
LL | println!("{local_i32:0$}", width);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -430,7 +430,7 @@ LL + println!("{local_i32:width$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:86:5
+ --> $DIR/uninlined_format_args.rs:91:5
|
LL | println!("{local_i32:w$}", w = width);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -442,7 +442,7 @@ LL + println!("{local_i32:width$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:87:5
+ --> $DIR/uninlined_format_args.rs:92:5
|
LL | println!("{local_i32:.0$}", prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -454,7 +454,7 @@ LL + println!("{local_i32:.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:88:5
+ --> $DIR/uninlined_format_args.rs:93:5
|
LL | println!("{local_i32:.p$}", p = prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -466,7 +466,7 @@ LL + println!("{local_i32:.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:89:5
+ --> $DIR/uninlined_format_args.rs:94:5
|
LL | println!("{:0$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -478,7 +478,7 @@ LL + println!("{val:val$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:90:5
+ --> $DIR/uninlined_format_args.rs:95:5
|
LL | println!("{0:0$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -490,7 +490,7 @@ LL + println!("{val:val$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:91:5
+ --> $DIR/uninlined_format_args.rs:96:5
|
LL | println!("{:0$.0$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -502,7 +502,7 @@ LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:92:5
+ --> $DIR/uninlined_format_args.rs:97:5
|
LL | println!("{0:0$.0$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -514,7 +514,7 @@ LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:93:5
+ --> $DIR/uninlined_format_args.rs:98:5
|
LL | println!("{0:0$.v$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -526,7 +526,7 @@ LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:94:5
+ --> $DIR/uninlined_format_args.rs:99:5
|
LL | println!("{0:v$.0$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -538,7 +538,7 @@ LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:95:5
+ --> $DIR/uninlined_format_args.rs:100:5
|
LL | println!("{v:0$.0$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -550,7 +550,7 @@ LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:96:5
+ --> $DIR/uninlined_format_args.rs:101:5
|
LL | println!("{v:v$.0$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -562,7 +562,7 @@ LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:97:5
+ --> $DIR/uninlined_format_args.rs:102:5
|
LL | println!("{v:0$.v$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -574,7 +574,7 @@ LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:98:5
+ --> $DIR/uninlined_format_args.rs:103:5
|
LL | println!("{v:v$.v$}", v = val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -586,7 +586,7 @@ LL + println!("{val:val$.val$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:99:5
+ --> $DIR/uninlined_format_args.rs:104:5
|
LL | println!("{:0$}", width);
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -598,7 +598,7 @@ LL + println!("{width:width$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:100:5
+ --> $DIR/uninlined_format_args.rs:105:5
|
LL | println!("{:1$}", local_i32, width);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -610,7 +610,7 @@ LL + println!("{local_i32:width$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:101:5
+ --> $DIR/uninlined_format_args.rs:106:5
|
LL | println!("{:w$}", w = width);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -622,7 +622,7 @@ LL + println!("{width:width$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:102:5
+ --> $DIR/uninlined_format_args.rs:107:5
|
LL | println!("{:w$}", local_i32, w = width);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -634,7 +634,7 @@ LL + println!("{local_i32:width$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:103:5
+ --> $DIR/uninlined_format_args.rs:108:5
|
LL | println!("{:.0$}", prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -646,7 +646,7 @@ LL + println!("{prec:.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:104:5
+ --> $DIR/uninlined_format_args.rs:109:5
|
LL | println!("{:.1$}", local_i32, prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -658,7 +658,7 @@ LL + println!("{local_i32:.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:105:5
+ --> $DIR/uninlined_format_args.rs:110:5
|
LL | println!("{:.p$}", p = prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -670,7 +670,7 @@ LL + println!("{prec:.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:106:5
+ --> $DIR/uninlined_format_args.rs:111:5
|
LL | println!("{:.p$}", local_i32, p = prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -682,7 +682,7 @@ LL + println!("{local_i32:.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:107:5
+ --> $DIR/uninlined_format_args.rs:112:5
|
LL | println!("{:0$.1$}", width, prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -694,7 +694,7 @@ LL + println!("{width:width$.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:108:5
+ --> $DIR/uninlined_format_args.rs:113:5
|
LL | println!("{:0$.w$}", width, w = prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -706,7 +706,7 @@ LL + println!("{width:width$.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:109:5
+ --> $DIR/uninlined_format_args.rs:114:5
|
LL | println!("{:1$.2$}", local_f64, width, prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -718,7 +718,7 @@ LL + println!("{local_f64:width$.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:110:5
+ --> $DIR/uninlined_format_args.rs:115:5
|
LL | println!("{:1$.2$} {0} {1} {2}", local_f64, width, prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -730,7 +730,7 @@ LL + println!("{local_f64:width$.prec$} {local_f64} {width} {prec}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:111:5
+ --> $DIR/uninlined_format_args.rs:116:5
|
LL | / println!(
LL | | "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}",
@@ -739,7 +739,7 @@ LL | | );
| |_____^
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:122:5
+ --> $DIR/uninlined_format_args.rs:127:5
|
LL | println!("Width = {}, value with width = {:0$}", local_i32, local_f64);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -751,7 +751,7 @@ LL + println!("Width = {local_i32}, value with width = {local_f64:local_i32$
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:123:5
+ --> $DIR/uninlined_format_args.rs:128:5
|
LL | println!("{:w$.p$}", local_i32, w = width, p = prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -763,7 +763,7 @@ LL + println!("{local_i32:width$.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:124:5
+ --> $DIR/uninlined_format_args.rs:129:5
|
LL | println!("{:w$.p$}", w = width, p = prec);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -775,7 +775,7 @@ LL + println!("{width:width$.prec$}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:143:5
+ --> $DIR/uninlined_format_args.rs:148:5
|
LL | / println!(
LL | | "{}",
@@ -785,7 +785,7 @@ LL | | );
| |_____^
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:148:5
+ --> $DIR/uninlined_format_args.rs:153:5
|
LL | println!("{}", /* comment with a comma , in it */ val);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -797,7 +797,7 @@ LL + println!("{val}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:154:9
+ --> $DIR/uninlined_format_args.rs:159:9
|
LL | panic!("p1 {}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -809,7 +809,7 @@ LL + panic!("p1 {local_i32}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:157:9
+ --> $DIR/uninlined_format_args.rs:162:9
|
LL | panic!("p2 {0}", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -821,7 +821,7 @@ LL + panic!("p2 {local_i32}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:160:9
+ --> $DIR/uninlined_format_args.rs:165:9
|
LL | panic!("p3 {local_i32}", local_i32 = local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -833,7 +833,7 @@ LL + panic!("p3 {local_i32}");
|
error: variables can be used directly in the `format!` string
- --> $DIR/uninlined_format_args.rs:180:5
+ --> $DIR/uninlined_format_args.rs:185:5
|
LL | println!("expand='{}'", local_i32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/tests/ui/unnecessary_lazy_eval.fixed b/tests/ui/unnecessary_lazy_eval.fixed
index 565bd96cf30a..75a42809ad28 100644
--- a/tests/ui/unnecessary_lazy_eval.fixed
+++ b/tests/ui/unnecessary_lazy_eval.fixed
@@ -5,6 +5,7 @@
#![allow(clippy::bind_instead_of_map)]
#![allow(clippy::map_identity)]
#![allow(clippy::needless_borrow)]
+#![allow(clippy::unnecessary_literal_unwrap)]
use std::ops::Deref;
diff --git a/tests/ui/unnecessary_lazy_eval.rs b/tests/ui/unnecessary_lazy_eval.rs
index 3627076b2af1..3777b9c25c22 100644
--- a/tests/ui/unnecessary_lazy_eval.rs
+++ b/tests/ui/unnecessary_lazy_eval.rs
@@ -5,6 +5,7 @@
#![allow(clippy::bind_instead_of_map)]
#![allow(clippy::map_identity)]
#![allow(clippy::needless_borrow)]
+#![allow(clippy::unnecessary_literal_unwrap)]
use std::ops::Deref;
diff --git a/tests/ui/unnecessary_lazy_eval.stderr b/tests/ui/unnecessary_lazy_eval.stderr
index 2850a632fc77..458eed1f359a 100644
--- a/tests/ui/unnecessary_lazy_eval.stderr
+++ b/tests/ui/unnecessary_lazy_eval.stderr
@@ -1,5 +1,5 @@
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:68:13
+ --> $DIR/unnecessary_lazy_eval.rs:69:13
|
LL | let _ = opt.unwrap_or_else(|| 2);
| ^^^^--------------------
@@ -9,7 +9,7 @@ LL | let _ = opt.unwrap_or_else(|| 2);
= note: `-D clippy::unnecessary-lazy-evaluations` implied by `-D warnings`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:69:13
+ --> $DIR/unnecessary_lazy_eval.rs:70:13
|
LL | let _ = opt.unwrap_or_else(|| astronomers_pi);
| ^^^^---------------------------------
@@ -17,7 +17,7 @@ LL | let _ = opt.unwrap_or_else(|| astronomers_pi);
| help: use `unwrap_or(..)` instead: `unwrap_or(astronomers_pi)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:70:13
+ --> $DIR/unnecessary_lazy_eval.rs:71:13
|
LL | let _ = opt.unwrap_or_else(|| ext_str.some_field);
| ^^^^-------------------------------------
@@ -25,7 +25,7 @@ LL | let _ = opt.unwrap_or_else(|| ext_str.some_field);
| help: use `unwrap_or(..)` instead: `unwrap_or(ext_str.some_field)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:72:13
+ --> $DIR/unnecessary_lazy_eval.rs:73:13
|
LL | let _ = opt.and_then(|_| ext_opt);
| ^^^^---------------------
@@ -33,7 +33,7 @@ LL | let _ = opt.and_then(|_| ext_opt);
| help: use `and(..)` instead: `and(ext_opt)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:73:13
+ --> $DIR/unnecessary_lazy_eval.rs:74:13
|
LL | let _ = opt.or_else(|| ext_opt);
| ^^^^-------------------
@@ -41,7 +41,7 @@ LL | let _ = opt.or_else(|| ext_opt);
| help: use `or(..)` instead: `or(ext_opt)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:74:13
+ --> $DIR/unnecessary_lazy_eval.rs:75:13
|
LL | let _ = opt.or_else(|| None);
| ^^^^----------------
@@ -49,7 +49,7 @@ LL | let _ = opt.or_else(|| None);
| help: use `or(..)` instead: `or(None)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:75:13
+ --> $DIR/unnecessary_lazy_eval.rs:76:13
|
LL | let _ = opt.get_or_insert_with(|| 2);
| ^^^^------------------------
@@ -57,7 +57,7 @@ LL | let _ = opt.get_or_insert_with(|| 2);
| help: use `get_or_insert(..)` instead: `get_or_insert(2)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:76:13
+ --> $DIR/unnecessary_lazy_eval.rs:77:13
|
LL | let _ = opt.ok_or_else(|| 2);
| ^^^^----------------
@@ -65,7 +65,7 @@ LL | let _ = opt.ok_or_else(|| 2);
| help: use `ok_or(..)` instead: `ok_or(2)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:77:13
+ --> $DIR/unnecessary_lazy_eval.rs:78:13
|
LL | let _ = nested_tuple_opt.unwrap_or_else(|| Some((1, 2)));
| ^^^^^^^^^^^^^^^^^-------------------------------
@@ -73,7 +73,7 @@ LL | let _ = nested_tuple_opt.unwrap_or_else(|| Some((1, 2)));
| help: use `unwrap_or(..)` instead: `unwrap_or(Some((1, 2)))`
error: unnecessary closure used with `bool::then`
- --> $DIR/unnecessary_lazy_eval.rs:78:13
+ --> $DIR/unnecessary_lazy_eval.rs:79:13
|
LL | let _ = cond.then(|| astronomers_pi);
| ^^^^^-----------------------
@@ -81,7 +81,7 @@ LL | let _ = cond.then(|| astronomers_pi);
| help: use `then_some(..)` instead: `then_some(astronomers_pi)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:82:13
+ --> $DIR/unnecessary_lazy_eval.rs:83:13
|
LL | let _ = Some(1).unwrap_or_else(|| *r);
| ^^^^^^^^---------------------
@@ -89,7 +89,7 @@ LL | let _ = Some(1).unwrap_or_else(|| *r);
| help: use `unwrap_or(..)` instead: `unwrap_or(*r)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:84:13
+ --> $DIR/unnecessary_lazy_eval.rs:85:13
|
LL | let _ = Some(1).unwrap_or_else(|| *b);
| ^^^^^^^^---------------------
@@ -97,7 +97,7 @@ LL | let _ = Some(1).unwrap_or_else(|| *b);
| help: use `unwrap_or(..)` instead: `unwrap_or(*b)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:86:13
+ --> $DIR/unnecessary_lazy_eval.rs:87:13
|
LL | let _ = Some(1).as_ref().unwrap_or_else(|| &r);
| ^^^^^^^^^^^^^^^^^---------------------
@@ -105,7 +105,7 @@ LL | let _ = Some(1).as_ref().unwrap_or_else(|| &r);
| help: use `unwrap_or(..)` instead: `unwrap_or(&r)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:87:13
+ --> $DIR/unnecessary_lazy_eval.rs:88:13
|
LL | let _ = Some(1).as_ref().unwrap_or_else(|| &b);
| ^^^^^^^^^^^^^^^^^---------------------
@@ -113,7 +113,7 @@ LL | let _ = Some(1).as_ref().unwrap_or_else(|| &b);
| help: use `unwrap_or(..)` instead: `unwrap_or(&b)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:90:13
+ --> $DIR/unnecessary_lazy_eval.rs:91:13
|
LL | let _ = Some(10).unwrap_or_else(|| 2);
| ^^^^^^^^^--------------------
@@ -121,7 +121,7 @@ LL | let _ = Some(10).unwrap_or_else(|| 2);
| help: use `unwrap_or(..)` instead: `unwrap_or(2)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:91:13
+ --> $DIR/unnecessary_lazy_eval.rs:92:13
|
LL | let _ = Some(10).and_then(|_| ext_opt);
| ^^^^^^^^^---------------------
@@ -129,7 +129,7 @@ LL | let _ = Some(10).and_then(|_| ext_opt);
| help: use `and(..)` instead: `and(ext_opt)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:92:28
+ --> $DIR/unnecessary_lazy_eval.rs:93:28
|
LL | let _: Option = None.or_else(|| ext_opt);
| ^^^^^-------------------
@@ -137,7 +137,7 @@ LL | let _: Option = None.or_else(|| ext_opt);
| help: use `or(..)` instead: `or(ext_opt)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:93:13
+ --> $DIR/unnecessary_lazy_eval.rs:94:13
|
LL | let _ = None.get_or_insert_with(|| 2);
| ^^^^^------------------------
@@ -145,7 +145,7 @@ LL | let _ = None.get_or_insert_with(|| 2);
| help: use `get_or_insert(..)` instead: `get_or_insert(2)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:94:35
+ --> $DIR/unnecessary_lazy_eval.rs:95:35
|
LL | let _: Result = None.ok_or_else(|| 2);
| ^^^^^----------------
@@ -153,7 +153,7 @@ LL | let _: Result = None.ok_or_else(|| 2);
| help: use `ok_or(..)` instead: `ok_or(2)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:95:28
+ --> $DIR/unnecessary_lazy_eval.rs:96:28
|
LL | let _: Option = None.or_else(|| None);
| ^^^^^----------------
@@ -161,7 +161,7 @@ LL | let _: Option = None.or_else(|| None);
| help: use `or(..)` instead: `or(None)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:98:13
+ --> $DIR/unnecessary_lazy_eval.rs:99:13
|
LL | let _ = deep.0.unwrap_or_else(|| 2);
| ^^^^^^^--------------------
@@ -169,7 +169,7 @@ LL | let _ = deep.0.unwrap_or_else(|| 2);
| help: use `unwrap_or(..)` instead: `unwrap_or(2)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:99:13
+ --> $DIR/unnecessary_lazy_eval.rs:100:13
|
LL | let _ = deep.0.and_then(|_| ext_opt);
| ^^^^^^^---------------------
@@ -177,7 +177,7 @@ LL | let _ = deep.0.and_then(|_| ext_opt);
| help: use `and(..)` instead: `and(ext_opt)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:100:13
+ --> $DIR/unnecessary_lazy_eval.rs:101:13
|
LL | let _ = deep.0.or_else(|| None);
| ^^^^^^^----------------
@@ -185,7 +185,7 @@ LL | let _ = deep.0.or_else(|| None);
| help: use `or(..)` instead: `or(None)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:101:13
+ --> $DIR/unnecessary_lazy_eval.rs:102:13
|
LL | let _ = deep.0.get_or_insert_with(|| 2);
| ^^^^^^^------------------------
@@ -193,7 +193,7 @@ LL | let _ = deep.0.get_or_insert_with(|| 2);
| help: use `get_or_insert(..)` instead: `get_or_insert(2)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:102:13
+ --> $DIR/unnecessary_lazy_eval.rs:103:13
|
LL | let _ = deep.0.ok_or_else(|| 2);
| ^^^^^^^----------------
@@ -201,7 +201,7 @@ LL | let _ = deep.0.ok_or_else(|| 2);
| help: use `ok_or(..)` instead: `ok_or(2)`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:132:28
+ --> $DIR/unnecessary_lazy_eval.rs:133:28
|
LL | let _: Option = None.or_else(|| Some(3));
| ^^^^^-------------------
@@ -209,7 +209,7 @@ LL | let _: Option = None.or_else(|| Some(3));
| help: use `or(..)` instead: `or(Some(3))`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:133:13
+ --> $DIR/unnecessary_lazy_eval.rs:134:13
|
LL | let _ = deep.0.or_else(|| Some(3));
| ^^^^^^^-------------------
@@ -217,7 +217,7 @@ LL | let _ = deep.0.or_else(|| Some(3));
| help: use `or(..)` instead: `or(Some(3))`
error: unnecessary closure used to substitute value for `Option::None`
- --> $DIR/unnecessary_lazy_eval.rs:134:13
+ --> $DIR/unnecessary_lazy_eval.rs:135:13
|
LL | let _ = opt.or_else(|| Some(3));
| ^^^^-------------------
@@ -225,7 +225,7 @@ LL | let _ = opt.or_else(|| Some(3));
| help: use `or(..)` instead: `or(Some(3))`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval.rs:140:13
+ --> $DIR/unnecessary_lazy_eval.rs:141:13
|
LL | let _ = res2.unwrap_or_else(|_| 2);
| ^^^^^---------------------
@@ -233,7 +233,7 @@ LL | let _ = res2.unwrap_or_else(|_| 2);
| help: use `unwrap_or(..)` instead: `unwrap_or(2)`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval.rs:141:13
+ --> $DIR/unnecessary_lazy_eval.rs:142:13
|
LL | let _ = res2.unwrap_or_else(|_| astronomers_pi);
| ^^^^^----------------------------------
@@ -241,7 +241,7 @@ LL | let _ = res2.unwrap_or_else(|_| astronomers_pi);
| help: use `unwrap_or(..)` instead: `unwrap_or(astronomers_pi)`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval.rs:142:13
+ --> $DIR/unnecessary_lazy_eval.rs:143:13
|
LL | let _ = res2.unwrap_or_else(|_| ext_str.some_field);
| ^^^^^--------------------------------------
@@ -249,7 +249,7 @@ LL | let _ = res2.unwrap_or_else(|_| ext_str.some_field);
| help: use `unwrap_or(..)` instead: `unwrap_or(ext_str.some_field)`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval.rs:164:35
+ --> $DIR/unnecessary_lazy_eval.rs:165:35
|
LL | let _: Result = res.and_then(|_| Err(2));
| ^^^^--------------------
@@ -257,7 +257,7 @@ LL | let _: Result = res.and_then(|_| Err(2));
| help: use `and(..)` instead: `and(Err(2))`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval.rs:165:35
+ --> $DIR/unnecessary_lazy_eval.rs:166:35
|
LL | let _: Result = res.and_then(|_| Err(astronomers_pi));
| ^^^^---------------------------------
@@ -265,7 +265,7 @@ LL | let _: Result = res.and_then(|_| Err(astronomers_pi));
| help: use `and(..)` instead: `and(Err(astronomers_pi))`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval.rs:166:35
+ --> $DIR/unnecessary_lazy_eval.rs:167:35
|
LL | let _: Result = res.and_then(|_| Err(ext_str.some_field));
| ^^^^-------------------------------------
@@ -273,7 +273,7 @@ LL | let _: Result = res.and_then(|_| Err(ext_str.some_field))
| help: use `and(..)` instead: `and(Err(ext_str.some_field))`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval.rs:168:35
+ --> $DIR/unnecessary_lazy_eval.rs:169:35
|
LL | let _: Result = res.or_else(|_| Ok(2));
| ^^^^------------------
@@ -281,7 +281,7 @@ LL | let _: Result = res.or_else(|_| Ok(2));
| help: use `or(..)` instead: `or(Ok(2))`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval.rs:169:35
+ --> $DIR/unnecessary_lazy_eval.rs:170:35
|
LL | let _: Result = res.or_else(|_| Ok(astronomers_pi));
| ^^^^-------------------------------
@@ -289,7 +289,7 @@ LL | let _: Result = res.or_else(|_| Ok(astronomers_pi));
| help: use `or(..)` instead: `or(Ok(astronomers_pi))`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval.rs:170:35
+ --> $DIR/unnecessary_lazy_eval.rs:171:35
|
LL | let _: Result = res.or_else(|_| Ok(ext_str.some_field));
| ^^^^-----------------------------------
@@ -297,7 +297,7 @@ LL | let _: Result = res.or_else(|_| Ok(ext_str.some_field));
| help: use `or(..)` instead: `or(Ok(ext_str.some_field))`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval.rs:171:35
+ --> $DIR/unnecessary_lazy_eval.rs:172:35
|
LL | let _: Result = res.
| ___________________________________^
diff --git a/tests/ui/unnecessary_lazy_eval_unfixable.rs b/tests/ui/unnecessary_lazy_eval_unfixable.rs
index b05dd143bfd7..b4a1f81679ad 100644
--- a/tests/ui/unnecessary_lazy_eval_unfixable.rs
+++ b/tests/ui/unnecessary_lazy_eval_unfixable.rs
@@ -1,4 +1,5 @@
#![warn(clippy::unnecessary_lazy_evaluations)]
+#![allow(clippy::unnecessary_literal_unwrap)]
struct Deep(Option);
diff --git a/tests/ui/unnecessary_lazy_eval_unfixable.stderr b/tests/ui/unnecessary_lazy_eval_unfixable.stderr
index 20acab6e844f..7f353ba06982 100644
--- a/tests/ui/unnecessary_lazy_eval_unfixable.stderr
+++ b/tests/ui/unnecessary_lazy_eval_unfixable.stderr
@@ -1,5 +1,5 @@
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval_unfixable.rs:12:13
+ --> $DIR/unnecessary_lazy_eval_unfixable.rs:13:13
|
LL | let _ = Ok(1).unwrap_or_else(|()| 2);
| ^^^^^^----------------------
@@ -9,7 +9,7 @@ LL | let _ = Ok(1).unwrap_or_else(|()| 2);
= note: `-D clippy::unnecessary-lazy-evaluations` implied by `-D warnings`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval_unfixable.rs:16:13
+ --> $DIR/unnecessary_lazy_eval_unfixable.rs:17:13
|
LL | let _ = Ok(1).unwrap_or_else(|e::E| 2);
| ^^^^^^------------------------
@@ -17,7 +17,7 @@ LL | let _ = Ok(1).unwrap_or_else(|e::E| 2);
| help: use `unwrap_or(..)` instead: `unwrap_or(2)`
error: unnecessary closure used to substitute value for `Result::Err`
- --> $DIR/unnecessary_lazy_eval_unfixable.rs:17:13
+ --> $DIR/unnecessary_lazy_eval_unfixable.rs:18:13
|
LL | let _ = Ok(1).unwrap_or_else(|SomeStruct { .. }| 2);
| ^^^^^^-------------------------------------
diff --git a/tests/ui/unwrap.rs b/tests/ui/unwrap.rs
index d9fd402e7cfb..64d6437834e6 100644
--- a/tests/ui/unwrap.rs
+++ b/tests/ui/unwrap.rs
@@ -1,4 +1,5 @@
#![warn(clippy::unwrap_used)]
+#![allow(clippy::unnecessary_literal_unwrap)]
fn unwrap_option() {
let opt = Some(0);
diff --git a/tests/ui/unwrap.stderr b/tests/ui/unwrap.stderr
index d49bf2b32283..3796d942ff9f 100644
--- a/tests/ui/unwrap.stderr
+++ b/tests/ui/unwrap.stderr
@@ -1,5 +1,5 @@
error: used `unwrap()` on an `Option` value
- --> $DIR/unwrap.rs:5:13
+ --> $DIR/unwrap.rs:6:13
|
LL | let _ = opt.unwrap();
| ^^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL | let _ = opt.unwrap();
= note: `-D clippy::unwrap-used` implied by `-D warnings`
error: used `unwrap()` on a `Result` value
- --> $DIR/unwrap.rs:10:13
+ --> $DIR/unwrap.rs:11:13
|
LL | let _ = res.unwrap();
| ^^^^^^^^^^^^
@@ -16,7 +16,7 @@ LL | let _ = res.unwrap();
= help: if you don't want to handle the `Err` case gracefully, consider using `expect()` to provide a better panic message
error: used `unwrap_err()` on a `Result` value
- --> $DIR/unwrap.rs:11:13
+ --> $DIR/unwrap.rs:12:13
|
LL | let _ = res.unwrap_err();
| ^^^^^^^^^^^^^^^^
diff --git a/tests/ui/unwrap_expect_used.rs b/tests/ui/unwrap_expect_used.rs
index 9f27fef82494..7f57efc53c9c 100644
--- a/tests/ui/unwrap_expect_used.rs
+++ b/tests/ui/unwrap_expect_used.rs
@@ -1,4 +1,5 @@
#![warn(clippy::unwrap_used, clippy::expect_used)]
+#![allow(clippy::unnecessary_literal_unwrap)]
trait OptionExt {
type Item;
diff --git a/tests/ui/unwrap_expect_used.stderr b/tests/ui/unwrap_expect_used.stderr
index fe4ecef11453..1a551ab5ab8e 100644
--- a/tests/ui/unwrap_expect_used.stderr
+++ b/tests/ui/unwrap_expect_used.stderr
@@ -1,5 +1,5 @@
error: used `unwrap()` on an `Option` value
- --> $DIR/unwrap_expect_used.rs:23:5
+ --> $DIR/unwrap_expect_used.rs:24:5
|
LL | Some(3).unwrap();
| ^^^^^^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL | Some(3).unwrap();
= note: `-D clippy::unwrap-used` implied by `-D warnings`
error: used `expect()` on an `Option` value
- --> $DIR/unwrap_expect_used.rs:24:5
+ --> $DIR/unwrap_expect_used.rs:25:5
|
LL | Some(3).expect("Hello world!");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -17,7 +17,7 @@ LL | Some(3).expect("Hello world!");
= note: `-D clippy::expect-used` implied by `-D warnings`
error: used `unwrap()` on a `Result` value
- --> $DIR/unwrap_expect_used.rs:31:5
+ --> $DIR/unwrap_expect_used.rs:32:5
|
LL | a.unwrap();
| ^^^^^^^^^^
@@ -25,7 +25,7 @@ LL | a.unwrap();
= help: if this value is an `Err`, it will panic
error: used `expect()` on a `Result` value
- --> $DIR/unwrap_expect_used.rs:32:5
+ --> $DIR/unwrap_expect_used.rs:33:5
|
LL | a.expect("Hello world!");
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -33,7 +33,7 @@ LL | a.expect("Hello world!");
= help: if this value is an `Err`, it will panic
error: used `unwrap_err()` on a `Result` value
- --> $DIR/unwrap_expect_used.rs:33:5
+ --> $DIR/unwrap_expect_used.rs:34:5
|
LL | a.unwrap_err();
| ^^^^^^^^^^^^^^
@@ -41,7 +41,7 @@ LL | a.unwrap_err();
= help: if this value is an `Ok`, it will panic
error: used `expect_err()` on a `Result` value
- --> $DIR/unwrap_expect_used.rs:34:5
+ --> $DIR/unwrap_expect_used.rs:35:5
|
LL | a.expect_err("Hello error!");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/tests/ui/unwrap_or.rs b/tests/ui/unwrap_or.rs
index a0c003f5b1ea..5bea85e66924 100644
--- a/tests/ui/unwrap_or.rs
+++ b/tests/ui/unwrap_or.rs
@@ -1,4 +1,5 @@
#![warn(clippy::all, clippy::or_fun_call)]
+#![allow(clippy::unnecessary_literal_unwrap)]
fn main() {
let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len();
diff --git a/tests/ui/unwrap_or.stderr b/tests/ui/unwrap_or.stderr
index c3a7464fd470..cf720eaaf052 100644
--- a/tests/ui/unwrap_or.stderr
+++ b/tests/ui/unwrap_or.stderr
@@ -1,5 +1,5 @@
error: use of `unwrap_or` followed by a function call
- --> $DIR/unwrap_or.rs:4:47
+ --> $DIR/unwrap_or.rs:5:47
|
LL | let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| "Fail".to_string())`
@@ -7,7 +7,7 @@ LL | let s = Some(String::from("test string")).unwrap_or("Fail".to_string())
= note: `-D clippy::or-fun-call` implied by `-D warnings`
error: use of `unwrap_or` followed by a function call
- --> $DIR/unwrap_or.rs:8:47
+ --> $DIR/unwrap_or.rs:9:47
|
LL | let s = Some(String::from("test string")).unwrap_or("Fail".to_string()).len();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| "Fail".to_string())`
diff --git a/tests/ui/unwrap_or_else_default.fixed b/tests/ui/unwrap_or_else_default.fixed
index 59a0ca3f192f..08b89a18bbbd 100644
--- a/tests/ui/unwrap_or_else_default.fixed
+++ b/tests/ui/unwrap_or_else_default.fixed
@@ -2,7 +2,7 @@
#![warn(clippy::unwrap_or_else_default)]
#![allow(dead_code)]
-#![allow(clippy::unnecessary_wraps)]
+#![allow(clippy::unnecessary_wraps, clippy::unnecessary_literal_unwrap)]
/// Checks implementation of the `UNWRAP_OR_ELSE_DEFAULT` lint.
fn unwrap_or_else_default() {
diff --git a/tests/ui/unwrap_or_else_default.rs b/tests/ui/unwrap_or_else_default.rs
index 97cafa336eda..ad2a744908fc 100644
--- a/tests/ui/unwrap_or_else_default.rs
+++ b/tests/ui/unwrap_or_else_default.rs
@@ -2,7 +2,7 @@
#![warn(clippy::unwrap_or_else_default)]
#![allow(dead_code)]
-#![allow(clippy::unnecessary_wraps)]
+#![allow(clippy::unnecessary_wraps, clippy::unnecessary_literal_unwrap)]
/// Checks implementation of the `UNWRAP_OR_ELSE_DEFAULT` lint.
fn unwrap_or_else_default() {