about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTakayuki Maeda <takoyaki0316@gmail.com>2022-07-31 11:33:01 +0900
committerTakayuki Maeda <takoyaki0316@gmail.com>2022-07-31 11:33:01 +0900
commit03622552ecdbac78072ea5e4aa4d7389d606c25c (patch)
tree9f891c6e3d5400828e2a1d2dcff8853db01a453a
parenta2318651d4d2c6280a5047544cbf4180119ba966 (diff)
downloadrust-03622552ecdbac78072ea5e4aa4d7389d606c25c.tar.gz
rust-03622552ecdbac78072ea5e4aa4d7389d606c25c.zip
use appropriate `HirID` for finding `else_span`
-rw-r--r--compiler/rustc_infer/src/infer/error_reporting/mod.rs16
1 files 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 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
                 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 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
         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(