Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Sep 22, 2019
1 parent 3e6b844 commit daed674
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 30 deletions.
8 changes: 4 additions & 4 deletions src/librustc_typeck/check/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,11 +821,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

let (adjustments, _) = self.register_infer_ok_obligations(ok);
self.apply_adjustments(expr, adjustments);
if expr_ty.references_error() {
Ok(self.tcx.types.err)
Ok(if expr_ty.references_error() {
self.tcx.types.err
} else {
Ok(target)
}
target
})
}

/// Same as `try_coerce()`, but without side-effects.
Expand Down
39 changes: 14 additions & 25 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3751,36 +3751,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

if let Some(ref init) = local.init {
let init_ty = self.check_decl_initializer(local, &init);
if init_ty.references_error() {
// Override the types everywhere with `types.err` to avoid knock down errors.
self.write_ty(local.hir_id, init_ty);
self.write_ty(local.pat.hir_id, init_ty);
self.locals.borrow_mut().insert(local.hir_id, LocalTy {
decl_ty: t,
revealed_ty: init_ty,
});
self.locals.borrow_mut().insert(local.pat.hir_id, LocalTy {
decl_ty: t,
revealed_ty: init_ty,
});
}
self.overwrite_local_ty_if_err(local, t, init_ty);
}

self.check_pat_top(&local.pat, t, None);
let pat_ty = self.node_ty(local.pat.hir_id);
debug!("check_decl_local pat_ty {:?}", pat_ty);
if pat_ty.references_error() {
self.overwrite_local_ty_if_err(local, t, pat_ty);
}

fn overwrite_local_ty_if_err(&self, local: &'tcx hir::Local, decl_ty: Ty<'tcx>, ty: Ty<'tcx>) {
if ty.references_error() {
// Override the types everywhere with `types.err` to avoid knock down errors.
self.write_ty(local.hir_id, pat_ty);
self.write_ty(local.pat.hir_id, pat_ty);
self.locals.borrow_mut().insert(local.hir_id, LocalTy {
decl_ty: t,
revealed_ty: pat_ty,
});
self.locals.borrow_mut().insert(local.pat.hir_id, LocalTy {
decl_ty: t,
revealed_ty: pat_ty,
});
self.write_ty(local.hir_id, ty);
self.write_ty(local.pat.hir_id, ty);
let local_ty = LocalTy {
decl_ty,
revealed_ty: ty,
};
self.locals.borrow_mut().insert(local.hir_id, local_ty);
self.locals.borrow_mut().insert(local.pat.hir_id, local_ty);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-33575.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fn main() {
let baz = ().foo(); //~ ERROR no method named `foo` found for type `()` in the current scope
<i32 as std::str::FromStr>::from_str(&baz); // No complains about `str` being unsized
<i32 as std::str::FromStr>::from_str(&baz); // No complaints about `str` being unsized
}

0 comments on commit daed674

Please sign in to comment.