mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 07:00:55 +00:00
Auto merge of #11106 - syvb:literal_unwrap_ice, r=dswij
[`unnecessary_literal_unwrap`]: Fix ICE on None.unwrap_or_default() Fixes #11099 Fixes #11064 I'm running into #11099 (cc `@y21)` on my Rust codebase. Clippy ICEs on this code when evaluating the `unnecessary_literal_unwrap` lint: ```rust fn main() { let val1: u8 = None.unwrap_or_default(); } ``` This fixes that ICE and adds an message specifically for that case: ``` error: used `unwrap_or_default()` on `None` value --> $DIR/unnecessary_literal_unwrap.rs:26:5 | LL | None::<String>.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap_or_default()`: `String::default()` ``` This PR also fixes the same ICE with `None.unwrap_or_else` (by giving the generic error message for the lint in that case). changelog: Fix ICE in `unnecessary_literal_unwrap` on `None.unwrap_or_default()`
This commit is contained in:
commit
fca1f9aec5
6 changed files with 300 additions and 125 deletions
|
@ -3,6 +3,8 @@ use clippy_utils::{is_res_lang_ctor, last_path_segment, path_res, MaybePath};
|
|||
use rustc_errors::Applicability;
|
||||
use rustc_hir as hir;
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::ty;
|
||||
use rustc_middle::ty::print::with_forced_trimmed_paths;
|
||||
|
||||
use super::UNNECESSARY_LITERAL_UNWRAP;
|
||||
|
||||
|
@ -22,6 +24,7 @@ fn get_ty_from_args<'a>(args: Option<&'a [hir::GenericArg<'a>]>, index: usize) -
|
|||
}
|
||||
}
|
||||
|
||||
#[expect(clippy::too_many_lines)]
|
||||
pub(super) fn check(
|
||||
cx: &LateContext<'_>,
|
||||
expr: &hir::Expr<'_>,
|
||||
|
@ -84,6 +87,34 @@ pub(super) fn check(
|
|||
}
|
||||
Some(suggs)
|
||||
},
|
||||
("None", "unwrap_or_default", _) => {
|
||||
let ty = cx.typeck_results().expr_ty(expr);
|
||||
let default_ty_string = if let ty::Adt(def, ..) = ty.kind() {
|
||||
with_forced_trimmed_paths!(format!("{}", cx.tcx.def_path_str(def.did())))
|
||||
} else {
|
||||
"Default".to_string()
|
||||
};
|
||||
Some(vec![(expr.span, format!("{default_ty_string}::default()"))])
|
||||
},
|
||||
("None", "unwrap_or", _) => Some(vec![
|
||||
(expr.span.with_hi(args[0].span.lo()), String::new()),
|
||||
(expr.span.with_lo(args[0].span.hi()), String::new()),
|
||||
]),
|
||||
("None", "unwrap_or_else", _) => match args[0].kind {
|
||||
hir::ExprKind::Closure(hir::Closure {
|
||||
fn_decl:
|
||||
hir::FnDecl {
|
||||
output: hir::FnRetTy::DefaultReturn(span) | hir::FnRetTy::Return(hir::Ty { span, .. }),
|
||||
..
|
||||
},
|
||||
..
|
||||
}) => Some(vec![
|
||||
(expr.span.with_hi(span.hi()), String::new()),
|
||||
(expr.span.with_lo(args[0].span.hi()), String::new()),
|
||||
]),
|
||||
_ => None,
|
||||
},
|
||||
_ if call_args.is_empty() => None,
|
||||
(_, _, Some(_)) => None,
|
||||
("Ok", "unwrap_err", None) | ("Err", "unwrap", None) => Some(vec![
|
||||
(
|
||||
|
|
|
@ -16,12 +16,23 @@ fn unwrap_option_some() {
|
|||
1;
|
||||
}
|
||||
|
||||
#[rustfmt::skip] // force rustfmt not to remove braces in `|| { 234 }`
|
||||
fn unwrap_option_none() {
|
||||
let _val = panic!();
|
||||
let _val = panic!("this always happens");
|
||||
let _val: String = String::default();
|
||||
let _val: u16 = 234;
|
||||
let _val: u16 = 234;
|
||||
let _val: u16 = { 234 };
|
||||
let _val: u16 = { 234 };
|
||||
|
||||
panic!();
|
||||
panic!("this always happens");
|
||||
String::default();
|
||||
234;
|
||||
234;
|
||||
{ 234 };
|
||||
{ 234 };
|
||||
}
|
||||
|
||||
fn unwrap_result_ok() {
|
||||
|
|
|
@ -16,12 +16,23 @@ fn unwrap_option_some() {
|
|||
Some(1).expect("this never happens");
|
||||
}
|
||||
|
||||
#[rustfmt::skip] // force rustfmt not to remove braces in `|| { 234 }`
|
||||
fn unwrap_option_none() {
|
||||
let _val = None::<()>.unwrap();
|
||||
let _val = None::<()>.expect("this always happens");
|
||||
let _val: String = None.unwrap_or_default();
|
||||
let _val: u16 = None.unwrap_or(234);
|
||||
let _val: u16 = None.unwrap_or_else(|| 234);
|
||||
let _val: u16 = None.unwrap_or_else(|| { 234 });
|
||||
let _val: u16 = None.unwrap_or_else(|| -> u16 { 234 });
|
||||
|
||||
None::<()>.unwrap();
|
||||
None::<()>.expect("this always happens");
|
||||
None::<String>.unwrap_or_default();
|
||||
None::<u16>.unwrap_or(234);
|
||||
None::<u16>.unwrap_or_else(|| 234);
|
||||
None::<u16>.unwrap_or_else(|| { 234 });
|
||||
None::<u16>.unwrap_or_else(|| -> u16 { 234 });
|
||||
}
|
||||
|
||||
fn unwrap_result_ok() {
|
||||
|
|
|
@ -48,13 +48,13 @@ LL + 1;
|
|||
|
|
||||
|
||||
error: used `unwrap()` on `None` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:20:16
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:21:16
|
||||
|
|
||||
LL | let _val = None::<()>.unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap()`: `panic!()`
|
||||
|
||||
error: used `expect()` on `None` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:21:16
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:22:16
|
||||
|
|
||||
LL | let _val = None::<()>.expect("this always happens");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -64,14 +64,68 @@ help: remove the `None` and `expect()`
|
|||
LL | let _val = panic!("this always happens");
|
||||
| ~~~~~~~ ~
|
||||
|
||||
error: used `unwrap_or_default()` on `None` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:23:24
|
||||
|
|
||||
LL | let _val: String = None.unwrap_or_default();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap_or_default()`: `String::default()`
|
||||
|
||||
error: used `unwrap_or()` on `None` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:24:21
|
||||
|
|
||||
LL | let _val: u16 = None.unwrap_or(234);
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `None` and `unwrap_or()`
|
||||
|
|
||||
LL - let _val: u16 = None.unwrap_or(234);
|
||||
LL + let _val: u16 = 234;
|
||||
|
|
||||
|
||||
error: used `unwrap_or_else()` on `None` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:25:21
|
||||
|
|
||||
LL | let _val: u16 = None.unwrap_or_else(|| 234);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `None` and `unwrap_or_else()`
|
||||
|
|
||||
LL - let _val: u16 = None.unwrap_or_else(|| 234);
|
||||
LL + let _val: u16 = 234;
|
||||
|
|
||||
|
||||
error: used `unwrap_or_else()` on `None` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:26:21
|
||||
|
|
||||
LL | let _val: u16 = None.unwrap_or_else(|| { 234 });
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `None` and `unwrap_or_else()`
|
||||
|
|
||||
LL - let _val: u16 = None.unwrap_or_else(|| { 234 });
|
||||
LL + let _val: u16 = { 234 };
|
||||
|
|
||||
|
||||
error: used `unwrap_or_else()` on `None` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:27:21
|
||||
|
|
||||
LL | let _val: u16 = None.unwrap_or_else(|| -> u16 { 234 });
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `None` and `unwrap_or_else()`
|
||||
|
|
||||
LL - let _val: u16 = None.unwrap_or_else(|| -> u16 { 234 });
|
||||
LL + let _val: u16 = { 234 };
|
||||
|
|
||||
|
||||
error: used `unwrap()` on `None` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:23:5
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:29:5
|
||||
|
|
||||
LL | None::<()>.unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap()`: `panic!()`
|
||||
|
||||
error: used `expect()` on `None` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:24:5
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:30:5
|
||||
|
|
||||
LL | None::<()>.expect("this always happens");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -81,8 +135,62 @@ help: remove the `None` and `expect()`
|
|||
LL | panic!("this always happens");
|
||||
| ~~~~~~~ ~
|
||||
|
||||
error: used `unwrap_or_default()` on `None` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:31:5
|
||||
|
|
||||
LL | None::<String>.unwrap_or_default();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap_or_default()`: `String::default()`
|
||||
|
||||
error: used `unwrap_or()` on `None` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:32:5
|
||||
|
|
||||
LL | None::<u16>.unwrap_or(234);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `None` and `unwrap_or()`
|
||||
|
|
||||
LL - None::<u16>.unwrap_or(234);
|
||||
LL + 234;
|
||||
|
|
||||
|
||||
error: used `unwrap_or_else()` on `None` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:33:5
|
||||
|
|
||||
LL | None::<u16>.unwrap_or_else(|| 234);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `None` and `unwrap_or_else()`
|
||||
|
|
||||
LL - None::<u16>.unwrap_or_else(|| 234);
|
||||
LL + 234;
|
||||
|
|
||||
|
||||
error: used `unwrap_or_else()` on `None` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:34:5
|
||||
|
|
||||
LL | None::<u16>.unwrap_or_else(|| { 234 });
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `None` and `unwrap_or_else()`
|
||||
|
|
||||
LL - None::<u16>.unwrap_or_else(|| { 234 });
|
||||
LL + { 234 };
|
||||
|
|
||||
|
||||
error: used `unwrap_or_else()` on `None` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:35:5
|
||||
|
|
||||
LL | None::<u16>.unwrap_or_else(|| -> u16 { 234 });
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `None` and `unwrap_or_else()`
|
||||
|
|
||||
LL - None::<u16>.unwrap_or_else(|| -> u16 { 234 });
|
||||
LL + { 234 };
|
||||
|
|
||||
|
||||
error: used `unwrap()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:28:16
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:39:16
|
||||
|
|
||||
LL | let _val = Ok::<_, ()>(1).unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -94,7 +202,7 @@ LL + let _val = 1;
|
|||
|
|
||||
|
||||
error: used `expect()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:29:16
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:40:16
|
||||
|
|
||||
LL | let _val = Ok::<_, ()>(1).expect("this never happens");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -106,7 +214,7 @@ LL + let _val = 1;
|
|||
|
|
||||
|
||||
error: used `unwrap_err()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:30:16
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:41:16
|
||||
|
|
||||
LL | let _val = Ok::<_, ()>(1).unwrap_err();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -117,7 +225,7 @@ LL | let _val = panic!("{:?}", 1);
|
|||
| ~~~~~~~~~~~~~~ ~
|
||||
|
||||
error: used `expect_err()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:31:16
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:42:16
|
||||
|
|
||||
LL | let _val = Ok::<_, ()>(1).expect_err("this always happens");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -128,7 +236,7 @@ LL | let _val = panic!("{1}: {:?}", 1, "this always happens");
|
|||
| ~~~~~~~~~~~~~~~~~~~ ~
|
||||
|
||||
error: used `unwrap()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:33:5
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:44:5
|
||||
|
|
||||
LL | Ok::<_, ()>(1).unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -140,7 +248,7 @@ LL + 1;
|
|||
|
|
||||
|
||||
error: used `expect()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:34:5
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:45:5
|
||||
|
|
||||
LL | Ok::<_, ()>(1).expect("this never happens");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -152,7 +260,7 @@ LL + 1;
|
|||
|
|
||||
|
||||
error: used `unwrap_err()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:35:5
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:46:5
|
||||
|
|
||||
LL | Ok::<_, ()>(1).unwrap_err();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -163,7 +271,7 @@ LL | panic!("{:?}", 1);
|
|||
| ~~~~~~~~~~~~~~ ~
|
||||
|
||||
error: used `expect_err()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:36:5
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:47:5
|
||||
|
|
||||
LL | Ok::<_, ()>(1).expect_err("this always happens");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -174,7 +282,7 @@ LL | panic!("{1}: {:?}", 1, "this always happens");
|
|||
| ~~~~~~~~~~~~~~~~~~~ ~
|
||||
|
||||
error: used `unwrap_err()` on `Err` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:40:16
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:51:16
|
||||
|
|
||||
LL | let _val = Err::<(), _>(1).unwrap_err();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -186,7 +294,7 @@ LL + let _val = 1;
|
|||
|
|
||||
|
||||
error: used `expect_err()` on `Err` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:41:16
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:52:16
|
||||
|
|
||||
LL | let _val = Err::<(), _>(1).expect_err("this never happens");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -198,7 +306,7 @@ LL + let _val = 1;
|
|||
|
|
||||
|
||||
error: used `unwrap()` on `Err` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:42:16
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:53:16
|
||||
|
|
||||
LL | let _val = Err::<(), _>(1).unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -209,7 +317,7 @@ LL | let _val = panic!("{:?}", 1);
|
|||
| ~~~~~~~~~~~~~~ ~
|
||||
|
||||
error: used `expect()` on `Err` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:43:16
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:54:16
|
||||
|
|
||||
LL | let _val = Err::<(), _>(1).expect("this always happens");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -220,7 +328,7 @@ LL | let _val = panic!("{1}: {:?}", 1, "this always happens");
|
|||
| ~~~~~~~~~~~~~~~~~~~ ~
|
||||
|
||||
error: used `unwrap_err()` on `Err` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:45:5
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:56:5
|
||||
|
|
||||
LL | Err::<(), _>(1).unwrap_err();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -232,7 +340,7 @@ LL + 1;
|
|||
|
|
||||
|
||||
error: used `expect_err()` on `Err` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:46:5
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:57:5
|
||||
|
|
||||
LL | Err::<(), _>(1).expect_err("this never happens");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -244,7 +352,7 @@ LL + 1;
|
|||
|
|
||||
|
||||
error: used `unwrap()` on `Err` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:47:5
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:58:5
|
||||
|
|
||||
LL | Err::<(), _>(1).unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -255,7 +363,7 @@ LL | panic!("{:?}", 1);
|
|||
| ~~~~~~~~~~~~~~ ~
|
||||
|
||||
error: used `expect()` on `Err` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:48:5
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:59:5
|
||||
|
|
||||
LL | Err::<(), _>(1).expect("this always happens");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -266,7 +374,7 @@ LL | panic!("{1}: {:?}", 1, "this always happens");
|
|||
| ~~~~~~~~~~~~~~~~~~~ ~
|
||||
|
||||
error: used `unwrap_or()` on `Some` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:52:16
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:63:16
|
||||
|
|
||||
LL | let _val = Some(1).unwrap_or(2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -278,7 +386,7 @@ LL + let _val = 1;
|
|||
|
|
||||
|
||||
error: used `unwrap_or_default()` on `Some` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:53:16
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:64:16
|
||||
|
|
||||
LL | let _val = Some(1).unwrap_or_default();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -290,7 +398,7 @@ LL + let _val = 1;
|
|||
|
|
||||
|
||||
error: used `unwrap_or_else()` on `Some` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:54:16
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:65:16
|
||||
|
|
||||
LL | let _val = Some(1).unwrap_or_else(|| 2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -302,7 +410,7 @@ LL + let _val = 1;
|
|||
|
|
||||
|
||||
error: used `unwrap_or()` on `Some` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:56:5
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:67:5
|
||||
|
|
||||
LL | Some(1).unwrap_or(2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -314,7 +422,7 @@ LL + 1;
|
|||
|
|
||||
|
||||
error: used `unwrap_or_default()` on `Some` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:57:5
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:68:5
|
||||
|
|
||||
LL | Some(1).unwrap_or_default();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -326,7 +434,7 @@ LL + 1;
|
|||
|
|
||||
|
||||
error: used `unwrap_or_else()` on `Some` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:58:5
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:69:5
|
||||
|
|
||||
LL | Some(1).unwrap_or_else(|| 2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -338,7 +446,7 @@ LL + 1;
|
|||
|
|
||||
|
||||
error: used `unwrap_or()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:62:16
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:73:16
|
||||
|
|
||||
LL | let _val = Ok::<_, ()>(1).unwrap_or(2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -350,7 +458,7 @@ LL + let _val = 1;
|
|||
|
|
||||
|
||||
error: used `unwrap_or_default()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:63:16
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:74:16
|
||||
|
|
||||
LL | let _val = Ok::<_, ()>(1).unwrap_or_default();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -362,7 +470,7 @@ LL + let _val = 1;
|
|||
|
|
||||
|
||||
error: used `unwrap_or_else()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:64:16
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:75:16
|
||||
|
|
||||
LL | let _val = Ok::<_, ()>(1).unwrap_or_else(|_| 2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -374,7 +482,7 @@ LL + let _val = 1;
|
|||
|
|
||||
|
||||
error: used `unwrap_or()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:66:5
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:77:5
|
||||
|
|
||||
LL | Ok::<_, ()>(1).unwrap_or(2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -386,7 +494,7 @@ LL + 1;
|
|||
|
|
||||
|
||||
error: used `unwrap_or_default()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:67:5
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:78:5
|
||||
|
|
||||
LL | Ok::<_, ()>(1).unwrap_or_default();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -398,7 +506,7 @@ LL + 1;
|
|||
|
|
||||
|
||||
error: used `unwrap_or_else()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:68:5
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:79:5
|
||||
|
|
||||
LL | Ok::<_, ()>(1).unwrap_or_else(|_| 2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -410,7 +518,7 @@ LL + 1;
|
|||
|
|
||||
|
||||
error: used `unwrap_unchecked()` on `Some` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:82:22
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:93:22
|
||||
|
|
||||
LL | let _ = unsafe { Some(1).unwrap_unchecked() };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -422,7 +530,7 @@ LL + let _ = 1;
|
|||
|
|
||||
|
||||
error: used `unwrap_unchecked()` on `Some` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:83:22
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:94:22
|
||||
|
|
||||
LL | let _ = unsafe { Some(1).unwrap_unchecked() + *(&1 as *const i32) }; // needs to keep the unsafe block
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -434,7 +542,7 @@ LL + let _ = unsafe { 1 + *(&1 as *const i32) }; // needs to keep the unsafe
|
|||
|
|
||||
|
||||
error: used `unwrap_unchecked()` on `Some` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:84:22
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:95:22
|
||||
|
|
||||
LL | let _ = unsafe { Some(1).unwrap_unchecked() } + 1;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -446,7 +554,7 @@ LL + let _ = 1 + 1;
|
|||
|
|
||||
|
||||
error: used `unwrap_unchecked()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:85:22
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:96:22
|
||||
|
|
||||
LL | let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -458,7 +566,7 @@ LL + let _ = 1;
|
|||
|
|
||||
|
||||
error: used `unwrap_unchecked()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:86:22
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:97:22
|
||||
|
|
||||
LL | let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() + *(&1 as *const i32) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -470,7 +578,7 @@ LL + let _ = unsafe { 1 + *(&1 as *const i32) };
|
|||
|
|
||||
|
||||
error: used `unwrap_unchecked()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:87:22
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:98:22
|
||||
|
|
||||
LL | let _ = unsafe { Ok::<_, ()>(1).unwrap_unchecked() } + 1;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -482,7 +590,7 @@ LL + let _ = 1 + 1;
|
|||
|
|
||||
|
||||
error: used `unwrap_err_unchecked()` on `Err` value
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:88:22
|
||||
--> $DIR/unnecessary_literal_unwrap.rs:99:22
|
||||
|
|
||||
LL | let _ = unsafe { Err::<(), i32>(123).unwrap_err_unchecked() };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -493,5 +601,5 @@ LL - let _ = unsafe { Err::<(), i32>(123).unwrap_err_unchecked() };
|
|||
LL + let _ = 123;
|
||||
|
|
||||
|
||||
error: aborting due to 43 previous errors
|
||||
error: aborting due to 53 previous errors
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@ fn unwrap_option_none() {
|
|||
let val = None::<()>;
|
||||
let _val2 = val.unwrap();
|
||||
let _val2 = val.expect("this always happens");
|
||||
let _val3: u8 = None.unwrap_or_default();
|
||||
None::<()>.unwrap_or_default();
|
||||
}
|
||||
|
||||
fn unwrap_result_ok() {
|
||||
|
|
|
@ -95,509 +95,521 @@ help: remove the `None` and `expect()`
|
|||
LL | let val = None::<()>;
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: used `unwrap_or_default()` on `None` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:24:21
|
||||
|
|
||||
LL | let _val3: u8 = None.unwrap_or_default();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap_or_default()`: `Default::default()`
|
||||
|
||||
error: used `unwrap_or_default()` on `None` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:25:5
|
||||
|
|
||||
LL | None::<()>.unwrap_or_default();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap_or_default()`: `Default::default()`
|
||||
|
||||
error: used `unwrap()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:28:17
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:30:17
|
||||
|
|
||||
LL | let _val2 = val.unwrap();
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Ok` and `unwrap()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:27:15
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:29:15
|
||||
|
|
||||
LL | let val = Ok::<_, ()>(1);
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: used `expect()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:29:17
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:31:17
|
||||
|
|
||||
LL | let _val2 = val.expect("this never happens");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Ok` and `expect()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:27:15
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:29:15
|
||||
|
|
||||
LL | let val = Ok::<_, ()>(1);
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: used `unwrap_err()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:30:17
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:32:17
|
||||
|
|
||||
LL | let _val2 = val.unwrap_err();
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Ok` and `unwrap_err()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:27:15
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:29:15
|
||||
|
|
||||
LL | let val = Ok::<_, ()>(1);
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: used `expect_err()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:31:17
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:33:17
|
||||
|
|
||||
LL | let _val2 = val.expect_err("this always happens");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Ok` and `expect_err()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:27:15
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:29:15
|
||||
|
|
||||
LL | let val = Ok::<_, ()>(1);
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: used `unwrap()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:35:16
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:37:16
|
||||
|
|
||||
LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Ok` and `unwrap()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:35:16
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:37:16
|
||||
|
|
||||
LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: used `expect()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:36:16
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:38:16
|
||||
|
|
||||
LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).expect("this never happens");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Ok` and `expect()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:36:16
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:38:16
|
||||
|
|
||||
LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).expect("this never happens");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: used `unwrap_err()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:37:16
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:39:16
|
||||
|
|
||||
LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_err();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Ok` and `unwrap_err()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:37:16
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:39:16
|
||||
|
|
||||
LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_err();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: used `expect_err()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:38:16
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:40:16
|
||||
|
|
||||
LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).expect_err("this always happens");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Ok` and `expect_err()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:38:16
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:40:16
|
||||
|
|
||||
LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).expect_err("this always happens");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: used `unwrap()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:41:17
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:43:17
|
||||
|
|
||||
LL | let _val2 = val.unwrap();
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Ok` and `unwrap()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:40:15
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:42:15
|
||||
|
|
||||
LL | let val = Ok::<usize, ()>([1, 2, 3].iter().sum());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: used `expect()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:42:17
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:44:17
|
||||
|
|
||||
LL | let _val2 = val.expect("this never happens");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Ok` and `expect()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:40:15
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:42:15
|
||||
|
|
||||
LL | let val = Ok::<usize, ()>([1, 2, 3].iter().sum());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: used `unwrap_err()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:43:17
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:45:17
|
||||
|
|
||||
LL | let _val2 = val.unwrap_err();
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Ok` and `unwrap_err()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:40:15
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:42:15
|
||||
|
|
||||
LL | let val = Ok::<usize, ()>([1, 2, 3].iter().sum());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: used `expect_err()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:44:17
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:46: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
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:42:15
|
||||
|
|
||||
LL | let val = Ok::<usize, ()>([1, 2, 3].iter().sum());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: used `unwrap_err()` on `Err` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:49:17
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:51:17
|
||||
|
|
||||
LL | let _val2 = val.unwrap_err();
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Err` and `unwrap_err()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:48:15
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:50:15
|
||||
|
|
||||
LL | let val = Err::<(), _>(1);
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: used `expect_err()` on `Err` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:50:17
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:52: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
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:50:15
|
||||
|
|
||||
LL | let val = Err::<(), _>(1);
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: used `unwrap()` on `Err` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:51:17
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:53:17
|
||||
|
|
||||
LL | let _val2 = val.unwrap();
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Err` and `unwrap()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:48:15
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:50:15
|
||||
|
|
||||
LL | let val = Err::<(), _>(1);
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: used `expect()` on `Err` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:52:17
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:54:17
|
||||
|
|
||||
LL | let _val2 = val.expect("this always happens");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Err` and `expect()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:48:15
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:50:15
|
||||
|
|
||||
LL | let val = Err::<(), _>(1);
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: used `unwrap_err()` on `Err` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:56:16
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:58: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
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:58: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
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:59: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
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:59: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
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:60: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
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:60: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
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:61: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
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:61: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
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:64:17
|
||||
|
|
||||
LL | let _val2 = val.unwrap_err();
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Err` and `unwrap_err()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:61:15
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:63: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
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:65:17
|
||||
|
|
||||
LL | let _val2 = val.expect_err("this never happens");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Err` and `expect_err()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:61:15
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:63:15
|
||||
|
|
||||
LL | let val = Err::<(), usize>([1, 2, 3].iter().sum());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: used `unwrap()` on `Err` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:64:17
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:66:17
|
||||
|
|
||||
LL | let _val2 = val.unwrap();
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Err` and `unwrap()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:61:15
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:63:15
|
||||
|
|
||||
LL | let val = Err::<(), usize>([1, 2, 3].iter().sum());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: used `expect()` on `Err` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:65:17
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:67:17
|
||||
|
|
||||
LL | let _val2 = val.expect("this always happens");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Err` and `expect()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:61:15
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:63:15
|
||||
|
|
||||
LL | let val = Err::<(), usize>([1, 2, 3].iter().sum());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: used `unwrap_or()` on `Some` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:70:17
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:72:17
|
||||
|
|
||||
LL | let _val2 = val.unwrap_or(2);
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Some` and `unwrap_or()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:69:15
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:71:15
|
||||
|
|
||||
LL | let val = Some(1);
|
||||
| ^^^^^^^
|
||||
|
||||
error: used `unwrap_or_default()` on `Some` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:71:17
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:73:17
|
||||
|
|
||||
LL | let _val2 = val.unwrap_or_default();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Some` and `unwrap_or_default()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:69:15
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:71:15
|
||||
|
|
||||
LL | let val = Some(1);
|
||||
| ^^^^^^^
|
||||
|
||||
error: used `unwrap_or_else()` on `Some` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:72:17
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:74:17
|
||||
|
|
||||
LL | let _val2 = val.unwrap_or_else(|| 2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Some` and `unwrap_or_else()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:69:15
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:71:15
|
||||
|
|
||||
LL | let val = Some(1);
|
||||
| ^^^^^^^
|
||||
|
||||
error: used `unwrap_or()` on `Some` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:76:16
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:78:16
|
||||
|
|
||||
LL | let _val = Some::<usize>([1, 2, 3].iter().sum()).unwrap_or(2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Some` and `unwrap_or()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:76:16
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:78:16
|
||||
|
|
||||
LL | let _val = Some::<usize>([1, 2, 3].iter().sum()).unwrap_or(2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: used `unwrap_or_default()` on `Some` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:77:16
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:79:16
|
||||
|
|
||||
LL | let _val = Some::<usize>([1, 2, 3].iter().sum()).unwrap_or_default();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Some` and `unwrap_or_default()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:77:16
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:79:16
|
||||
|
|
||||
LL | let _val = Some::<usize>([1, 2, 3].iter().sum()).unwrap_or_default();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: used `unwrap_or_else()` on `Some` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:78:16
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:80:16
|
||||
|
|
||||
LL | let _val = Some::<usize>([1, 2, 3].iter().sum()).unwrap_or_else(|| 2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Some` and `unwrap_or_else()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:78:16
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:80:16
|
||||
|
|
||||
LL | let _val = Some::<usize>([1, 2, 3].iter().sum()).unwrap_or_else(|| 2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: used `unwrap_or()` on `Some` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:81:17
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:83:17
|
||||
|
|
||||
LL | let _val2 = val.unwrap_or(2);
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Some` and `unwrap_or()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:80:15
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:82:15
|
||||
|
|
||||
LL | let val = Some::<usize>([1, 2, 3].iter().sum());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: used `unwrap_or_default()` on `Some` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:82:17
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:84:17
|
||||
|
|
||||
LL | let _val2 = val.unwrap_or_default();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Some` and `unwrap_or_default()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:80:15
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:82:15
|
||||
|
|
||||
LL | let val = Some::<usize>([1, 2, 3].iter().sum());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: used `unwrap_or_else()` on `Some` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:83:17
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:85: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
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:82:15
|
||||
|
|
||||
LL | let val = Some::<usize>([1, 2, 3].iter().sum());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: used `unwrap_or()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:88:17
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:90:17
|
||||
|
|
||||
LL | let _val2 = val.unwrap_or(2);
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Ok` and `unwrap_or()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:87:15
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:89:15
|
||||
|
|
||||
LL | let val = Ok::<_, ()>(1);
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: used `unwrap_or_default()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:89:17
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:91:17
|
||||
|
|
||||
LL | let _val2 = val.unwrap_or_default();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Ok` and `unwrap_or_default()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:87:15
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:89:15
|
||||
|
|
||||
LL | let val = Ok::<_, ()>(1);
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: used `unwrap_or_else()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:90:17
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:92: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
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:89:15
|
||||
|
|
||||
LL | let val = Ok::<_, ()>(1);
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: used `unwrap_or()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:94:16
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:96:16
|
||||
|
|
||||
LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_or(2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Ok` and `unwrap_or()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:94:16
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:96:16
|
||||
|
|
||||
LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_or(2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: used `unwrap_or_default()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:95:16
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:97:16
|
||||
|
|
||||
LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_or_default();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Ok` and `unwrap_or_default()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:95:16
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:97:16
|
||||
|
|
||||
LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_or_default();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: used `unwrap_or_else()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:96:16
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:98:16
|
||||
|
|
||||
LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_or_else(|_| 2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Ok` and `unwrap_or_else()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:96:16
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:98:16
|
||||
|
|
||||
LL | let _val = Ok::<usize, ()>([1, 2, 3].iter().sum()).unwrap_or_else(|_| 2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: used `unwrap_or()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:99:17
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:101:17
|
||||
|
|
||||
LL | let _val2 = val.unwrap_or(2);
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Ok` and `unwrap_or()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:98:15
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:100:15
|
||||
|
|
||||
LL | let val = Ok::<usize, ()>([1, 2, 3].iter().sum());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: used `unwrap_or_default()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:100:17
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:102:17
|
||||
|
|
||||
LL | let _val2 = val.unwrap_or_default();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Ok` and `unwrap_or_default()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:98:15
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:100:15
|
||||
|
|
||||
LL | let val = Ok::<usize, ()>([1, 2, 3].iter().sum());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: used `unwrap_or_else()` on `Ok` value
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:101:17
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:103:17
|
||||
|
|
||||
LL | let _val2 = val.unwrap_or_else(|_| 2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Ok` and `unwrap_or_else()`
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:98:15
|
||||
--> $DIR/unnecessary_literal_unwrap_unfixable.rs:100:15
|
||||
|
|
||||
LL | let val = Ok::<usize, ()>([1, 2, 3].iter().sum());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 50 previous errors
|
||||
error: aborting due to 52 previous errors
|
||||
|
||||
|
|
Loading…
Reference in a new issue