Add MSRV check for question_mark

This commit is contained in:
Jan Verbeek 2025-03-19 09:16:58 +01:00
parent a422d9e68c
commit d793c0abfa
7 changed files with 80 additions and 4 deletions

View file

@ -409,3 +409,24 @@ fn issue_13417_weirder(foo: &mut StructWithOptionString, mut bar: Option<Wrapper
//~^^^ question_mark
Some(())
}
#[clippy::msrv = "1.12"]
fn msrv_1_12(arg: Option<i32>) -> Option<i32> {
if arg.is_none() {
return None;
}
let val = match arg {
Some(val) => val,
None => return None,
};
println!("{}", val);
Some(val)
}
#[clippy::msrv = "1.13"]
fn msrv_1_13(arg: Option<i32>) -> Option<i32> {
arg?;
let val = arg?;
println!("{}", val);
Some(val)
}

View file

@ -496,3 +496,31 @@ fn issue_13417_weirder(foo: &mut StructWithOptionString, mut bar: Option<Wrapper
//~^^^ question_mark
Some(())
}
#[clippy::msrv = "1.12"]
fn msrv_1_12(arg: Option<i32>) -> Option<i32> {
if arg.is_none() {
return None;
}
let val = match arg {
Some(val) => val,
None => return None,
};
println!("{}", val);
Some(val)
}
#[clippy::msrv = "1.13"]
fn msrv_1_13(arg: Option<i32>) -> Option<i32> {
if arg.is_none() {
//~^ question_mark
return None;
}
let val = match arg {
//~^ question_mark
Some(val) => val,
None => return None,
};
println!("{}", val);
Some(val)
}

View file

@ -255,5 +255,25 @@ LL | | return None;
LL | | };
| |______^ help: replace it with: `let x @ &mut WrapperStructWithString(_) = bar.as_mut()?;`
error: aborting due to 27 previous errors
error: this block may be rewritten with the `?` operator
--> tests/ui/question_mark.rs:515:5
|
LL | / if arg.is_none() {
LL | |
LL | | return None;
LL | | }
| |_____^ help: replace it with: `arg?;`
error: this `match` expression can be replaced with `?`
--> tests/ui/question_mark.rs:519:15
|
LL | let val = match arg {
| _______________^
LL | |
LL | | Some(val) => val,
LL | | None => return None,
LL | | };
| |_____^ help: try instead: `arg?`
error: aborting due to 29 previous errors