Propagate types.err in locals further to avoid spurious knock-down errors

This commit is contained in:
Esteban Küber 2019-09-21 16:31:27 -07:00
parent 9ad1e7c46c
commit 3e6b84474d
4 changed files with 41 additions and 3 deletions

View File

@ -163,7 +163,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
// Just ignore error types.
if a.references_error() || b.references_error() {
return success(vec![], b, vec![]);
return success(vec![], self.fcx.tcx.types.err, vec![]);
}
if a.is_never() {
@ -821,7 +821,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let (adjustments, _) = self.register_infer_ok_obligations(ok);
self.apply_adjustments(expr, adjustments);
Ok(target)
if expr_ty.references_error() {
Ok(self.tcx.types.err)
} else {
Ok(target)
}
}
/// Same as `try_coerce()`, but without side-effects.

View File

@ -153,7 +153,7 @@ use self::method::{MethodCallee, SelfSource};
use self::TupleArgumentsFlag::*;
/// The type of a local binding, including the revealed type for anon types.
#[derive(Copy, Clone)]
#[derive(Copy, Clone, Debug)]
pub struct LocalTy<'tcx> {
decl_ty: Ty<'tcx>,
revealed_ty: Ty<'tcx>
@ -3752,14 +3752,35 @@ 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.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() {
// 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,
});
}
}

View File

@ -0,0 +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
}

View File

@ -0,0 +1,9 @@
error[E0599]: no method named `foo` found for type `()` in the current scope
--> $DIR/issue-33575.rs:2:18
|
LL | let baz = ().foo();
| ^^^ method not found in `()`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0599`.