summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/manual_let_else.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/clippy/tests/ui/manual_let_else.rs')
-rw-r--r--src/tools/clippy/tests/ui/manual_let_else.rs66
1 files changed, 60 insertions, 6 deletions
diff --git a/src/tools/clippy/tests/ui/manual_let_else.rs b/src/tools/clippy/tests/ui/manual_let_else.rs
index 3996d775f..46241afec 100644
--- a/src/tools/clippy/tests/ui/manual_let_else.rs
+++ b/src/tools/clippy/tests/ui/manual_let_else.rs
@@ -4,7 +4,8 @@
clippy::unused_unit,
clippy::let_unit_value,
clippy::match_single_binding,
- clippy::never_loop
+ clippy::never_loop,
+ clippy::needless_if
)]
#![warn(clippy::manual_let_else)]
@@ -127,8 +128,8 @@ fn fire() {
return;
};
- // Tuples supported for the identity block and pattern
- let v = if let (Some(v_some), w_some) = (g(), 0) {
+ // Tuples supported with multiple bindings
+ let (w, S { v }) = if let (Some(v_some), w_some) = (g().map(|_| S { v: 0 }), 0) {
(w_some, v_some)
} else {
return;
@@ -146,10 +147,44 @@ fn fire() {
Variant::A(0, 0)
}
- // Should not be renamed
let v = if let Variant::A(a, 0) = e() { a } else { return };
- // Should be renamed
- let v = if let Variant::B(b) = e() { b } else { return };
+
+ // `mut v` is inserted into the pattern
+ let mut v = if let Variant::B(b) = e() { b } else { return };
+
+ // Nesting works
+ let nested = Ok(Some(e()));
+ let v = if let Ok(Some(Variant::B(b))) | Err(Some(Variant::A(b, _))) = nested {
+ b
+ } else {
+ return;
+ };
+ // dot dot works
+ let v = if let Variant::A(.., a) = e() { a } else { return };
+
+ // () is preserved: a bit of an edge case but make sure it stays around
+ let w = if let (Some(v), ()) = (g(), ()) { v } else { return };
+
+ // Tuple structs work
+ let w = if let Some(S { v: x }) = Some(S { v: 0 }) {
+ x
+ } else {
+ return;
+ };
+
+ // Field init shorthand is suggested
+ let v = if let Some(S { v: x }) = Some(S { v: 0 }) {
+ x
+ } else {
+ return;
+ };
+
+ // Multi-field structs also work
+ let (x, S { v }, w) = if let Some(U { v, w, x }) = None::<U<S<()>>> {
+ (x, v, w)
+ } else {
+ return;
+ };
}
fn not_fire() {
@@ -274,4 +309,23 @@ fn not_fire() {
};
1
};
+
+ // This would require creation of a suggestion of the form
+ // let v @ (Some(_), _) = (...) else { return };
+ // Which is too advanced for our code, so we just bail.
+ let v = if let (Some(v_some), w_some) = (g(), 0) {
+ (w_some, v_some)
+ } else {
+ return;
+ };
+}
+
+struct S<T> {
+ v: T,
+}
+
+struct U<T> {
+ v: T,
+ w: T,
+ x: T,
}