pub fn for_item(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: NodeId)
                    -> ParameterEnvironment<'tcx> {
        match tcx.hir.find(id) {
            Some(hir_map::NodeImplItem(ref impl_item)) => {
                match impl_item.node {
                    hir::ImplItemKind::Type(_) | hir::ImplItemKind::Const(..) => {
                        // associated types don't have their own entry (for some reason),
                        // so for now just grab environment for the impl
                        let impl_id = tcx.hir.get_parent(id);
                        let impl_def_id = tcx.hir.local_def_id(impl_id);
                        tcx.construct_parameter_environment(impl_item.span,
                                                            impl_def_id,
                                                            tcx.region_maps.item_extent(id))
                    }
                    hir::ImplItemKind::Method(_, ref body) => {
                        tcx.construct_parameter_environment(
                            impl_item.span,
                            tcx.hir.local_def_id(id),
                            tcx.region_maps.call_site_extent(id, body.node_id))
                    }
                }
            }
            Some(hir_map::NodeTraitItem(trait_item)) => {
                match trait_item.node {
                    hir::TraitItemKind::Type(..) | hir::TraitItemKind::Const(..) => {
                        // associated types don't have their own entry (for some reason),
                        // so for now just grab environment for the trait
                        let trait_id = tcx.hir.get_parent(id);
                        let trait_def_id = tcx.hir.local_def_id(trait_id);
                        tcx.construct_parameter_environment(trait_item.span,
                                                            trait_def_id,
                                                            tcx.region_maps.item_extent(id))
                    }
                    hir::TraitItemKind::Method(_, ref body) => {
                        // Use call-site for extent (unless this is a
                        // trait method with no default; then fallback
                        // to the method id).
                        let extent = if let hir::TraitMethod::Provided(body_id) = *body {
                            // default impl: use call_site extent as free_id_outlive bound.
                            tcx.region_maps.call_site_extent(id, body_id.node_id)
                        } else {
                            // no default impl: use item extent as free_id_outlive bound.
                            tcx.region_maps.item_extent(id)
                        };
                        tcx.construct_parameter_environment(
                            trait_item.span,
                            tcx.hir.local_def_id(id),
                            extent)
                    }
                }
            }
            Some(hir_map::NodeItem(item)) => {
                match item.node {
                    hir::ItemFn(.., body_id) => {
                        // We assume this is a function.
                        let fn_def_id = tcx.hir.local_def_id(id);

                        tcx.construct_parameter_environment(
                            item.span,
                            fn_def_id,
                            tcx.region_maps.call_site_extent(id, body_id.node_id))
                    }
                    hir::ItemEnum(..) |
                    hir::ItemStruct(..) |
                    hir::ItemUnion(..) |
                    hir::ItemTy(..) |
                    hir::ItemImpl(..) |
                    hir::ItemConst(..) |
                    hir::ItemStatic(..) => {
                        let def_id = tcx.hir.local_def_id(id);
                        tcx.construct_parameter_environment(item.span,
                                                            def_id,
                                                            tcx.region_maps.item_extent(id))
                    }
                    hir::ItemTrait(..) => {
                        let def_id = tcx.hir.local_def_id(id);
                        tcx.construct_parameter_environment(item.span,
                                                            def_id,
                                                            tcx.region_maps.item_extent(id))
                    }
                    _ => {
                        span_bug!(item.span,
                                  "ParameterEnvironment::for_item():
                                   can't create a parameter \
                                   environment for this kind of item")
                    }
                }
            }
            Some(hir_map::NodeExpr(expr)) => {
                // This is a convenience to allow closures to work.
                if let hir::ExprClosure(.., body, _) = expr.node {
                    let def_id = tcx.hir.local_def_id(id);
                    let base_def_id = tcx.closure_base_def_id(def_id);
                    tcx.construct_parameter_environment(
                        expr.span,
                        base_def_id,
                        tcx.region_maps.call_site_extent(id, body.node_id))
                } else {
                    tcx.empty_parameter_environment()
                }
            }
            Some(hir_map::NodeForeignItem(item)) => {
                let def_id = tcx.hir.local_def_id(id);
                tcx.construct_parameter_environment(item.span,
                                                    def_id,
                                                    ROOT_CODE_EXTENT)
            }
            _ => {
                bug!("ParameterEnvironment::from_item(): \
                      `{}` is not an item",
                     tcx.hir.node_to_string(id))
            }
        }
    }
/// Construct a parameter environment given an item, impl item, or trait item
Construct a parameter environment given an item, impl item, or trait item
Construct a parameter environment given an item impl item or trait item
pub fn for_item(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: NodeId)
                    -> ParameterEnvironment<'tcx> {
        match tcx.hir.find(id) {
            Some(hir_map::NodeImplItem(ref impl_item)) => {
                match impl_item.node {
                    hir::ImplItemKind::Type(_) | hir::ImplItemKind::Const(..) => {
                        // associated types don't have their own entry (for some reason),
                        // so for now just grab environment for the impl
                        let impl_id = tcx.hir.get_parent(id);
                        let impl_def_id = tcx.hir.local_def_id(impl_id);
                        tcx.construct_parameter_environment(impl_item.span,
                                                            impl_def_id,
                                                            tcx.region_maps.item_extent(id))
                    }
                    hir::ImplItemKind::Method(_, ref body) => {
                        tcx.construct_parameter_environment(
                            impl_item.span,
                            tcx.hir.local_def_id(id),
                            tcx.region_maps.call_site_extent(id, body.node_id))
                    }
                }
            }
            Some(hir_map::NodeTraitItem(trait_item)) => {
                match trait_item.node {
                    hir::TraitItemKind::Type(..) | hir::TraitItemKind::Const(..) => {
                        // associated types don't have their own entry (for some reason),
                        // so for now just grab environment for the trait
                        let trait_id = tcx.hir.get_parent(id);
                        let trait_def_id = tcx.hir.local_def_id(trait_id);
                        tcx.construct_parameter_environment(trait_item.span,
                                                            trait_def_id,
                                                            tcx.region_maps.item_extent(id))
                    }
                    hir::TraitItemKind::Method(_, ref body) => {
                        // Use call-site for extent (unless this is a
                        // trait method with no default; then fallback
                        // to the method id).
                        let extent = if let hir::TraitMethod::Provided(body_id) = *body {
                            // default impl: use call_site extent as free_id_outlive bound.
                            tcx.region_maps.call_site_extent(id, body_id.node_id)
                        } else {
                            // no default impl: use item extent as free_id_outlive bound.
                            tcx.region_maps.item_extent(id)
                        };
                        tcx.construct_parameter_environment(
                            trait_item.span,
                            tcx.hir.local_def_id(id),
                            extent)
                    }
                }
            }
            Some(hir_map::NodeItem(item)) => {
                match item.node {
                    hir::ItemFn(.., body_id) => {
                        // We assume this is a function.
                        let fn_def_id = tcx.hir.local_def_id(id);
                        tcx.construct_parameter_environment(
                            item.span,
                            fn_def_id,
                            tcx.region_maps.call_site_extent(id, body_id.node_id))
                    }
                    hir::ItemEnum(..) |
                    hir::ItemStruct(..) |
                    hir::ItemUnion(..) |
                    hir::ItemTy(..) |
                    hir::ItemImpl(..) |
                    hir::ItemConst(..) |
                    hir::ItemStatic(..) => {
                        let def_id = tcx.hir.local_def_id(id);
                        tcx.construct_parameter_environment(item.span,
                                                            def_id,
                                                            tcx.region_maps.item_extent(id))
                    }
                    hir::ItemTrait(..) => {
                        let def_id = tcx.hir.local_def_id(id);
                        tcx.construct_parameter_environment(item.span,
                                                            def_id,
                                                            tcx.region_maps.item_extent(id))
                    }
                    _ => {
                        span_bug!(item.span,
                                  "ParameterEnvironment::for_item():
                                   can't create a parameter \
                                   environment for this kind of item")
                    }
                }
            }
            Some(hir_map::NodeExpr(expr)) => {
                // This is a convenience to allow closures to work.
                if let hir::ExprClosure(.., body, _) = expr.node {
                    let def_id = tcx.hir.local_def_id(id);
                    let base_def_id = tcx.closure_base_def_id(def_id);
                    tcx.construct_parameter_environment(
                        expr.span,
                        base_def_id,
                        tcx.region_maps.call_site_extent(id, body.node_id))
                } else {
                    tcx.empty_parameter_environment()
                }
            }
            Some(hir_map::NodeForeignItem(item)) => {
                let def_id = tcx.hir.local_def_id(id);
                tcx.construct_parameter_environment(item.span,
                                                    def_id,
                                                    ROOT_CODE_EXTENT)
            }
            _ => {
                bug!("ParameterEnvironment::from_item(): \
                      `{}` is not an item",
                     tcx.hir.node_to_string(id))
            }
        }
    }
pub fn for_item ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , id : NodeId ) -> ParameterEnvironment < ' tcx > { match tcx . hir . find ( id ) { Some ( hir_map :: NodeImplItem ( ref impl_item ) ) => { match impl_item . node { hir :: ImplItemKind :: Type ( _ ) | hir :: ImplItemKind :: Const ( .. ) => { // associated types don't have their own entry (for some reason), // so for now just grab environment for the impl let impl_id = tcx . hir . get_parent ( id ) ; let impl_def_id = tcx . hir . local_def_id ( impl_id ) ; tcx . construct_parameter_environment ( impl_item . span , impl_def_id , tcx . region_maps . item_extent ( id ) ) } hir :: ImplItemKind :: Method ( _ , ref body ) => { tcx . construct_parameter_environment ( impl_item . span , tcx . hir . local_def_id ( id ) , tcx . region_maps . call_site_extent ( id , body . node_id ) ) } } } Some ( hir_map :: NodeTraitItem ( trait_item ) ) => { match trait_item . node { hir :: TraitItemKind :: Type ( .. ) | hir :: TraitItemKind :: Const ( .. ) => { // associated types don't have their own entry (for some reason), // so for now just grab environment for the trait let trait_id = tcx . hir . get_parent ( id ) ; let trait_def_id = tcx . hir . local_def_id ( trait_id ) ; tcx . construct_parameter_environment ( trait_item . span , trait_def_id , tcx . region_maps . item_extent ( id ) ) } hir :: TraitItemKind :: Method ( _ , ref body ) => { // Use call-site for extent (unless this is a // trait method with no default; then fallback // to the method id). let extent = if let hir :: TraitMethod :: Provided ( body_id ) = * body { // default impl: use call_site extent as free_id_outlive bound. tcx . region_maps . call_site_extent ( id , body_id . node_id ) } else { // no default impl: use item extent as free_id_outlive bound. tcx . region_maps . item_extent ( id ) } ; tcx . construct_parameter_environment ( trait_item . span , tcx . hir . local_def_id ( id ) , extent ) } } } Some ( hir_map :: NodeItem ( item ) ) => { match item . node { hir :: ItemFn ( .. , body_id ) => { // We assume this is a function. let fn_def_id = tcx . hir . local_def_id ( id ) ; tcx . construct_parameter_environment ( item . span , fn_def_id , tcx . region_maps . call_site_extent ( id , body_id . node_id ) ) } hir :: ItemEnum ( .. ) | hir :: ItemStruct ( .. ) | hir :: ItemUnion ( .. ) | hir :: ItemTy ( .. ) | hir :: ItemImpl ( .. ) | hir :: ItemConst ( .. ) | hir :: ItemStatic ( .. ) => { let def_id = tcx . hir . local_def_id ( id ) ; tcx . construct_parameter_environment ( item . span , def_id , tcx . region_maps . item_extent ( id ) ) } hir :: ItemTrait ( .. ) => { let def_id = tcx . hir . local_def_id ( id ) ; tcx . construct_parameter_environment ( item . span , def_id , tcx . region_maps . item_extent ( id ) ) } _ => { span_bug ! ( item span " \
 " ) } } } Some ( hir_map :: NodeExpr ( expr ) ) => { // This is a convenience to allow closures to work. if let hir :: ExprClosure ( .. , body , _ ) = expr . node { let def_id = tcx . hir . local_def_id ( id ) ; let base_def_id = tcx . closure_base_def_id ( def_id ) ; tcx . construct_parameter_environment ( expr . span , base_def_id , tcx . region_maps . call_site_extent ( id , body . node_id ) ) } else { tcx . empty_parameter_environment ( ) } } Some ( hir_map :: NodeForeignItem ( item ) ) => { let def_id = tcx . hir . local_def_id ( id ) ; tcx . construct_parameter_environment ( item . span , def_id , ROOT_CODE_EXTENT ) } _ => { bug ! ( " \
 " tcx hir node_to_string ( id ) ) } } }
Construct a parameter environment given an item, impl item, or trait item
Construct a parameter environment given an item impl item or trait item
tcx
TyCtxt<'a, 'tcx, 'tcx>
id
NodeId