Skip to content

Commit

Permalink
Fix rebase issue and test
Browse files Browse the repository at this point in the history
  • Loading branch information
fanzier committed Nov 4, 2020
1 parent a0d4c55 commit c25779a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
18 changes: 18 additions & 0 deletions compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 4 additions & 13 deletions src/test/ui/suggestions/if-let-typo.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand All @@ -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 {}
| ------- ^
Expand All @@ -75,20 +66,20 @@ 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 {}
| - ^
| |
| 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`.

0 comments on commit c25779a

Please sign in to comment.