fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
                            unsafety: hir::Unsafety,
                            unsafety_id: ast::NodeId,
                            fn_sig: &ty::FnSig<'tcx>,
                            decl: &'gcx hir::FnDecl,
                            fn_id: ast::NodeId,
                            body: &'gcx hir::Body)
                            -> FnCtxt<'a, 'gcx, 'tcx>
{
    let mut fn_sig = fn_sig.clone();

    debug!("check_fn(sig={:?}, fn_id={})", fn_sig, fn_id);

    // Create the function context.  This is either derived from scratch or,
    // in the case of function expressions, based on the outer context.
    let mut fcx = FnCtxt::new(inherited, None, body.value.id);
    let ret_ty = fn_sig.output();
    *fcx.ps.borrow_mut() = UnsafetyState::function(unsafety, unsafety_id);

    fcx.require_type_is_sized(ret_ty, decl.output.span(), traits::ReturnType);
    fcx.ret_ty = fcx.instantiate_anon_types(&Some(ret_ty));
    fn_sig = fcx.tcx.mk_fn_sig(fn_sig.inputs().iter().cloned(), &fcx.ret_ty.unwrap(),
                               fn_sig.variadic);

    GatherLocalsVisitor { fcx: &fcx, }.visit_body(body);

    // Add formal parameters.
    for (arg_ty, arg) in fn_sig.inputs().iter().zip(&body.arguments) {
        // The type of the argument must be well-formed.
        //
        // NB -- this is now checked in wfcheck, but that
        // currently only results in warnings, so we issue an
        // old-style WF obligation here so that we still get the
        // errors that we used to get.
        fcx.register_old_wf_obligation(arg_ty, arg.pat.span, traits::MiscObligation);

        // Check the pattern.
        fcx.check_pat_arg(&arg.pat, arg_ty, true);
        fcx.write_ty(arg.id, arg_ty);
    }

    inherited.tables.borrow_mut().liberated_fn_sigs.insert(fn_id, fn_sig);

    fcx.check_expr_coercable_to_type(&body.value, fcx.ret_ty.unwrap());

    fcx
}
/// Helper used by check_bare_fn and check_expr_fn. Does the grungy work of checking a function
/// body and returns the function context used for that purpose, since in the case of a fn item
/// there is still a bit more to do.
///
/// * ...
/// * inherited: other fields inherited from the enclosing fn (if any)


other fields inherited from the enclosing fn (if any)
other fields inherited from the enclosing fn ( if any )
fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
                            unsafety: hir::Unsafety,
                            unsafety_id: ast::NodeId,
                            fn_sig: &ty::FnSig<'tcx>,
                            decl: &'gcx hir::FnDecl,
                            fn_id: ast::NodeId,
                            body: &'gcx hir::Body)
                            -> FnCtxt<'a, 'gcx, 'tcx>
{
    let mut fn_sig = fn_sig.clone();
    debug!("check_fn(sig={:?}, fn_id={})", fn_sig, fn_id);
    // Create the function context.  This is either derived from scratch or,
    // in the case of function expressions, based on the outer context.
    let mut fcx = FnCtxt::new(inherited, None, body.value.id);
    let ret_ty = fn_sig.output();
    *fcx.ps.borrow_mut() = UnsafetyState::function(unsafety, unsafety_id);
    fcx.require_type_is_sized(ret_ty, decl.output.span(), traits::ReturnType);
    fcx.ret_ty = fcx.instantiate_anon_types(&Some(ret_ty));
    fn_sig = fcx.tcx.mk_fn_sig(fn_sig.inputs().iter().cloned(), &fcx.ret_ty.unwrap(),
                               fn_sig.variadic);
    GatherLocalsVisitor { fcx: &fcx, }.visit_body(body);
    // Add formal parameters.
    for (arg_ty, arg) in fn_sig.inputs().iter().zip(&body.arguments) {
        // The type of the argument must be well-formed.
        //
        // NB -- this is now checked in wfcheck, but that
        // currently only results in warnings, so we issue an
        // old-style WF obligation here so that we still get the
        // errors that we used to get.
        fcx.register_old_wf_obligation(arg_ty, arg.pat.span, traits::MiscObligation);
        // Check the pattern.
        fcx.check_pat_arg(&arg.pat, arg_ty, true);
        fcx.write_ty(arg.id, arg_ty);
    }
    inherited.tables.borrow_mut().liberated_fn_sigs.insert(fn_id, fn_sig);
    fcx.check_expr_coercable_to_type(&body.value, fcx.ret_ty.unwrap());
    fcx
}
fn check_fn < ' a , ' gcx , ' tcx > ( inherited : & ' a Inherited < ' a , ' gcx , ' tcx > , unsafety : hir :: Unsafety , unsafety_id : ast :: NodeId , fn_sig : & ty :: FnSig < ' tcx > , decl : & ' gcx hir :: FnDecl , fn_id : ast :: NodeId , body : & ' gcx hir :: Body ) -> FnCtxt < ' a , ' gcx , ' tcx > { let mut fn_sig = fn_sig . clone ( ) ; debug ! ( " " fn_sig fn_id ) ; // Create the function context.  This is either derived from scratch or, // in the case of function expressions, based on the outer context. let mut fcx = FnCtxt :: new ( inherited , None , body . value . id ) ; let ret_ty = fn_sig . output ( ) ; * fcx . ps . borrow_mut ( ) = UnsafetyState :: function ( unsafety , unsafety_id ) ; fcx . require_type_is_sized ( ret_ty , decl . output . span ( ) , traits :: ReturnType ) ; fcx . ret_ty = fcx . instantiate_anon_types ( & Some ( ret_ty ) ) ; fn_sig = fcx . tcx . mk_fn_sig ( fn_sig . inputs ( ) . iter ( ) . cloned ( ) , & fcx . ret_ty . unwrap ( ) , fn_sig . variadic ) ; GatherLocalsVisitor { fcx : & fcx , } . visit_body ( body ) ; // Add formal parameters. for ( arg_ty , arg ) in fn_sig . inputs ( ) . iter ( ) . zip ( & body . arguments ) { // The type of the argument must be well-formed. // // NB -- this is now checked in wfcheck, but that // currently only results in warnings, so we issue an // old-style WF obligation here so that we still get the // errors that we used to get. fcx . register_old_wf_obligation ( arg_ty , arg . pat . span , traits :: MiscObligation ) ; // Check the pattern. fcx . check_pat_arg ( & arg . pat , arg_ty , true ) ; fcx . write_ty ( arg . id , arg_ty ) ; } inherited . tables . borrow_mut ( ) . liberated_fn_sigs . insert ( fn_id , fn_sig ) ; fcx . check_expr_coercable_to_type ( & body . value , fcx . ret_ty . unwrap ( ) ) ; fcx }
Helper used by check_bare_fn and check_expr_fn.
Helper used by check_bare_fn and check_expr_fn .
inherited
&'a Inherited<'a, 'gcx, 'tcx>
unsafety
hir::Unsafety
unsafety_id
ast::NodeId
fn_sig
&ty::FnSig<'tcx>
decl
&'gcx hir::FnDecl
fn_id
ast::NodeId
body
&'gcx hir::Body
inherited
&'a Inherited<'a, 'gcx, 'tcx>
unsafety
hir::Unsafety
unsafety_id
ast::NodeId
fn_sig
&ty::FnSig<'tcx>
decl
&'gcx hir::FnDecl
fn_id
ast::NodeId
body
&'gcx hir::Body