fn adjust_local_def(&mut self, local_def: LocalDef, span: Span) -> Option<Def> {
        let ribs = match local_def.ribs {
            Some((TypeNS, i)) => &self.type_ribs[i + 1..],
            Some((ValueNS, i)) => &self.value_ribs[i + 1..],
            _ => &[] as &[_],
        };
        let mut def = local_def.def;
        match def {
            Def::Upvar(..) => {
                span_bug!(span, "unexpected {:?} in bindings", def)
            }
            Def::Local(_, node_id) => {
                for rib in ribs {
                    match rib.kind {
                        NormalRibKind | ModuleRibKind(..) | MacroDefinition(..) => {
                            // Nothing to do. Continue.
                        }
                        ClosureRibKind(function_id) => {
                            let prev_def = def;
                            let node_def_id = self.definitions.local_def_id(node_id);

                            let seen = self.freevars_seen
                                           .entry(function_id)
                                           .or_insert_with(|| NodeMap());
                            if let Some(&index) = seen.get(&node_id) {
                                def = Def::Upvar(node_def_id, node_id, index, function_id);
                                continue;
                            }
                            let vec = self.freevars
                                          .entry(function_id)
                                          .or_insert_with(|| vec![]);
                            let depth = vec.len();
                            vec.push(Freevar {
                                def: prev_def,
                                span: span,
                            });

                            def = Def::Upvar(node_def_id, node_id, depth, function_id);
                            seen.insert(node_id, depth);
                        }
                        ItemRibKind | MethodRibKind(_) => {
                            // This was an attempt to access an upvar inside a
                            // named function item. This is not allowed, so we
                            // report an error.
                            resolve_error(self,
                                          span,
                                          ResolutionError::CannotCaptureDynamicEnvironmentInFnItem);
                            return None;
                        }
                        ConstantItemRibKind => {
                            // Still doesn't deal with upvars
                            resolve_error(self,
                                          span,
                                          ResolutionError::AttemptToUseNonConstantValueInConstant);
                            return None;
                        }
                    }
                }
            }
            Def::TyParam(..) | Def::SelfTy(..) => {
                for rib in ribs {
                    match rib.kind {
                        NormalRibKind | MethodRibKind(_) | ClosureRibKind(..) |
                        ModuleRibKind(..) | MacroDefinition(..) => {
                            // Nothing to do. Continue.
                        }
                        ItemRibKind => {
                            // This was an attempt to use a type parameter outside
                            // its scope.

                            resolve_error(self,
                                          span,
                                          ResolutionError::TypeParametersFromOuterFunction);
                            return None;
                        }
                        ConstantItemRibKind => {
                            // see #9186
                            resolve_error(self, span, ResolutionError::OuterTypeParameterContext);
                            return None;
                        }
                    }
                }
            }
            _ => {}
        }
        return Some(def);
    }
// Resolve a local definition, potentially adjusting for closures.
Resolve a local definition, potentially adjusting for closures.
Resolve a local definition potentially adjusting for closures .
fn adjust_local_def(&mut self, local_def: LocalDef, span: Span) -> Option<Def> {
        let ribs = match local_def.ribs {
            Some((TypeNS, i)) => &self.type_ribs[i + 1..],
            Some((ValueNS, i)) => &self.value_ribs[i + 1..],
            _ => &[] as &[_],
        };
        let mut def = local_def.def;
        match def {
            Def::Upvar(..) => {
                span_bug!(span, "unexpected {:?} in bindings", def)
            }
            Def::Local(_, node_id) => {
                for rib in ribs {
                    match rib.kind {
                        NormalRibKind | ModuleRibKind(..) | MacroDefinition(..) => {
                            // Nothing to do. Continue.
                        }
                        ClosureRibKind(function_id) => {
                            let prev_def = def;
                            let node_def_id = self.definitions.local_def_id(node_id);
                            let seen = self.freevars_seen
                                           .entry(function_id)
                                           .or_insert_with(|| NodeMap());
                            if let Some(&index) = seen.get(&node_id) {
                                def = Def::Upvar(node_def_id, node_id, index, function_id);
                                continue;
                            }
                            let vec = self.freevars
                                          .entry(function_id)
                                          .or_insert_with(|| vec![]);
                            let depth = vec.len();
                            vec.push(Freevar {
                                def: prev_def,
                                span: span,
                            });
                            def = Def::Upvar(node_def_id, node_id, depth, function_id);
                            seen.insert(node_id, depth);
                        }
                        ItemRibKind | MethodRibKind(_) => {
                            // This was an attempt to access an upvar inside a
                            // named function item. This is not allowed, so we
                            // report an error.
                            resolve_error(self,
                                          span,
                                          ResolutionError::CannotCaptureDynamicEnvironmentInFnItem);
                            return None;
                        }
                        ConstantItemRibKind => {
                            // Still doesn't deal with upvars
                            resolve_error(self,
                                          span,
                                          ResolutionError::AttemptToUseNonConstantValueInConstant);
                            return None;
                        }
                    }
                }
            }
            Def::TyParam(..) | Def::SelfTy(..) => {
                for rib in ribs {
                    match rib.kind {
                        NormalRibKind | MethodRibKind(_) | ClosureRibKind(..) |
                        ModuleRibKind(..) | MacroDefinition(..) => {
                            // Nothing to do. Continue.
                        }
                        ItemRibKind => {
                            // This was an attempt to use a type parameter outside
                            // its scope.
                            resolve_error(self,
                                          span,
                                          ResolutionError::TypeParametersFromOuterFunction);
                            return None;
                        }
                        ConstantItemRibKind => {
                            // see #9186
                            resolve_error(self, span, ResolutionError::OuterTypeParameterContext);
                            return None;
                        }
                    }
                }
            }
            _ => {}
        }
        return Some(def);
    }
fn adjust_local_def ( & mut self , local_def : LocalDef , span : Span ) -> Option < Def > { let ribs = match local_def . ribs { Some ( ( TypeNS , i ) ) => & self . type_ribs [ i + 1 .. ] , Some ( ( ValueNS , i ) ) => & self . value_ribs [ i + 1 .. ] , _ => & [ ] as & [ _ ] , } ; let mut def = local_def . def ; match def { Def :: Upvar ( .. ) => { span_bug ! ( span " " def ) } Def :: Local ( _ , node_id ) => { for rib in ribs { match rib . kind { NormalRibKind | ModuleRibKind ( .. ) | MacroDefinition ( .. ) => { // Nothing to do. Continue. } ClosureRibKind ( function_id ) => { let prev_def = def ; let node_def_id = self . definitions . local_def_id ( node_id ) ; let seen = self . freevars_seen . entry ( function_id ) . or_insert_with ( | | NodeMap ( ) ) ; if let Some ( & index ) = seen . get ( & node_id ) { def = Def :: Upvar ( node_def_id , node_id , index , function_id ) ; continue ; } let vec = self . freevars . entry ( function_id ) . or_insert_with ( | | vec ! [ ] ) ; let depth = vec . len ( ) ; vec . push ( Freevar { def : prev_def , span : span , } ) ; def = Def :: Upvar ( node_def_id , node_id , depth , function_id ) ; seen . insert ( node_id , depth ) ; } ItemRibKind | MethodRibKind ( _ ) => { // This was an attempt to access an upvar inside a // named function item. This is not allowed, so we // report an error. resolve_error ( self , span , ResolutionError :: CannotCaptureDynamicEnvironmentInFnItem ) ; return None ; } ConstantItemRibKind => { // Still doesn't deal with upvars resolve_error ( self , span , ResolutionError :: AttemptToUseNonConstantValueInConstant ) ; return None ; } } } } Def :: TyParam ( .. ) | Def :: SelfTy ( .. ) => { for rib in ribs { match rib . kind { NormalRibKind | MethodRibKind ( _ ) | ClosureRibKind ( .. ) | ModuleRibKind ( .. ) | MacroDefinition ( .. ) => { // Nothing to do. Continue. } ItemRibKind => { // This was an attempt to use a type parameter outside // its scope. resolve_error ( self , span , ResolutionError :: TypeParametersFromOuterFunction ) ; return None ; } ConstantItemRibKind => { // see #9186 resolve_error ( self , span , ResolutionError :: OuterTypeParameterContext ) ; return None ; } } } } _ => { } } return Some ( def ) ; }
Resolve a local definition, potentially adjusting for closures.
Resolve a local definition potentially adjusting for closures .
&mut self
local_def
LocalDef
span
Span
&mut self
local_def
LocalDef
span
Span