From f35840f77cbb496dc35645331318f4b52c9a5b2a Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Mon, 30 Dec 2019 08:17:32 +0100 Subject: [PATCH] Pass the span of `` in `let = ;` when type checking ``. --- src/librustc_typeck/check/mod.rs | 10 +++++----- src/librustc_typeck/check/pat.rs | 9 ++------- src/test/ui/issues/issue-14541.stderr | 4 +++- src/test/ui/issues/issue-16338.stderr | 4 +++- src/test/ui/issues/issue-37026.stderr | 4 +++- ...ssue-67037-pat-tup-scrut-ty-diff-less-fields.stderr | 4 +++- 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index c6c3ada49e31..583a0409fb9f 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -4275,17 +4275,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } pub fn check_decl_local(&self, local: &'tcx hir::Local<'tcx>) { - let t = self.local_ty(local.span, local.hir_id).decl_ty; - self.write_ty(local.hir_id, t); + let ty = self.local_ty(local.span, local.hir_id).decl_ty; + self.write_ty(local.hir_id, ty); if let Some(ref init) = local.init { let init_ty = self.check_decl_initializer(local, &init); - self.overwrite_local_ty_if_err(local, t, init_ty); + self.overwrite_local_ty_if_err(local, ty, init_ty); } - self.check_pat_top(&local.pat, t, None); + self.check_pat_top(&local.pat, ty, local.init.map(|init| init.span)); let pat_ty = self.node_ty(local.pat.hir_id); - self.overwrite_local_ty_if_err(local, t, pat_ty); + self.overwrite_local_ty_if_err(local, ty, pat_ty); } fn overwrite_local_ty_if_err( diff --git a/src/librustc_typeck/check/pat.rs b/src/librustc_typeck/check/pat.rs index c7986311242b..b18a7ac75a28 100644 --- a/src/librustc_typeck/check/pat.rs +++ b/src/librustc_typeck/check/pat.rs @@ -59,14 +59,9 @@ impl<'tcx> FnCtxt<'_, 'tcx> { } impl<'a, 'tcx> FnCtxt<'a, 'tcx> { - pub fn check_pat_top( - &self, - pat: &'tcx Pat<'tcx>, - expected: Ty<'tcx>, - discrim_span: Option, - ) { + pub fn check_pat_top(&self, pat: &'tcx Pat<'tcx>, expected: Ty<'tcx>, span: Option) { let def_bm = BindingMode::BindByValue(hir::Mutability::Not); - self.check_pat(pat, expected, def_bm, discrim_span); + self.check_pat(pat, expected, def_bm, span); } /// `discrim_span` argument having a `Span` indicates that this pattern is part of a match diff --git a/src/test/ui/issues/issue-14541.stderr b/src/test/ui/issues/issue-14541.stderr index c5512e03007d..cf155f428c6a 100644 --- a/src/test/ui/issues/issue-14541.stderr +++ b/src/test/ui/issues/issue-14541.stderr @@ -2,7 +2,9 @@ error[E0308]: mismatched types --> $DIR/issue-14541.rs:5:9 | LL | let Vec3 { y: _, z: _ } = v; - | ^^^^^^^^^^^^^^^^^^^ expected struct `Vec2`, found struct `Vec3` + | ^^^^^^^^^^^^^^^^^^^ - this expression has type `Vec2` + | | + | expected struct `Vec2`, found struct `Vec3` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-16338.stderr b/src/test/ui/issues/issue-16338.stderr index c35edb0c8c0e..03eb93821b5f 100644 --- a/src/test/ui/issues/issue-16338.stderr +++ b/src/test/ui/issues/issue-16338.stderr @@ -2,7 +2,9 @@ error[E0308]: mismatched types --> $DIR/issue-16338.rs:7:9 | LL | let Slice { data: data, len: len } = "foo"; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `str`, found struct `Slice` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ----- this expression has type `str` + | | + | expected `str`, found struct `Slice` | = note: expected type `str` found struct `Slice<_>` diff --git a/src/test/ui/issues/issue-37026.stderr b/src/test/ui/issues/issue-37026.stderr index 00952356b183..361369e68bc0 100644 --- a/src/test/ui/issues/issue-37026.stderr +++ b/src/test/ui/issues/issue-37026.stderr @@ -8,7 +8,9 @@ error[E0308]: mismatched types --> $DIR/issue-37026.rs:7:9 | LL | let empty_struct::XEmpty6(..) = (); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found struct `empty_struct::XEmpty6` + | ^^^^^^^^^^^^^^^^^^^^^^^^^ -- this expression has type `()` + | | + | expected `()`, found struct `empty_struct::XEmpty6` error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr b/src/test/ui/issues/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr index 521dd0256f7d..6e8ea6bf618f 100644 --- a/src/test/ui/issues/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr +++ b/src/test/ui/issues/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr @@ -2,7 +2,9 @@ error[E0308]: mismatched types --> $DIR/issue-67037-pat-tup-scrut-ty-diff-less-fields.rs:19:9 | LL | let P() = U {}; - | ^^^ expected struct `U`, found struct `P` + | ^^^ ---- this expression has type `U` + | | + | expected struct `U`, found struct `P` | = note: expected struct `U` found struct `P<_>`