mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 15:11:30 +00:00
Update question_mark
test to behave better
This commit is contained in:
parent
a91ec59460
commit
2fd168285a
3 changed files with 25 additions and 29 deletions
|
@ -2,9 +2,6 @@
|
||||||
#![allow(unreachable_code)]
|
#![allow(unreachable_code)]
|
||||||
#![allow(clippy::unnecessary_wraps)]
|
#![allow(clippy::unnecessary_wraps)]
|
||||||
|
|
||||||
use std::env;
|
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
fn some_func(a: Option<u32>) -> Option<u32> {
|
fn some_func(a: Option<u32>) -> Option<u32> {
|
||||||
a?;
|
a?;
|
||||||
|
|
||||||
|
@ -107,20 +104,20 @@ fn func() -> Option<i32> {
|
||||||
Some(0)
|
Some(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn func_returning_result() -> Result<i32, String> {
|
fn func_returning_result() -> Result<i32, i32> {
|
||||||
Ok(1)
|
Ok(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn result_func(x: Result<i32, String>) -> Result<i32, String> {
|
fn result_func(x: Result<i32, i32>) -> Result<i32, i32> {
|
||||||
let _ = x?;
|
let _ = x?;
|
||||||
|
|
||||||
x.as_ref()?;
|
x?;
|
||||||
|
|
||||||
// No warning
|
// No warning
|
||||||
let y = if let Ok(x) = x {
|
let y = if let Ok(x) = x {
|
||||||
x
|
x
|
||||||
} else {
|
} else {
|
||||||
return Err("some error".to_string());
|
return Err(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
// issue #7859
|
// issue #7859
|
||||||
|
@ -128,9 +125,10 @@ fn result_func(x: Result<i32, String>) -> Result<i32, String> {
|
||||||
let _ = if let Ok(x) = func_returning_result() {
|
let _ = if let Ok(x) = func_returning_result() {
|
||||||
x
|
x
|
||||||
} else {
|
} else {
|
||||||
return Err("some error".to_string());
|
return Err(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// no warning
|
||||||
if func_returning_result().is_err() {
|
if func_returning_result().is_err() {
|
||||||
return func_returning_result();
|
return func_returning_result();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,6 @@
|
||||||
#![allow(unreachable_code)]
|
#![allow(unreachable_code)]
|
||||||
#![allow(clippy::unnecessary_wraps)]
|
#![allow(clippy::unnecessary_wraps)]
|
||||||
|
|
||||||
use std::env;
|
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
fn some_func(a: Option<u32>) -> Option<u32> {
|
fn some_func(a: Option<u32>) -> Option<u32> {
|
||||||
if a.is_none() {
|
if a.is_none() {
|
||||||
return None;
|
return None;
|
||||||
|
@ -137,11 +134,11 @@ fn func() -> Option<i32> {
|
||||||
Some(0)
|
Some(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn func_returning_result() -> Result<i32, String> {
|
fn func_returning_result() -> Result<i32, i32> {
|
||||||
Ok(1)
|
Ok(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn result_func(x: Result<i32, String>) -> Result<i32, String> {
|
fn result_func(x: Result<i32, i32>) -> Result<i32, i32> {
|
||||||
let _ = if let Ok(x) = x { x } else { return x };
|
let _ = if let Ok(x) = x { x } else { return x };
|
||||||
|
|
||||||
if x.is_err() {
|
if x.is_err() {
|
||||||
|
@ -152,7 +149,7 @@ fn result_func(x: Result<i32, String>) -> Result<i32, String> {
|
||||||
let y = if let Ok(x) = x {
|
let y = if let Ok(x) = x {
|
||||||
x
|
x
|
||||||
} else {
|
} else {
|
||||||
return Err("some error".to_string());
|
return Err(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
// issue #7859
|
// issue #7859
|
||||||
|
@ -160,9 +157,10 @@ fn result_func(x: Result<i32, String>) -> Result<i32, String> {
|
||||||
let _ = if let Ok(x) = func_returning_result() {
|
let _ = if let Ok(x) = func_returning_result() {
|
||||||
x
|
x
|
||||||
} else {
|
} else {
|
||||||
return Err("some error".to_string());
|
return Err(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// no warning
|
||||||
if func_returning_result().is_err() {
|
if func_returning_result().is_err() {
|
||||||
return func_returning_result();
|
return func_returning_result();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error: this block may be rewritten with the `?` operator
|
error: this block may be rewritten with the `?` operator
|
||||||
--> $DIR/question_mark.rs:9:5
|
--> $DIR/question_mark.rs:6:5
|
||||||
|
|
|
|
||||||
LL | / if a.is_none() {
|
LL | / if a.is_none() {
|
||||||
LL | | return None;
|
LL | | return None;
|
||||||
|
@ -9,7 +9,7 @@ LL | | }
|
||||||
= note: `-D clippy::question-mark` implied by `-D warnings`
|
= note: `-D clippy::question-mark` implied by `-D warnings`
|
||||||
|
|
||||||
error: this block may be rewritten with the `?` operator
|
error: this block may be rewritten with the `?` operator
|
||||||
--> $DIR/question_mark.rs:54:9
|
--> $DIR/question_mark.rs:51:9
|
||||||
|
|
|
|
||||||
LL | / if (self.opt).is_none() {
|
LL | / if (self.opt).is_none() {
|
||||||
LL | | return None;
|
LL | | return None;
|
||||||
|
@ -17,7 +17,7 @@ LL | | }
|
||||||
| |_________^ help: replace it with: `(self.opt)?;`
|
| |_________^ help: replace it with: `(self.opt)?;`
|
||||||
|
|
||||||
error: this block may be rewritten with the `?` operator
|
error: this block may be rewritten with the `?` operator
|
||||||
--> $DIR/question_mark.rs:58:9
|
--> $DIR/question_mark.rs:55:9
|
||||||
|
|
|
|
||||||
LL | / if self.opt.is_none() {
|
LL | / if self.opt.is_none() {
|
||||||
LL | | return None
|
LL | | return None
|
||||||
|
@ -25,7 +25,7 @@ LL | | }
|
||||||
| |_________^ help: replace it with: `self.opt?;`
|
| |_________^ help: replace it with: `self.opt?;`
|
||||||
|
|
||||||
error: this block may be rewritten with the `?` operator
|
error: this block may be rewritten with the `?` operator
|
||||||
--> $DIR/question_mark.rs:62:17
|
--> $DIR/question_mark.rs:59:17
|
||||||
|
|
|
|
||||||
LL | let _ = if self.opt.is_none() {
|
LL | let _ = if self.opt.is_none() {
|
||||||
| _________________^
|
| _________________^
|
||||||
|
@ -36,7 +36,7 @@ LL | | };
|
||||||
| |_________^ help: replace it with: `Some(self.opt?)`
|
| |_________^ help: replace it with: `Some(self.opt?)`
|
||||||
|
|
||||||
error: this if-let-else may be rewritten with the `?` operator
|
error: this if-let-else may be rewritten with the `?` operator
|
||||||
--> $DIR/question_mark.rs:68:17
|
--> $DIR/question_mark.rs:65:17
|
||||||
|
|
|
|
||||||
LL | let _ = if let Some(x) = self.opt {
|
LL | let _ = if let Some(x) = self.opt {
|
||||||
| _________________^
|
| _________________^
|
||||||
|
@ -47,7 +47,7 @@ LL | | };
|
||||||
| |_________^ help: replace it with: `self.opt?`
|
| |_________^ help: replace it with: `self.opt?`
|
||||||
|
|
||||||
error: this block may be rewritten with the `?` operator
|
error: this block may be rewritten with the `?` operator
|
||||||
--> $DIR/question_mark.rs:85:9
|
--> $DIR/question_mark.rs:82:9
|
||||||
|
|
|
|
||||||
LL | / if self.opt.is_none() {
|
LL | / if self.opt.is_none() {
|
||||||
LL | | return None;
|
LL | | return None;
|
||||||
|
@ -55,7 +55,7 @@ LL | | }
|
||||||
| |_________^ help: replace it with: `self.opt.as_ref()?;`
|
| |_________^ help: replace it with: `self.opt.as_ref()?;`
|
||||||
|
|
||||||
error: this block may be rewritten with the `?` operator
|
error: this block may be rewritten with the `?` operator
|
||||||
--> $DIR/question_mark.rs:93:9
|
--> $DIR/question_mark.rs:90:9
|
||||||
|
|
|
|
||||||
LL | / if self.opt.is_none() {
|
LL | / if self.opt.is_none() {
|
||||||
LL | | return None;
|
LL | | return None;
|
||||||
|
@ -63,7 +63,7 @@ LL | | }
|
||||||
| |_________^ help: replace it with: `self.opt.as_ref()?;`
|
| |_________^ help: replace it with: `self.opt.as_ref()?;`
|
||||||
|
|
||||||
error: this block may be rewritten with the `?` operator
|
error: this block may be rewritten with the `?` operator
|
||||||
--> $DIR/question_mark.rs:101:9
|
--> $DIR/question_mark.rs:98:9
|
||||||
|
|
|
|
||||||
LL | / if self.opt.is_none() {
|
LL | / if self.opt.is_none() {
|
||||||
LL | | return None;
|
LL | | return None;
|
||||||
|
@ -71,7 +71,7 @@ LL | | }
|
||||||
| |_________^ help: replace it with: `self.opt.as_ref()?;`
|
| |_________^ help: replace it with: `self.opt.as_ref()?;`
|
||||||
|
|
||||||
error: this if-let-else may be rewritten with the `?` operator
|
error: this if-let-else may be rewritten with the `?` operator
|
||||||
--> $DIR/question_mark.rs:108:26
|
--> $DIR/question_mark.rs:105:26
|
||||||
|
|
|
|
||||||
LL | let v: &Vec<_> = if let Some(ref v) = self.opt {
|
LL | let v: &Vec<_> = if let Some(ref v) = self.opt {
|
||||||
| __________________________^
|
| __________________________^
|
||||||
|
@ -82,7 +82,7 @@ LL | | };
|
||||||
| |_________^ help: replace it with: `self.opt.as_ref()?`
|
| |_________^ help: replace it with: `self.opt.as_ref()?`
|
||||||
|
|
||||||
error: this if-let-else may be rewritten with the `?` operator
|
error: this if-let-else may be rewritten with the `?` operator
|
||||||
--> $DIR/question_mark.rs:118:17
|
--> $DIR/question_mark.rs:115:17
|
||||||
|
|
|
|
||||||
LL | let v = if let Some(v) = self.opt {
|
LL | let v = if let Some(v) = self.opt {
|
||||||
| _________________^
|
| _________________^
|
||||||
|
@ -93,7 +93,7 @@ LL | | };
|
||||||
| |_________^ help: replace it with: `self.opt?`
|
| |_________^ help: replace it with: `self.opt?`
|
||||||
|
|
||||||
error: this block may be rewritten with the `?` operator
|
error: this block may be rewritten with the `?` operator
|
||||||
--> $DIR/question_mark.rs:133:5
|
--> $DIR/question_mark.rs:130:5
|
||||||
|
|
|
|
||||||
LL | / if f().is_none() {
|
LL | / if f().is_none() {
|
||||||
LL | | return None;
|
LL | | return None;
|
||||||
|
@ -101,18 +101,18 @@ LL | | }
|
||||||
| |_____^ help: replace it with: `f()?;`
|
| |_____^ help: replace it with: `f()?;`
|
||||||
|
|
||||||
error: this if-let-else may be rewritten with the `?` operator
|
error: this if-let-else may be rewritten with the `?` operator
|
||||||
--> $DIR/question_mark.rs:145:13
|
--> $DIR/question_mark.rs:142:13
|
||||||
|
|
|
|
||||||
LL | let _ = if let Ok(x) = x { x } else { return x };
|
LL | let _ = if let Ok(x) = x { x } else { return x };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `x?`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `x?`
|
||||||
|
|
||||||
error: this block may be rewritten with the `?` operator
|
error: this block may be rewritten with the `?` operator
|
||||||
--> $DIR/question_mark.rs:147:5
|
--> $DIR/question_mark.rs:144:5
|
||||||
|
|
|
|
||||||
LL | / if x.is_err() {
|
LL | / if x.is_err() {
|
||||||
LL | | return x;
|
LL | | return x;
|
||||||
LL | | }
|
LL | | }
|
||||||
| |_____^ help: replace it with: `x.as_ref()?;`
|
| |_____^ help: replace it with: `x?;`
|
||||||
|
|
||||||
error: aborting due to 13 previous errors
|
error: aborting due to 13 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue