about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2022-09-09 03:10:06 +0000
committerMichael Goulet <michael@errs.io>2022-09-12 02:00:20 +0000
commit0a605d33cdd2acccbe46141086fce0c500281a6f (patch)
treec674d6de96be8769b407106ab004451d6adb41b0
parent98e1f041b6e33598a18edb928ec9db93a850c6cb (diff)
downloadrust-0a605d33cdd2acccbe46141086fce0c500281a6f.tar.gz
rust-0a605d33cdd2acccbe46141086fce0c500281a6f.zip
No more ret_type_span
-rw-r--r--compiler/rustc_typeck/src/check/_match.rs22
-rw-r--r--compiler/rustc_typeck/src/check/check.rs1
-rw-r--r--compiler/rustc_typeck/src/check/fn_ctxt/mod.rs3
3 files changed, 16 insertions, 10 deletions
diff --git a/compiler/rustc_typeck/src/check/_match.rs b/compiler/rustc_typeck/src/check/_match.rs
index 25bafdfe859..c98caafa6d9 100644
--- a/compiler/rustc_typeck/src/check/_match.rs
+++ b/compiler/rustc_typeck/src/check/_match.rs
@@ -137,9 +137,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                 Some(&arm.body),
                 arm_ty,
                 Some(&mut |err| {
-                    let Some(ret) = self.ret_type_span else {
-                        return;
-                    };
+                    let Some(ret) = self
+                        .tcx
+                        .hir()
+                        .find_by_def_id(self.body_id.owner)
+                        .and_then(|owner| owner.fn_decl())
+                        .map(|decl| decl.output.span())
+                        else { return; };
                     let Expectation::IsLast(stmt) = orig_expected else {
                         return
                     };
@@ -517,9 +521,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                         }
                     }
                 }
-                // If all the obligations hold (or there are no obligations) the tail expression
-                // we can suggest to return a boxed trait object instead of an opaque type.
-                if suggest_box { self.ret_type_span } else { None }
+                if suggest_box {
+                    self.tcx
+                        .hir()
+                        .find_by_def_id(self.body_id.owner)
+                        .and_then(|owner| owner.fn_decl())
+                        .map(|decl| decl.output.span())
+                } else {
+                    None
+                }
             }
             _ => None,
         }
diff --git a/compiler/rustc_typeck/src/check/check.rs b/compiler/rustc_typeck/src/check/check.rs
index 43893263be1..d6fa74c8730 100644
--- a/compiler/rustc_typeck/src/check/check.rs
+++ b/compiler/rustc_typeck/src/check/check.rs
@@ -106,7 +106,6 @@ pub(super) fn check_fn<'a, 'tcx>(
     fcx.return_type_has_opaque = ret_ty != declared_ret_ty;
 
     fcx.ret_coercion = Some(RefCell::new(CoerceMany::new(ret_ty)));
-    fcx.ret_type_span = Some(decl.output.span());
 
     let span = body.value.span;
 
diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs b/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs
index e008d50aa51..0e22971d3aa 100644
--- a/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs
+++ b/compiler/rustc_typeck/src/check/fn_ctxt/mod.rs
@@ -68,8 +68,6 @@ pub struct FnCtxt<'a, 'tcx> {
     /// any).
     pub(super) ret_coercion: Option<RefCell<DynamicCoerceMany<'tcx>>>,
 
-    pub(super) ret_type_span: Option<Span>,
-
     /// Used exclusively to reduce cost of advanced evaluation used for
     /// more helpful diagnostics.
     pub(super) in_tail_expr: bool,
@@ -142,7 +140,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
             param_env,
             err_count_on_creation: inh.tcx.sess.err_count(),
             ret_coercion: None,
-            ret_type_span: None,
             in_tail_expr: false,
             ret_coercion_span: Cell::new(None),
             resume_yield_tys: None,