mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 17:24:06 +00:00
Pass the span of <init>
in let <pat> = <init>;
when type checking `<pat>`.
This commit is contained in:
parent
6137ad49e4
commit
f35840f77c
@ -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(
|
||||
|
@ -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<Span>,
|
||||
) {
|
||||
pub fn check_pat_top(&self, pat: &'tcx Pat<'tcx>, expected: Ty<'tcx>, span: Option<Span>) {
|
||||
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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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<_>`
|
||||
|
@ -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
|
||||
|
||||
|
@ -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<_>`
|
||||
|
Loading…
Reference in New Issue
Block a user