From c25779a6624ac821abbcee18a56fa48f9e6c474e Mon Sep 17 00:00:00 2001 From: Fabian Zaiser Date: Sun, 11 Oct 2020 16:13:49 +0100 Subject: [PATCH] Fix rebase issue and test --- .../rustc_typeck/src/check/fn_ctxt/checks.rs | 18 ++++++++++++++++++ .../struct_destructure_fail.stderr | 9 +++++++++ src/test/ui/suggestions/if-let-typo.stderr | 17 ++++------------- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs index a820661d8432a..9f94d61cf0aba 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs @@ -17,6 +17,7 @@ use rustc_hir::{ExprKind, Node, QPath}; use rustc_middle::ty::adjustment::AllowTwoPhase; use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::{self, Ty}; +use rustc_session::parse::feature_err; use rustc_session::Session; use rustc_span::symbol::{sym, Ident}; use rustc_span::{self, MultiSpan, Span}; @@ -515,6 +516,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// Type check a `let` statement. pub fn check_decl_local(&self, local: &'tcx hir::Local<'tcx>) { + // Check for destructuring assignment. + match local.source { + hir::LocalSource::AssignDesugar(eq_sign_span) + if !self.tcx.features().destructuring_assignment => + { + feature_err( + &self.tcx.sess.parse_sess, + sym::destructuring_assignment, + eq_sign_span, + "destructuring assignments are unstable", + ) + .span_label(local.pat.span, "cannot assign to this expression") + .emit(); + } + _ => {} + } + // Determine and write the type which we'll check the pattern against. let ty = self.local_ty(local.span, local.hir_id).decl_ty; self.write_ty(local.hir_id, ty); diff --git a/src/test/ui/destructuring-assignment/struct_destructure_fail.stderr b/src/test/ui/destructuring-assignment/struct_destructure_fail.stderr index 7317b27d33498..c8ddc4bafc17c 100644 --- a/src/test/ui/destructuring-assignment/struct_destructure_fail.stderr +++ b/src/test/ui/destructuring-assignment/struct_destructure_fail.stderr @@ -29,6 +29,15 @@ error[E0027]: pattern does not mention field `b` | LL | Struct { a, _ } = Struct { a: 1, b: 2 }; | ^^^^^^^^^^^^^^^ missing field `b` + | +help: include the missing field in the pattern + | +LL | Struct { a, b, _ } = Struct { a: 1, b: 2 }; + | ^^^ +help: if you don't care about this missing field, you can explicitely ignore it + | +LL | Struct { a, .., _ } = Struct { a: 1, b: 2 }; + | ^^^^ error: aborting due to 5 previous errors diff --git a/src/test/ui/suggestions/if-let-typo.stderr b/src/test/ui/suggestions/if-let-typo.stderr index b4ac3625b449b..2c8ec11d39495 100644 --- a/src/test/ui/suggestions/if-let-typo.stderr +++ b/src/test/ui/suggestions/if-let-typo.stderr @@ -43,15 +43,6 @@ error[E0308]: mismatched types LL | if Some(foo) = bar {} | ^^^^^^^^^^^^^^^ expected `bool`, found `()` -error[E0308]: mismatched types - --> $DIR/if-let-typo.rs:9:12 - | -LL | if 3 = foo {} - | ^^^ expected integer, found enum `Option` - | - = note: expected type `{integer}` - found enum `Option<{integer}>` - error[E0308]: mismatched types --> $DIR/if-let-typo.rs:9:8 | @@ -64,7 +55,7 @@ LL | if let 3 = foo {} | ^^^ error[E0658]: destructuring assignments are unstable - --> $DIR/if-let-typo.rs:11:16 + --> $DIR/if-let-typo.rs:10:16 | LL | if Some(3) = foo {} | ------- ^ @@ -75,7 +66,7 @@ LL | if Some(3) = foo {} = help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable error[E0070]: invalid left-hand side of assignment - --> $DIR/if-let-typo.rs:11:16 + --> $DIR/if-let-typo.rs:10:16 | LL | if Some(3) = foo {} | - ^ @@ -83,12 +74,12 @@ LL | if Some(3) = foo {} | cannot assign to this expression error[E0308]: mismatched types - --> $DIR/if-let-typo.rs:11:8 + --> $DIR/if-let-typo.rs:10:8 | LL | if Some(3) = foo {} | ^^^^^^^^^^^^^ expected `bool`, found `()` -error: aborting due to 10 previous errors +error: aborting due to 9 previous errors Some errors have detailed explanations: E0070, E0308, E0425, E0658. For more information about an error, try `rustc --explain E0070`.