From de84ad95b4b097e504171c7c606bf3715803c13b Mon Sep 17 00:00:00 2001 From: Fabian Zaiser Date: Sat, 7 Nov 2020 14:28:55 +0000 Subject: Implement destructuring assignment for structs and slices Co-authored-by: varkor --- .../clippy/clippy_lints/src/utils/ast_utils.rs | 11 +++++++- src/tools/clippy/tests/ui/crashes/ice-6250.stderr | 29 ++++++++++++++++------ 2 files changed, 32 insertions(+), 8 deletions(-) (limited to 'src/tools') diff --git a/src/tools/clippy/clippy_lints/src/utils/ast_utils.rs b/src/tools/clippy/clippy_lints/src/utils/ast_utils.rs index 0e9feef3746..7b65e664867 100644 --- a/src/tools/clippy/clippy_lints/src/utils/ast_utils.rs +++ b/src/tools/clippy/clippy_lints/src/utils/ast_utils.rs @@ -107,6 +107,15 @@ pub fn eq_expr_opt(l: &Option>, r: &Option>) -> bool { both(l, r, |l, r| eq_expr(l, r)) } +pub fn eq_struct_rest(l: &StructRest, r: &StructRest) -> bool { + match (l, r) { + (StructRest::Base(lb), StructRest::Base(rb)) => eq_expr(lb, rb), + (StructRest::Rest(_), StructRest::Rest(_)) => true, + (StructRest::None, StructRest::None) => true, + _ => false, + } +} + pub fn eq_expr(l: &Expr, r: &Expr) -> bool { use ExprKind::*; if !over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r)) { @@ -150,7 +159,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { (Path(lq, lp), Path(rq, rp)) => both(lq, rq, |l, r| eq_qself(l, r)) && eq_path(lp, rp), (MacCall(l), MacCall(r)) => eq_mac_call(l, r), (Struct(lp, lfs, lb), Struct(rp, rfs, rb)) => { - eq_path(lp, rp) && eq_expr_opt(lb, rb) && unordered_over(lfs, rfs, |l, r| eq_field(l, r)) + eq_path(lp, rp) && eq_struct_rest(lb, rb) && unordered_over(lfs, rfs, |l, r| eq_field(l, r)) }, _ => false, } diff --git a/src/tools/clippy/tests/ui/crashes/ice-6250.stderr b/src/tools/clippy/tests/ui/crashes/ice-6250.stderr index 8241dcd8feb..c38727316cd 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-6250.stderr +++ b/src/tools/clippy/tests/ui/crashes/ice-6250.stderr @@ -1,3 +1,14 @@ +error[E0658]: destructuring assignments are unstable + --> $DIR/ice-6250.rs:12:25 + | +LL | Some(reference) = cache.data.get(key) { + | --------------- ^ + | | + | cannot assign to this expression + | + = note: see issue #71126 for more information + = help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable + error[E0601]: `main` function not found in crate `ice_6250` --> $DIR/ice-6250.rs:4:1 | @@ -10,18 +21,22 @@ LL | | } LL | | } | |_^ consider adding a `main` function to `$DIR/ice-6250.rs` +error[E0308]: mismatched types + --> $DIR/ice-6250.rs:12:14 + | +LL | Some(reference) = cache.data.get(key) { + | ^^^^^^^^^ + | | + | expected integer, found `&i32` + | help: consider dereferencing the borrow: `*reference` + error[E0308]: mismatched types --> $DIR/ice-6250.rs:12:9 | LL | Some(reference) = cache.data.get(key) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `()` - | -help: you might have meant to use pattern matching - | -LL | let Some(reference) = cache.data.get(key) { - | ^^^ -error: aborting due to 2 previous errors +error: aborting due to 4 previous errors -Some errors have detailed explanations: E0308, E0601. +Some errors have detailed explanations: E0308, E0601, E0658. For more information about an error, try `rustc --explain E0308`. -- cgit 1.4.1-3-g733a5 From cd314ae99c15eea83ac8cb7044035160180e41dd Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Wed, 11 Nov 2020 21:28:24 -0600 Subject: update rustfmt --- Cargo.lock | 2 +- src/tools/rustfmt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/tools') diff --git a/Cargo.lock b/Cargo.lock index 45a19fd7963..c72c7b8481b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4329,7 +4329,7 @@ dependencies = [ [[package]] name = "rustfmt-nightly" -version = "1.4.24" +version = "1.4.25" dependencies = [ "annotate-snippets 0.6.1", "anyhow", diff --git a/src/tools/rustfmt b/src/tools/rustfmt index eb894d53708..0f29ff6da0c 160000 --- a/src/tools/rustfmt +++ b/src/tools/rustfmt @@ -1 +1 @@ -Subproject commit eb894d53708122a67762de9489881c11aa8ce257 +Subproject commit 0f29ff6da0c5ff622e739beb8fc3bbe77119b3c1 -- cgit 1.4.1-3-g733a5 From c338c81fbf9d86d365ea5acdef557bd50348c849 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Wed, 11 Nov 2020 20:41:24 -0800 Subject: Update cargo --- src/tools/cargo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/tools') diff --git a/src/tools/cargo b/src/tools/cargo index d5556aeb840..8662ab427a8 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit d5556aeb8405b1fe696adb6e297ad7a1f2989b62 +Subproject commit 8662ab427a8d6ad8047811cc4d78dbd20dd07699 -- cgit 1.4.1-3-g733a5