mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-30 10:45:18 +00:00
Add more tests
This commit is contained in:
parent
6e4dc93e24
commit
6cf138e9b6
@ -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;
|
||||
|
@ -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::<usize, ()>(1).unwrap_or(2);
|
||||
let _val = Ok::<usize, ()>(1).unwrap_or_default();
|
||||
let _val = Ok::<usize, ()>(1).unwrap_or_else(|()| _val);
|
||||
let _val = Ok::<usize, ()>(1).unwrap_or_else(|_| 2);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -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::<usize, ()>(1).unwrap_or_else(|()| _val);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | let _val = Ok::<usize, ()>(1).unwrap_or_else(|_| 2);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: remove the `Ok` and `unwrap_or_else()`
|
||||
|
|
||||
LL - let _val = Ok::<usize, ()>(1).unwrap_or_else(|()| _val);
|
||||
LL - let _val = Ok::<usize, ()>(1).unwrap_or_else(|_| 2);
|
||||
LL + let _val = 1;
|
||||
|
|
||||
|
||||
|
@ -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::<usize>;
|
||||
val.unwrap();
|
||||
val.expect("this always happens");
|
||||
}
|
||||
|
||||
fn unwrap_result_ok() {
|
||||
let val = Ok::<usize, ()>(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::<usize, ()>(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();
|
||||
}
|
||||
|
@ -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::<usize>;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
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::<usize>;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
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::<usize, ()>(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::<usize, ()>(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::<usize, ()>(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::<usize, ()>(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::<usize, ()>(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::<usize, ()>(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::<usize, ()>(1);
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 18 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user