summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-12-30 08:17:32 +0100
committerMazdak Farrokhzad <twingoow@gmail.com>2019-12-30 13:50:20 +0100
commitf35840f77cbb496dc35645331318f4b52c9a5b2a (patch)
tree42683216e51f715832a2b336200dba0c8991bb37
parentmove demand_eqtype_pat* to pat.rs (diff)
downloadrust-f35840f77cbb496dc35645331318f4b52c9a5b2a.tar.gz
rust-f35840f77cbb496dc35645331318f4b52c9a5b2a.tar.bz2
rust-f35840f77cbb496dc35645331318f4b52c9a5b2a.tar.xz
Pass the span of `<init>` in `let <pat> = <init>;`
when type checking `<pat>`.
-rw-r--r--src/librustc_typeck/check/mod.rs10
-rw-r--r--src/librustc_typeck/check/pat.rs9
-rw-r--r--src/test/ui/issues/issue-14541.stderr4
-rw-r--r--src/test/ui/issues/issue-16338.stderr4
-rw-r--r--src/test/ui/issues/issue-37026.stderr4
-rw-r--r--src/test/ui/issues/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr4
6 files changed, 19 insertions, 16 deletions
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index c6c3ada..583a040 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> {
4275 } 4275 }
4276 4276
4277 pub fn check_decl_local(&self, local: &'tcx hir::Local<'tcx>) { 4277 pub fn check_decl_local(&self, local: &'tcx hir::Local<'tcx>) {
4278 let t = self.local_ty(local.span, local.hir_id).decl_ty; 4278 let ty = self.local_ty(local.span, local.hir_id).decl_ty;
4279 self.write_ty(local.hir_id, t); 4279 self.write_ty(local.hir_id, ty);
4280 4280
4281 if let Some(ref init) = local.init { 4281 if let Some(ref init) = local.init {
4282 let init_ty = self.check_decl_initializer(local, &init); 4282 let init_ty = self.check_decl_initializer(local, &init);
4283 self.overwrite_local_ty_if_err(local, t, init_ty); 4283 self.overwrite_local_ty_if_err(local, ty, init_ty);
4284 } 4284 }
4285 4285
4286 self.check_pat_top(&local.pat, t, None); 4286 self.check_pat_top(&local.pat, ty, local.init.map(|init| init.span));
4287 let pat_ty = self.node_ty(local.pat.hir_id); 4287 let pat_ty = self.node_ty(local.pat.hir_id);
4288 self.overwrite_local_ty_if_err(local, t, pat_ty); 4288 self.overwrite_local_ty_if_err(local, ty, pat_ty);
4289 } 4289 }
4290 4290
4291 fn overwrite_local_ty_if_err( 4291 fn overwrite_local_ty_if_err(
diff --git a/src/librustc_typeck/check/pat.rs b/src/librustc_typeck/check/pat.rs
index c798631..b18a7ac 100644
--- a/src/librustc_typeck/check/pat.rs
+++ b/src/librustc_typeck/check/pat.rs
@@ -59,14 +59,9 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
59} 59}
60 60
61impl<'a, 'tcx> FnCtxt<'a, 'tcx> { 61impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
62 pub fn check_pat_top( 62 pub fn check_pat_top(&self, pat: &'tcx Pat<'tcx>, expected: Ty<'tcx>, span: Option<Span>) {
63 &self,
64 pat: &'tcx Pat<'tcx>,
65 expected: Ty<'tcx>,
66 discrim_span: Option<Span>,
67 ) {
68 let def_bm = BindingMode::BindByValue(hir::Mutability::Not); 63 let def_bm = BindingMode::BindByValue(hir::Mutability::Not);
69 self.check_pat(pat, expected, def_bm, discrim_span); 64 self.check_pat(pat, expected, def_bm, span);
70 } 65 }
71 66
72 /// `discrim_span` argument having a `Span` indicates that this pattern is part of a match 67 /// `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 c5512e0..cf155f4 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
2 --> $DIR/issue-14541.rs:5:9 2 --> $DIR/issue-14541.rs:5:9
3 | 3 |
4LL | let Vec3 { y: _, z: _ } = v; 4LL | let Vec3 { y: _, z: _ } = v;
5 | ^^^^^^^^^^^^^^^^^^^ expected struct `Vec2`, found struct `Vec3` 5 | ^^^^^^^^^^^^^^^^^^^ - this expression has type `Vec2`
6 | |
7 | expected struct `Vec2`, found struct `Vec3`
6 8
7error: aborting due to previous error 9error: aborting due to previous error
8 10
diff --git a/src/test/ui/issues/issue-16338.stderr b/src/test/ui/issues/issue-16338.stderr
index c35edb0..03eb938 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
2 --> $DIR/issue-16338.rs:7:9 2 --> $DIR/issue-16338.rs:7:9
3 | 3 |
4LL | let Slice { data: data, len: len } = "foo"; 4LL | let Slice { data: data, len: len } = "foo";
5 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `str`, found struct `Slice` 5 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ----- this expression has type `str`
6 | |
7 | expected `str`, found struct `Slice`
6 | 8 |
7 = note: expected type `str` 9 = note: expected type `str`
8 found struct `Slice<_>` 10 found struct `Slice<_>`
diff --git a/src/test/ui/issues/issue-37026.stderr b/src/test/ui/issues/issue-37026.stderr
index 0095235..361369e 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
8 --> $DIR/issue-37026.rs:7:9 8 --> $DIR/issue-37026.rs:7:9
9 | 9 |
10LL | let empty_struct::XEmpty6(..) = (); 10LL | let empty_struct::XEmpty6(..) = ();
11 | ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found struct `empty_struct::XEmpty6` 11 | ^^^^^^^^^^^^^^^^^^^^^^^^^ -- this expression has type `()`
12 | |
13 | expected `()`, found struct `empty_struct::XEmpty6`
12 14
13error: aborting due to 2 previous errors 15error: aborting due to 2 previous errors
14 16
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 521dd02..6e8ea6b 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
2 --> $DIR/issue-67037-pat-tup-scrut-ty-diff-less-fields.rs:19:9 2 --> $DIR/issue-67037-pat-tup-scrut-ty-diff-less-fields.rs:19:9
3 | 3 |
4LL | let P() = U {}; 4LL | let P() = U {};
5 | ^^^ expected struct `U`, found struct `P` 5 | ^^^ ---- this expression has type `U`
6 | |
7 | expected struct `U`, found struct `P`
6 | 8 |
7 = note: expected struct `U` 9 = note: expected struct `U`
8 found struct `P<_>` 10 found struct `P<_>`