From 03622552ecdbac78072ea5e4aa4d7389d606c25c Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Sun, 31 Jul 2022 11:33:01 +0900 Subject: [PATCH] use appropriate `HirID` for finding `else_span` --- .../rustc_infer/src/infer/error_reporting/mod.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 39faed0bf36..20864c657ff 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -712,7 +712,7 @@ fn note_error_origin( opt_suggest_box_span, }) => { let then_span = self.find_block_span_from_hir_id(then_id); - let else_span = self.find_block_span_from_hir_id(then_id); + let else_span = self.find_block_span_from_hir_id(else_id); err.span_label(then_span, "expected because of this"); if let Some(sp) = outer_span { err.span_label(sp, "`if` and `else` have incompatible types"); @@ -760,11 +760,15 @@ fn suggest_remove_semi_or_return_binding( second_ty: Ty<'tcx>, second_span: Span, ) { - let remove_semicolon = - [(first_id, second_ty), (second_id, first_ty)].into_iter().find_map(|(id, ty)| { - let hir::Node::Block(blk) = self.tcx.hir().get(id?) else { return None }; - self.could_remove_semicolon(blk, ty) - }); + let remove_semicolon = [ + (first_id, self.resolve_vars_if_possible(second_ty)), + (second_id, self.resolve_vars_if_possible(first_ty)), + ] + .into_iter() + .find_map(|(id, ty)| { + let hir::Node::Block(blk) = self.tcx.hir().get(id?) else { return None }; + self.could_remove_semicolon(blk, ty) + }); match remove_semicolon { Some((sp, StatementAsExpression::NeedsBoxing)) => { err.multipart_suggestion(