about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJack Huey <jack.huey@umassmed.edu>2021-03-11 21:08:49 -0500
committerJack Huey <jack.huey@umassmed.edu>2021-03-31 10:16:37 -0400
commit8ad7e5685ee38af0d1c62808c4eaf8301f3a0db8 (patch)
tree9e10acb3e9cfce56aeb76abd8eeaf78832c5a619
parent6d5efa9f040d2638318f9e8b96eab718ef664e3c (diff)
downloadrust-8ad7e5685ee38af0d1c62808c4eaf8301f3a0db8.tar.gz
rust-8ad7e5685ee38af0d1c62808c4eaf8301f3a0db8.zip
Fix new problem from rebase and a little cleanup
-rw-r--r--compiler/rustc_middle/src/ty/fold.rs15
-rw-r--r--compiler/rustc_typeck/src/check/coercion.rs2
-rw-r--r--compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs7
3 files changed, 14 insertions, 10 deletions
diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs
index 368236b146f..819399141b9 100644
--- a/compiler/rustc_middle/src/ty/fold.rs
+++ b/compiler/rustc_middle/src/ty/fold.rs
@@ -820,7 +820,8 @@ impl<'tcx> TypeVisitor<'tcx> for BoundVarsCollector<'tcx> {
     fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
         match r {
             ty::ReLateBound(index, _br) if *index == self.binder_index => {
-                bug!("{:?} {:?}", index, _br)
+                // If you hit this, you should be using `Binder::bind_with_vars` or `Binder::rebind`
+                bug!("Trying to collect bound vars with a bound region: {:?} {:?}", index, _br)
             }
 
             _ => (),
@@ -870,19 +871,19 @@ impl<'tcx> TypeVisitor<'tcx> for ValidateBoundVars<'tcx> {
         match *t.kind() {
             ty::Bound(debruijn, bound_ty) if debruijn == self.binder_index => {
                 if self.bound_vars.len() <= bound_ty.var.as_usize() {
-                    panic!("Not enough bound vars: {:?} not found in {:?}", t, self.bound_vars);
+                    bug!("Not enough bound vars: {:?} not found in {:?}", t, self.bound_vars);
                 }
                 let list_var = self.bound_vars[bound_ty.var.as_usize()];
                 match list_var {
                     ty::BoundVariableKind::Ty(kind) => {
                         if kind != bound_ty.kind {
-                            panic!(
+                            bug!(
                                 "Mismatched type kinds: {:?} doesn't var in list {:?}",
                                 bound_ty.kind, list_var
                             );
                         }
                     }
-                    _ => panic!(
+                    _ => bug!(
                         "Mismatched bound variable kinds! Expected type, found {:?}",
                         list_var
                     ),
@@ -899,19 +900,19 @@ impl<'tcx> TypeVisitor<'tcx> for ValidateBoundVars<'tcx> {
         match r {
             ty::ReLateBound(index, br) if *index == self.binder_index => {
                 if self.bound_vars.len() <= br.var.as_usize() {
-                    panic!("Not enough bound vars: {:?} not found in {:?}", *br, self.bound_vars);
+                    bug!("Not enough bound vars: {:?} not found in {:?}", *br, self.bound_vars);
                 }
                 let list_var = self.bound_vars[br.var.as_usize()];
                 match list_var {
                     ty::BoundVariableKind::Region(kind) => {
                         if kind != br.kind {
-                            panic!(
+                            bug!(
                                 "Mismatched region kinds: {:?} doesn't match var ({:?}) in list ({:?})",
                                 br.kind, list_var, self.bound_vars
                             );
                         }
                     }
-                    _ => panic!(
+                    _ => bug!(
                         "Mismatched bound variable kinds! Expected region, found {:?}",
                         list_var
                     ),
diff --git a/compiler/rustc_typeck/src/check/coercion.rs b/compiler/rustc_typeck/src/check/coercion.rs
index 94aee87364a..68a923a55eb 100644
--- a/compiler/rustc_typeck/src/check/coercion.rs
+++ b/compiler/rustc_typeck/src/check/coercion.rs
@@ -1487,7 +1487,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
         if let (Some((expr, _)), Some((fn_decl, _, _))) =
             (expression, fcx.get_node_fn_decl(parent_item))
         {
-            fcx.suggest_missing_return_expr(&mut err, expr, fn_decl, expected, found);
+            fcx.suggest_missing_return_expr(&mut err, expr, fn_decl, expected, found, parent_id);
         }
 
         if let (Some(sp), Some(fn_output)) = (fcx.ret_coercion_span.get(), fn_output) {
diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs
index b940e90fadb..6112a5fdc91 100644
--- a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs
+++ b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs
@@ -55,7 +55,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         if let Some((fn_decl, can_suggest)) = self.get_fn_decl(blk_id) {
             pointing_at_return_type =
                 self.suggest_missing_return_type(err, &fn_decl, expected, found, can_suggest);
-            self.suggest_missing_return_expr(err, expr, &fn_decl, expected, found);
+            let fn_id = self.tcx.hir().get_return_block(blk_id).unwrap();
+            self.suggest_missing_return_expr(err, expr, &fn_decl, expected, found, fn_id);
         }
         pointing_at_return_type
     }
@@ -479,6 +480,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         fn_decl: &hir::FnDecl<'_>,
         expected: Ty<'tcx>,
         found: Ty<'tcx>,
+        id: hir::HirId,
     ) {
         if !expected.is_unit() {
             return;
@@ -486,7 +488,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         let found = self.resolve_vars_with_obligations(found);
         if let hir::FnRetTy::Return(ty) = fn_decl.output {
             let ty = <dyn AstConv<'_>>::ast_ty_to_ty(self, ty);
-            let ty = self.tcx.erase_late_bound_regions(Binder::bind(ty, self.tcx));
+            let bound_vars = self.tcx.late_bound_vars(id);
+            let ty = self.tcx.erase_late_bound_regions(Binder::bind_with_vars(ty, bound_vars));
             let ty = self.normalize_associated_types_in(expr.span, ty);
             if self.can_coerce(found, ty) {
                 err.multipart_suggestion(