pub(in super::super) fn suggest_missing_return_type(
        &self,
        err: &mut DiagnosticBuilder<'_>,
        fn_decl: &hir::FnDecl<'_>,
        expected: Ty<'tcx>,
        found: Ty<'tcx>,
        can_suggest: bool,
        fn_id: hir::HirId,
    ) -> bool {
        // Only suggest changing the return type for methods that
        // haven't set a return type at all (and aren't `fn main()` or an impl).
        match (&fn_decl.output, found.is_suggestable(), can_suggest, expected.is_unit()) {
            (&hir::FnRetTy::DefaultReturn(span), true, true, true) => {
                err.span_suggestion(
                    span,
                    "try adding a return type",
                    format!("-> {} ", self.resolve_vars_with_obligations(found)),
                    Applicability::MachineApplicable,
                );
                true
            }
            (&hir::FnRetTy::DefaultReturn(span), false, true, true) => {
                err.span_label(span, "possibly return type missing here?");
                true
            }
            (&hir::FnRetTy::DefaultReturn(span), _, false, true) => {
                // `fn main()` must return `()`, do not suggest changing return type
                err.span_label(span, "expected `()` because of default return type");
                true
            }
            // expectation was caused by something else, not the default return
            (&hir::FnRetTy::DefaultReturn(_), _, _, false) => false,
            (&hir::FnRetTy::Return(ref ty), _, _, _) => {
                // Only point to return type if the expected type is the return type, as if they
                // are not, the expectation must have been caused by something else.
                debug!("suggest_missing_return_type: return type {:?} node {:?}", ty, ty.kind);
                let sp = ty.span;
                let ty = <dyn AstConv<'_>>::ast_ty_to_ty(self, ty);
                debug!("suggest_missing_return_type: return type {:?}", ty);
                debug!("suggest_missing_return_type: expected type {:?}", ty);
                let bound_vars = self.tcx.late_bound_vars(fn_id);
                let ty = Binder::bind_with_vars(ty, bound_vars);
                let ty = self.normalize_associated_types_in(sp, ty);
                let ty = self.tcx.erase_late_bound_regions(ty);
                if self.can_coerce(expected, ty) {
                    err.span_label(sp, format!("expected `{}` because of return type", expected));
                    self.try_suggest_return_impl_trait(err, expected, ty, fn_id);
                    return true;
                }
                false
            }
        }
    }
/// A possible error is to forget to add a return type that is needed:
///
/// ```
/// fn foo() {
///     bar_that_returns_u32()
/// }
/// ```
///
/// This routine checks if the return type is left as default, the method is not part of an
/// `impl` block and that it isn't the `main` method. If so, it suggests setting the return
/// type.


This routine checks if the return type is left as default, the method is not part of an
`impl` block and that it isn't the `main` method. If so, it suggests setting the return
type.
This routine checks if the return type is left as default the method is not part of an ` impl ` block and that it isn ' t the ` main ` method . If so it suggests setting the return type .
pub(in super::super) fn suggest_missing_return_type(
        &self,
        err: &mut DiagnosticBuilder<'_>,
        fn_decl: &hir::FnDecl<'_>,
        expected: Ty<'tcx>,
        found: Ty<'tcx>,
        can_suggest: bool,
        fn_id: hir::HirId,
    ) -> bool {
        // Only suggest changing the return type for methods that
        // haven't set a return type at all (and aren't `fn main()` or an impl).
        match (&fn_decl.output, found.is_suggestable(), can_suggest, expected.is_unit()) {
            (&hir::FnRetTy::DefaultReturn(span), true, true, true) => {
                err.span_suggestion(
                    span,
                    "try adding a return type",
                    format!("-> {} ", self.resolve_vars_with_obligations(found)),
                    Applicability::MachineApplicable,
                );
                true
            }
            (&hir::FnRetTy::DefaultReturn(span), false, true, true) => {
                err.span_label(span, "possibly return type missing here?");
                true
            }
            (&hir::FnRetTy::DefaultReturn(span), _, false, true) => {
                // `fn main()` must return `()`, do not suggest changing return type
                err.span_label(span, "expected `()` because of default return type");
                true
            }
            // expectation was caused by something else, not the default return
            (&hir::FnRetTy::DefaultReturn(_), _, _, false) => false,
            (&hir::FnRetTy::Return(ref ty), _, _, _) => {
                // Only point to return type if the expected type is the return type, as if they
                // are not, the expectation must have been caused by something else.
                debug!("suggest_missing_return_type: return type {:?} node {:?}", ty, ty.kind);
                let sp = ty.span;
                let ty = <dyn AstConv<'_>>::ast_ty_to_ty(self, ty);
                debug!("suggest_missing_return_type: return type {:?}", ty);
                debug!("suggest_missing_return_type: expected type {:?}", ty);
                let bound_vars = self.tcx.late_bound_vars(fn_id);
                let ty = Binder::bind_with_vars(ty, bound_vars);
                let ty = self.normalize_associated_types_in(sp, ty);
                let ty = self.tcx.erase_late_bound_regions(ty);
                if self.can_coerce(expected, ty) {
                    err.span_label(sp, format!("expected `{}` because of return type", expected));
                    self.try_suggest_return_impl_trait(err, expected, ty, fn_id);
                    return true;
                }
                false
            }
        }
    }
pub ( in super :: super ) fn suggest_missing_return_type ( & self , err : & mut DiagnosticBuilder < ' _ > , fn_decl : & hir :: FnDecl < ' _ > , expected : Ty < ' tcx > , found : Ty < ' tcx > , can_suggest : bool , fn_id : hir :: HirId , ) -> bool { // Only suggest changing the return type for methods that // haven't set a return type at all (and aren't `fn main()` or an impl). match ( & fn_decl . output , found . is_suggestable ( ) , can_suggest , expected . is_unit ( ) ) { ( & hir :: FnRetTy :: DefaultReturn ( span ) , true , true , true ) => { err . span_suggestion ( span , " " , format ! ( " " self resolve_vars_with_obligations ( found ) ) , Applicability :: MachineApplicable , ) ; true } ( & hir :: FnRetTy :: DefaultReturn ( span ) , false , true , true ) => { err . span_label ( span , " " ) ; true } ( & hir :: FnRetTy :: DefaultReturn ( span ) , _ , false , true ) => { // `fn main()` must return `()`, do not suggest changing return type err . span_label ( span , " " ) ; true } // expectation was caused by something else, not the default return ( & hir :: FnRetTy :: DefaultReturn ( _ ) , _ , _ , false ) => false , ( & hir :: FnRetTy :: Return ( ref ty ) , _ , _ , _ ) => { // Only point to return type if the expected type is the return type, as if they // are not, the expectation must have been caused by something else. debug ! ( " " ty ty kind ) ; let sp = ty . span ; let ty = < dyn AstConv < ' _ > > :: ast_ty_to_ty ( self , ty ) ; debug ! ( " " ty ) ; debug ! ( " " ty ) ; let bound_vars = self . tcx . late_bound_vars ( fn_id ) ; let ty = Binder :: bind_with_vars ( ty , bound_vars ) ; let ty = self . normalize_associated_types_in ( sp , ty ) ; let ty = self . tcx . erase_late_bound_regions ( ty ) ; if self . can_coerce ( expected , ty ) { err . span_label ( sp , format ! ( " " expected ) ) ; self . try_suggest_return_impl_trait ( err , expected , ty , fn_id ) ; return true ; } false } } }
A possible error is to forget to add a return type that is needed:
```
fn foo() {
bar_that_returns_u32()
}
```
A possible error is to forget to add a return type that is needed : ` ` ` fn foo () { bar_that_returns_u32 () } ` ` `
&self
err
&mut DiagnosticBuilder<'_>
fn_decl
&hir::FnDecl<'_>
expected
Ty<'tcx>
found
Ty<'tcx>
can_suggest
bool
fn_id
hir::HirId
&self
err
&mut DiagnosticBuilder<'_>
fn_decl
&hir::FnDecl<'_>
expected
Ty<'tcx>
found
Ty<'tcx>
can_suggest
bool
fn_id
hir::HirId