@@ -105,6 +105,8 @@ impl<'tcx> LateLintPass<'tcx> for IfThenSomeElseNone {
|
|||||||
snippet_with_context(cx, first_stmt.span.until(then_arg.span), ctxt, "..", &mut app);
|
snippet_with_context(cx, first_stmt.span.until(then_arg.span), ctxt, "..", &mut app);
|
||||||
let closure = if method_name == "then" { "|| " } else { "" };
|
let closure = if method_name == "then" { "|| " } else { "" };
|
||||||
format!("{closure} {{ {block_snippet}; {arg_snip} }}")
|
format!("{closure} {{ {block_snippet}; {arg_snip} }}")
|
||||||
|
} else if method_name == "then" {
|
||||||
|
(std::borrow::Cow::Borrowed("|| ") + arg_snip).into_owned()
|
||||||
} else {
|
} else {
|
||||||
arg_snip.into_owned()
|
arg_snip.into_owned()
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -113,6 +113,10 @@ fn issue11394(b: bool, v: Result<(), ()>) -> Result<(), ()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn issue13407(s: &str) -> Option<bool> {
|
||||||
|
(s == "1").then(|| true)
|
||||||
|
}
|
||||||
|
|
||||||
const fn issue12103(x: u32) -> Option<u32> {
|
const fn issue12103(x: u32) -> Option<u32> {
|
||||||
// Should not issue an error in `const` context
|
// Should not issue an error in `const` context
|
||||||
if x > 42 { Some(150) } else { None }
|
if x > 42 { Some(150) } else { None }
|
||||||
|
|||||||
@@ -131,6 +131,10 @@ fn issue11394(b: bool, v: Result<(), ()>) -> Result<(), ()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn issue13407(s: &str) -> Option<bool> {
|
||||||
|
if s == "1" { Some(true) } else { None }
|
||||||
|
}
|
||||||
|
|
||||||
const fn issue12103(x: u32) -> Option<u32> {
|
const fn issue12103(x: u32) -> Option<u32> {
|
||||||
// Should not issue an error in `const` context
|
// Should not issue an error in `const` context
|
||||||
if x > 42 { Some(150) } else { None }
|
if x > 42 { Some(150) } else { None }
|
||||||
|
|||||||
@@ -52,5 +52,11 @@ LL | | None
|
|||||||
LL | | };
|
LL | | };
|
||||||
| |_____^ help: try: `foo().then(|| { println!("true!"); 150 })`
|
| |_____^ help: try: `foo().then(|| { println!("true!"); 150 })`
|
||||||
|
|
||||||
error: aborting due to 5 previous errors
|
error: this could be simplified with `bool::then`
|
||||||
|
--> tests/ui/if_then_some_else_none.rs:135:5
|
||||||
|
|
|
||||||
|
LL | if s == "1" { Some(true) } else { None }
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(s == "1").then(|| true)`
|
||||||
|
|
||||||
|
error: aborting due to 6 previous errors
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user