Skip to content

Commit daed674

Browse files
committed
review comments
1 parent 3e6b844 commit daed674

File tree

3 files changed

+19
-30
lines changed

3 files changed

+19
-30
lines changed

src/librustc_typeck/check/coercion.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -821,11 +821,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
821821

822822
let (adjustments, _) = self.register_infer_ok_obligations(ok);
823823
self.apply_adjustments(expr, adjustments);
824-
if expr_ty.references_error() {
825-
Ok(self.tcx.types.err)
824+
Ok(if expr_ty.references_error() {
825+
self.tcx.types.err
826826
} else {
827-
Ok(target)
828-
}
827+
target
828+
})
829829
}
830830

831831
/// Same as `try_coerce()`, but without side-effects.

src/librustc_typeck/check/mod.rs

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3751,36 +3751,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
37513751

37523752
if let Some(ref init) = local.init {
37533753
let init_ty = self.check_decl_initializer(local, &init);
3754-
if init_ty.references_error() {
3755-
// Override the types everywhere with `types.err` to avoid knock down errors.
3756-
self.write_ty(local.hir_id, init_ty);
3757-
self.write_ty(local.pat.hir_id, init_ty);
3758-
self.locals.borrow_mut().insert(local.hir_id, LocalTy {
3759-
decl_ty: t,
3760-
revealed_ty: init_ty,
3761-
});
3762-
self.locals.borrow_mut().insert(local.pat.hir_id, LocalTy {
3763-
decl_ty: t,
3764-
revealed_ty: init_ty,
3765-
});
3766-
}
3754+
self.overwrite_local_ty_if_err(local, t, init_ty);
37673755
}
37683756

37693757
self.check_pat_top(&local.pat, t, None);
37703758
let pat_ty = self.node_ty(local.pat.hir_id);
3771-
debug!("check_decl_local pat_ty {:?}", pat_ty);
3772-
if pat_ty.references_error() {
3759+
self.overwrite_local_ty_if_err(local, t, pat_ty);
3760+
}
3761+
3762+
fn overwrite_local_ty_if_err(&self, local: &'tcx hir::Local, decl_ty: Ty<'tcx>, ty: Ty<'tcx>) {
3763+
if ty.references_error() {
37733764
// Override the types everywhere with `types.err` to avoid knock down errors.
3774-
self.write_ty(local.hir_id, pat_ty);
3775-
self.write_ty(local.pat.hir_id, pat_ty);
3776-
self.locals.borrow_mut().insert(local.hir_id, LocalTy {
3777-
decl_ty: t,
3778-
revealed_ty: pat_ty,
3779-
});
3780-
self.locals.borrow_mut().insert(local.pat.hir_id, LocalTy {
3781-
decl_ty: t,
3782-
revealed_ty: pat_ty,
3783-
});
3765+
self.write_ty(local.hir_id, ty);
3766+
self.write_ty(local.pat.hir_id, ty);
3767+
let local_ty = LocalTy {
3768+
decl_ty,
3769+
revealed_ty: ty,
3770+
};
3771+
self.locals.borrow_mut().insert(local.hir_id, local_ty);
3772+
self.locals.borrow_mut().insert(local.pat.hir_id, local_ty);
37843773
}
37853774
}
37863775

src/test/ui/issues/issue-33575.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
fn main() {
22
let baz = ().foo(); //~ ERROR no method named `foo` found for type `()` in the current scope
3-
<i32 as std::str::FromStr>::from_str(&baz); // No complains about `str` being unsized
3+
<i32 as std::str::FromStr>::from_str(&baz); // No complaints about `str` being unsized
44
}

0 commit comments

Comments
 (0)