diff --git a/compiler/rustc_typeck/src/check/_match.rs b/compiler/rustc_typeck/src/check/_match.rs index a8160313228b..f38ea7417499 100644 --- a/compiler/rustc_typeck/src/check/_match.rs +++ b/compiler/rustc_typeck/src/check/_match.rs @@ -80,7 +80,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.diverges.set(Diverges::Maybe); match g { hir::Guard::If(e) => { - self.check_expr_has_type_or_error(e, tcx.types.bool, |_| {}); + self.check_expr_has_type_or_error(e, tcx.types.bool, |_, _| {}); } hir::Guard::IfLet(pat, e) => { let scrutinee_ty = self.demand_scrutinee_type( @@ -478,7 +478,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { kind: TypeVariableOriginKind::TypeInference, span: scrut.span, }); - self.check_expr_has_type_or_error(scrut, scrut_ty, |_| {}); + self.check_expr_has_type_or_error(scrut, scrut_ty, |_, _| {}); scrut_ty } } diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index 311106474bea..f672afe2b19b 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -59,7 +59,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &self, expr: &'tcx hir::Expr<'tcx>, expected: Ty<'tcx>, - extend_err: impl Fn(&mut DiagnosticBuilder<'_>), + extend_err: impl Fn(&mut DiagnosticBuilder<'_>, Ty<'tcx>), ) -> Ty<'tcx> { self.check_expr_meets_expectation_or_error(expr, ExpectHasType(expected), extend_err) } @@ -68,7 +68,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &self, expr: &'tcx hir::Expr<'tcx>, expected: Expectation<'tcx>, - extend_err: impl Fn(&mut DiagnosticBuilder<'_>), + extend_err: impl Fn(&mut DiagnosticBuilder<'_>, Ty<'tcx>), ) -> Ty<'tcx> { let expected_ty = expected.to_option(&self).unwrap_or(self.tcx.types.bool); let mut ty = self.check_expr_with_expectation(expr, expected); @@ -94,7 +94,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let Some(mut err) = self.demand_suptype_diag(expr.span, expected_ty, ty) { let expr = expr.peel_drop_temps(); self.suggest_deref_ref_or_into(&mut err, expr, expected_ty, ty, None); - extend_err(&mut err); + extend_err(&mut err, ty); err.emit(); } ty @@ -907,7 +907,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { sp: Span, orig_expected: Expectation<'tcx>, ) -> Ty<'tcx> { - let cond_ty = self.check_expr_has_type_or_error(cond_expr, self.tcx.types.bool, |_| {}); + let cond_ty = self.check_expr_has_type_or_error(cond_expr, self.tcx.types.bool, |_, _| {}); self.warn_if_unreachable( cond_expr.hir_id, @@ -1264,7 +1264,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { kind: TypeVariableOriginKind::MiscVariable, span: element.span, }); - let element_ty = self.check_expr_has_type_or_error(&element, ty, |_| {}); + let element_ty = self.check_expr_has_type_or_error(&element, ty, |_, _| {}); (element_ty, ty) } }; @@ -1508,8 +1508,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } } else { - self.check_expr_has_type_or_error(base_expr, adt_ty, |_| { - let base_ty = self.check_expr(base_expr); + self.check_expr_has_type_or_error(base_expr, adt_ty, |_, base_ty| { let same_adt = match (adt_ty.kind(), base_ty.kind()) { (ty::Adt(adt, _), ty::Adt(base_adt, _)) if adt == base_adt => true, _ => false, diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs index 74d7f0a80b6c..3d121bdd517b 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs @@ -611,7 +611,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { hir::StmtKind::Item(_) => {} hir::StmtKind::Expr(ref expr) => { // Check with expected type of `()`. - self.check_expr_has_type_or_error(&expr, self.tcx.mk_unit(), |err| { + self.check_expr_has_type_or_error(&expr, self.tcx.mk_unit(), |err, _| { if expr.can_have_side_effects() { self.suggest_semicolon_at_end(expr.span, err); } diff --git a/src/test/ui/structs/issue-91502.rs b/src/test/ui/structs/issue-91502.rs new file mode 100644 index 000000000000..dba0593f7818 --- /dev/null +++ b/src/test/ui/structs/issue-91502.rs @@ -0,0 +1,9 @@ +struct Bar {} + +fn main() { + let old: Option = None; + + let b = Bar { + ..old.as_ref().unwrap() //~ ERROR E0308 + }; +} diff --git a/src/test/ui/structs/issue-91502.stderr b/src/test/ui/structs/issue-91502.stderr new file mode 100644 index 000000000000..f47c81ccc355 --- /dev/null +++ b/src/test/ui/structs/issue-91502.stderr @@ -0,0 +1,9 @@ +error[E0308]: mismatched types + --> $DIR/issue-91502.rs:7:11 + | +LL | ..old.as_ref().unwrap() + | ^^^^^^^^^^^^^^^^^^^^^ expected struct `Bar`, found `&Bar` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`.