Rollup merge of #116296 - compiler-errors:default-return, r=estebank · rust-lang/rust@cfce3a9 (original) (raw)

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

`

782

782

`}

`

783

783

`}

`

784

784

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

`

785

``

`-

let span = hir_ty.span;

`

786

``

-

787

785

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

`

788

786

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

`

789

787

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

`

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

`

799

797

`debug!(?found);

`

800

798

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

`

801

799

`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() });

`

803

801

`return true;

`

804

802

`} else {

`

805

``

`-

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

`

``

803

`+

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

`

806

804

`}

`

807

805

`}

`

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

`+

}

`

824

822

`}

`

825

823

`}

`

826

824

` _ => {}

`