Point to where missing return type should go · rust-lang/rust@137b6d0

@@ -782,8 +782,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

782782

}

783783

}

784784

hir::FnRetTy::Return(hir_ty) => {

785-

let span = hir_ty.span;

786-787785

if let hir::TyKind::OpaqueDef(item_id, ..) = hir_ty.kind

788786

&& let hir::Node::Item(hir::Item {

789787

kind: hir::ItemKind::OpaqueTy(op_ty),

@@ -799,28 +797,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

799797

debug!(?found);

800798

if found.is_suggestable(self.tcx, false) {

801799

if term.span.is_empty() {

802-

err.subdiagnostic(errors::AddReturnTypeSuggestion::Add { span, found: found.to_string() });

800+

err.subdiagnostic(errors::AddReturnTypeSuggestion::Add { span: term.span, found: found.to_string() });

803801

return true;

804802

} else {

805-

err.subdiagnostic(errors::ExpectedReturnTypeLabel::Other { span, expected });

803+

err.subdiagnostic(errors::ExpectedReturnTypeLabel::Other { span: term.span, expected });

806804

}

807805

}

808-

}

809-810-

// Only point to return type if the expected type is the return type, as if they

811-

// are not, the expectation must have been caused by something else.

812-

debug!("return type {:?}", hir_ty);

813-

let ty = self.astconv().ast_ty_to_ty(hir_ty);

814-

debug!("return type {:?}", ty);

815-

debug!("expected type {:?}", expected);

816-

let bound_vars = self.tcx.late_bound_vars(hir_ty.hir_id.owner.into());

817-

let ty = Binder::bind_with_vars(ty, bound_vars);

818-

let ty = self.normalize(span, ty);

819-

let ty = self.tcx.erase_late_bound_regions(ty);

820-

if self.can_coerce(expected, ty) {

821-

err.subdiagnostic(errors::ExpectedReturnTypeLabel::Other { span, expected });

822-

self.try_suggest_return_impl_trait(err, expected, ty, fn_id);

823-

return true;

806+

} else {

807+

// Only point to return type if the expected type is the return type, as if they

808+

// are not, the expectation must have been caused by something else.

809+

debug!("return type {:?}", hir_ty);

810+

let ty = self.astconv().ast_ty_to_ty(hir_ty);

811+

debug!("return type {:?}", ty);

812+

debug!("expected type {:?}", expected);

813+

let bound_vars = self.tcx.late_bound_vars(hir_ty.hir_id.owner.into());

814+

let ty = Binder::bind_with_vars(ty, bound_vars);

815+

let ty = self.normalize(hir_ty.span, ty);

816+

let ty = self.tcx.erase_late_bound_regions(ty);

817+

if self.can_coerce(expected, ty) {

818+

err.subdiagnostic(errors::ExpectedReturnTypeLabel::Other { span: hir_ty.span, expected });

819+

self.try_suggest_return_impl_trait(err, expected, ty, fn_id);

820+

return true;

821+

}

824822

}

825823

}

826824

_ => {}