pub(super) fn suggest_missing_return_type(
        &self,
        err: &mut DiagnosticBuilder<'_>,
        fn_decl: &hir::FnDecl<'_>,
        expected: Ty<'tcx>,
        found: Ty<'tcx>,
        can_suggest: bool,
    ) -> 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 = AstConv::ast_ty_to_ty(self, ty);
                debug!("suggest_missing_return_type: return type {:?}", ty);
                debug!("suggest_missing_return_type: expected type {:?}", ty);
                if ty.kind() == expected.kind() {
                    err.span_label(sp, format!("expected `{}` because of return type", expected));
                    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(super) fn suggest_missing_return_type(
        &self,
        err: &mut DiagnosticBuilder<'_>,
        fn_decl: &hir::FnDecl<'_>,
        expected: Ty<'tcx>,
        found: Ty<'tcx>,
        can_suggest: bool,
    ) -> 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 = AstConv::ast_ty_to_ty(self, ty);
                debug!("suggest_missing_return_type: return type {:?}", ty);
                debug!("suggest_missing_return_type: expected type {:?}", ty);
                if ty.kind() == expected.kind() {
                    err.span_label(sp, format!("expected `{}` because of return type", expected));
                    return true;
                }
                false
            }
        }
    }
pub ( super ) fn suggest_missing_return_type ( & self , err : & mut DiagnosticBuilder < ' _ > , fn_decl : & hir :: FnDecl < ' _ > , expected : Ty < ' tcx > , found : Ty < ' tcx > , can_suggest : bool , ) -> 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 = AstConv :: ast_ty_to_ty ( self , ty ) ; debug ! ( " " ty ) ; debug ! ( " " ty ) ; if ty . kind ( ) == expected . kind ( ) { err . span_label ( sp , format ! ( " " expected ) ) ; 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
&self
err
&mut DiagnosticBuilder<'_>
fn_decl
&hir::FnDecl<'_>
expected
Ty<'tcx>
found
Ty<'tcx>
can_suggest
bool