X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_typeck%2Fsrc%2Fcheck%2Fexpr.rs;h=6e97b0bf2ab7dfba1d5add7d134e1f58a446147d;hb=0de7f756f034d9be9ea9d00ad994b3d5002f9255;hp=ba5ef5edc8630cd803cbe4379652e48f992ef578;hpb=3c4a66d04e2c3e6cd87a5c89f0a6c8905caaa976;p=rust.git diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index ba5ef5edc86..6e97b0bf2ab 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -766,7 +766,7 @@ fn check_expr_return( // If this didn't hold, we would not have to report an error in // the first place. - assert_ne!(hir::HirId::make_owner(encl_item_id), encl_body_owner_id); + assert_ne!(encl_item_id, encl_body_owner_id); let encl_body_id = self.tcx.hir().body_owned_by(encl_body_owner_id); let encl_body = self.tcx.hir().body(encl_body_id); @@ -1003,8 +1003,15 @@ fn check_then_else( let else_diverges = self.diverges.get(); let opt_suggest_box_span = self.opt_suggest_box_span(else_ty, orig_expected); - let if_cause = - self.if_cause(sp, then_expr, else_expr, then_ty, else_ty, opt_suggest_box_span); + let if_cause = self.if_cause( + sp, + cond_expr.span, + then_expr, + else_expr, + then_ty, + else_ty, + opt_suggest_box_span, + ); coerce.coerce(self, &if_cause, else_expr, else_ty); @@ -2648,6 +2655,9 @@ fn check_expr_index( Some((index_ty, element_ty)) => { // two-phase not needed because index_ty is never mutable self.demand_coerce(idx, idx_t, index_ty, None, AllowTwoPhase::No); + self.select_obligations_where_possible(false, |errors| { + self.point_at_index_if_possible(errors, idx.span) + }); element_ty } None => { @@ -2691,6 +2701,22 @@ fn check_expr_index( } } + fn point_at_index_if_possible( + &self, + errors: &mut Vec>, + span: Span, + ) { + for error in errors { + match error.obligation.predicate.kind().skip_binder() { + ty::PredicateKind::Trait(predicate) + if self.tcx.is_diagnostic_item(sym::SliceIndex, predicate.trait_ref.def_id) => { + } + _ => continue, + } + error.obligation.cause.span = span; + } + } + fn check_expr_yield( &self, value: &'tcx hir::Expr<'tcx>,