Skip to content

Commit c25779a

Browse files
committed
Fix rebase issue and test
1 parent a0d4c55 commit c25779a

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+18
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rustc_hir::{ExprKind, Node, QPath};
1717
use rustc_middle::ty::adjustment::AllowTwoPhase;
1818
use rustc_middle::ty::fold::TypeFoldable;
1919
use rustc_middle::ty::{self, Ty};
20+
use rustc_session::parse::feature_err;
2021
use rustc_session::Session;
2122
use rustc_span::symbol::{sym, Ident};
2223
use rustc_span::{self, MultiSpan, Span};
@@ -515,6 +516,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
515516

516517
/// Type check a `let` statement.
517518
pub fn check_decl_local(&self, local: &'tcx hir::Local<'tcx>) {
519+
// Check for destructuring assignment.
520+
match local.source {
521+
hir::LocalSource::AssignDesugar(eq_sign_span)
522+
if !self.tcx.features().destructuring_assignment =>
523+
{
524+
feature_err(
525+
&self.tcx.sess.parse_sess,
526+
sym::destructuring_assignment,
527+
eq_sign_span,
528+
"destructuring assignments are unstable",
529+
)
530+
.span_label(local.pat.span, "cannot assign to this expression")
531+
.emit();
532+
}
533+
_ => {}
534+
}
535+
518536
// Determine and write the type which we'll check the pattern against.
519537
let ty = self.local_ty(local.span, local.hir_id).decl_ty;
520538
self.write_ty(local.hir_id, ty);

src/test/ui/destructuring-assignment/struct_destructure_fail.stderr

+9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ error[E0027]: pattern does not mention field `b`
2929
|
3030
LL | Struct { a, _ } = Struct { a: 1, b: 2 };
3131
| ^^^^^^^^^^^^^^^ missing field `b`
32+
|
33+
help: include the missing field in the pattern
34+
|
35+
LL | Struct { a, b, _ } = Struct { a: 1, b: 2 };
36+
| ^^^
37+
help: if you don't care about this missing field, you can explicitely ignore it
38+
|
39+
LL | Struct { a, .., _ } = Struct { a: 1, b: 2 };
40+
| ^^^^
3241

3342
error: aborting due to 5 previous errors
3443

src/test/ui/suggestions/if-let-typo.stderr

+4-13
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,6 @@ error[E0308]: mismatched types
4343
LL | if Some(foo) = bar {}
4444
| ^^^^^^^^^^^^^^^ expected `bool`, found `()`
4545

46-
error[E0308]: mismatched types
47-
--> $DIR/if-let-typo.rs:9:12
48-
|
49-
LL | if 3 = foo {}
50-
| ^^^ expected integer, found enum `Option`
51-
|
52-
= note: expected type `{integer}`
53-
found enum `Option<{integer}>`
54-
5546
error[E0308]: mismatched types
5647
--> $DIR/if-let-typo.rs:9:8
5748
|
@@ -64,7 +55,7 @@ LL | if let 3 = foo {}
6455
| ^^^
6556

6657
error[E0658]: destructuring assignments are unstable
67-
--> $DIR/if-let-typo.rs:11:16
58+
--> $DIR/if-let-typo.rs:10:16
6859
|
6960
LL | if Some(3) = foo {}
7061
| ------- ^
@@ -75,20 +66,20 @@ LL | if Some(3) = foo {}
7566
= help: add `#![feature(destructuring_assignment)]` to the crate attributes to enable
7667

7768
error[E0070]: invalid left-hand side of assignment
78-
--> $DIR/if-let-typo.rs:11:16
69+
--> $DIR/if-let-typo.rs:10:16
7970
|
8071
LL | if Some(3) = foo {}
8172
| - ^
8273
| |
8374
| cannot assign to this expression
8475

8576
error[E0308]: mismatched types
86-
--> $DIR/if-let-typo.rs:11:8
77+
--> $DIR/if-let-typo.rs:10:8
8778
|
8879
LL | if Some(3) = foo {}
8980
| ^^^^^^^^^^^^^ expected `bool`, found `()`
9081

91-
error: aborting due to 10 previous errors
82+
error: aborting due to 9 previous errors
9283

9384
Some errors have detailed explanations: E0070, E0308, E0425, E0658.
9485
For more information about an error, try `rustc --explain E0070`.

0 commit comments

Comments
 (0)