Skip to content

Commit 8ad7e56

Browse files
committed
Fix new problem from rebase and a little cleanup
1 parent 6d5efa9 commit 8ad7e56

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

compiler/rustc_middle/src/ty/fold.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,8 @@ impl<'tcx> TypeVisitor<'tcx> for BoundVarsCollector<'tcx> {
820820
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
821821
match r {
822822
ty::ReLateBound(index, _br) if *index == self.binder_index => {
823-
bug!("{:?} {:?}", index, _br)
823+
// If you hit this, you should be using `Binder::bind_with_vars` or `Binder::rebind`
824+
bug!("Trying to collect bound vars with a bound region: {:?} {:?}", index, _br)
824825
}
825826

826827
_ => (),
@@ -870,19 +871,19 @@ impl<'tcx> TypeVisitor<'tcx> for ValidateBoundVars<'tcx> {
870871
match *t.kind() {
871872
ty::Bound(debruijn, bound_ty) if debruijn == self.binder_index => {
872873
if self.bound_vars.len() <= bound_ty.var.as_usize() {
873-
panic!("Not enough bound vars: {:?} not found in {:?}", t, self.bound_vars);
874+
bug!("Not enough bound vars: {:?} not found in {:?}", t, self.bound_vars);
874875
}
875876
let list_var = self.bound_vars[bound_ty.var.as_usize()];
876877
match list_var {
877878
ty::BoundVariableKind::Ty(kind) => {
878879
if kind != bound_ty.kind {
879-
panic!(
880+
bug!(
880881
"Mismatched type kinds: {:?} doesn't var in list {:?}",
881882
bound_ty.kind, list_var
882883
);
883884
}
884885
}
885-
_ => panic!(
886+
_ => bug!(
886887
"Mismatched bound variable kinds! Expected type, found {:?}",
887888
list_var
888889
),
@@ -899,19 +900,19 @@ impl<'tcx> TypeVisitor<'tcx> for ValidateBoundVars<'tcx> {
899900
match r {
900901
ty::ReLateBound(index, br) if *index == self.binder_index => {
901902
if self.bound_vars.len() <= br.var.as_usize() {
902-
panic!("Not enough bound vars: {:?} not found in {:?}", *br, self.bound_vars);
903+
bug!("Not enough bound vars: {:?} not found in {:?}", *br, self.bound_vars);
903904
}
904905
let list_var = self.bound_vars[br.var.as_usize()];
905906
match list_var {
906907
ty::BoundVariableKind::Region(kind) => {
907908
if kind != br.kind {
908-
panic!(
909+
bug!(
909910
"Mismatched region kinds: {:?} doesn't match var ({:?}) in list ({:?})",
910911
br.kind, list_var, self.bound_vars
911912
);
912913
}
913914
}
914-
_ => panic!(
915+
_ => bug!(
915916
"Mismatched bound variable kinds! Expected region, found {:?}",
916917
list_var
917918
),

compiler/rustc_typeck/src/check/coercion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
14871487
if let (Some((expr, _)), Some((fn_decl, _, _))) =
14881488
(expression, fcx.get_node_fn_decl(parent_item))
14891489
{
1490-
fcx.suggest_missing_return_expr(&mut err, expr, fn_decl, expected, found);
1490+
fcx.suggest_missing_return_expr(&mut err, expr, fn_decl, expected, found, parent_id);
14911491
}
14921492

14931493
if let (Some(sp), Some(fn_output)) = (fcx.ret_coercion_span.get(), fn_output) {

compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
5555
if let Some((fn_decl, can_suggest)) = self.get_fn_decl(blk_id) {
5656
pointing_at_return_type =
5757
self.suggest_missing_return_type(err, &fn_decl, expected, found, can_suggest);
58-
self.suggest_missing_return_expr(err, expr, &fn_decl, expected, found);
58+
let fn_id = self.tcx.hir().get_return_block(blk_id).unwrap();
59+
self.suggest_missing_return_expr(err, expr, &fn_decl, expected, found, fn_id);
5960
}
6061
pointing_at_return_type
6162
}
@@ -479,14 +480,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
479480
fn_decl: &hir::FnDecl<'_>,
480481
expected: Ty<'tcx>,
481482
found: Ty<'tcx>,
483+
id: hir::HirId,
482484
) {
483485
if !expected.is_unit() {
484486
return;
485487
}
486488
let found = self.resolve_vars_with_obligations(found);
487489
if let hir::FnRetTy::Return(ty) = fn_decl.output {
488490
let ty = <dyn AstConv<'_>>::ast_ty_to_ty(self, ty);
489-
let ty = self.tcx.erase_late_bound_regions(Binder::bind(ty, self.tcx));
491+
let bound_vars = self.tcx.late_bound_vars(id);
492+
let ty = self.tcx.erase_late_bound_regions(Binder::bind_with_vars(ty, bound_vars));
490493
let ty = self.normalize_associated_types_in(expr.span, ty);
491494
if self.can_coerce(found, ty) {
492495
err.multipart_suggestion(

0 commit comments

Comments
 (0)