Skip to content

Commit f35840f

Browse files
committed
Pass the span of <init> in let <pat> = <init>;
when type checking `<pat>`.
1 parent 6137ad4 commit f35840f

File tree

6 files changed

+19
-16
lines changed

6 files changed

+19
-16
lines changed

src/librustc_typeck/check/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -4275,17 +4275,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
42754275
}
42764276

42774277
pub fn check_decl_local(&self, local: &'tcx hir::Local<'tcx>) {
4278-
let t = self.local_ty(local.span, local.hir_id).decl_ty;
4279-
self.write_ty(local.hir_id, t);
4278+
let ty = self.local_ty(local.span, local.hir_id).decl_ty;
4279+
self.write_ty(local.hir_id, ty);
42804280

42814281
if let Some(ref init) = local.init {
42824282
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);
42844284
}
42854285

4286-
self.check_pat_top(&local.pat, t, None);
4286+
self.check_pat_top(&local.pat, ty, local.init.map(|init| init.span));
42874287
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);
42894289
}
42904290

42914291
fn overwrite_local_ty_if_err(

src/librustc_typeck/check/pat.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,9 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
5959
}
6060

6161
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
62-
pub fn check_pat_top(
63-
&self,
64-
pat: &'tcx Pat<'tcx>,
65-
expected: Ty<'tcx>,
66-
discrim_span: Option<Span>,
67-
) {
62+
pub fn check_pat_top(&self, pat: &'tcx Pat<'tcx>, expected: Ty<'tcx>, span: Option<Span>) {
6863
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);
7065
}
7166

7267
/// `discrim_span` argument having a `Span` indicates that this pattern is part of a match

src/test/ui/issues/issue-14541.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0308]: mismatched types
22
--> $DIR/issue-14541.rs:5:9
33
|
44
LL | 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`
68

79
error: aborting due to previous error
810

src/test/ui/issues/issue-16338.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0308]: mismatched types
22
--> $DIR/issue-16338.rs:7:9
33
|
44
LL | 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`
68
|
79
= note: expected type `str`
810
found struct `Slice<_>`

src/test/ui/issues/issue-37026.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ error[E0308]: mismatched types
88
--> $DIR/issue-37026.rs:7:9
99
|
1010
LL | let empty_struct::XEmpty6(..) = ();
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found struct `empty_struct::XEmpty6`
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ -- this expression has type `()`
12+
| |
13+
| expected `()`, found struct `empty_struct::XEmpty6`
1214

1315
error: aborting due to 2 previous errors
1416

src/test/ui/issues/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0308]: mismatched types
22
--> $DIR/issue-67037-pat-tup-scrut-ty-diff-less-fields.rs:19:9
33
|
44
LL | let P() = U {};
5-
| ^^^ expected struct `U`, found struct `P`
5+
| ^^^ ---- this expression has type `U`
6+
| |
7+
| expected struct `U`, found struct `P`
68
|
79
= note: expected struct `U`
810
found struct `P<_>`

0 commit comments

Comments
 (0)