fn validate_res_from_ribs(
        &mut self,
        rib_index: usize,
        rib_ident: Ident,
        res: Res,
        record_used: bool,
        span: Span,
        all_ribs: &[Rib<'a>],
    ) -> Res {
        debug!("validate_res_from_ribs({:?})", res);
        let ribs = &all_ribs[rib_index + 1..];

        // An invalid forward use of a type parameter from a previous default.
        if let ForwardTyParamBanRibKind = all_ribs[rib_index].kind {
            if record_used {
                let res_error = if rib_ident.name == kw::SelfUpper {
                    ResolutionError::SelfInTyParamDefault
                } else {
                    ResolutionError::ForwardDeclaredTyParam
                };
                self.report_error(span, res_error);
            }
            assert_eq!(res, Res::Err);
            return Res::Err;
        }

        match res {
            Res::Local(_) => {
                use ResolutionError::*;
                let mut res_err = None;

                for rib in ribs {
                    match rib.kind {
                        NormalRibKind
                        | ClosureOrAsyncRibKind
                        | ModuleRibKind(..)
                        | MacroDefinition(..)
                        | ForwardTyParamBanRibKind => {
                            // Nothing to do. Continue.
                        }
                        ItemRibKind(_) | FnItemRibKind | AssocItemRibKind => {
                            // This was an attempt to access an upvar inside a
                            // named function item. This is not allowed, so we
                            // report an error.
                            if record_used {
                                // We don't immediately trigger a resolve error, because
                                // we want certain other resolution errors (namely those
                                // emitted for `ConstantItemRibKind` below) to take
                                // precedence.
                                res_err = Some(CannotCaptureDynamicEnvironmentInFnItem);
                            }
                        }
                        ConstantItemRibKind => {
                            // Still doesn't deal with upvars
                            if record_used {
                                self.report_error(span, AttemptToUseNonConstantValueInConstant);
                            }
                            return Res::Err;
                        }
                    }
                }
                if let Some(res_err) = res_err {
                    self.report_error(span, res_err);
                    return Res::Err;
                }
            }
            Res::Def(DefKind::TyParam, _) | Res::SelfTy(..) => {
                for rib in ribs {
                    let has_generic_params = match rib.kind {
                        NormalRibKind
                        | ClosureOrAsyncRibKind
                        | AssocItemRibKind
                        | ModuleRibKind(..)
                        | MacroDefinition(..)
                        | ForwardTyParamBanRibKind
                        | ConstantItemRibKind => {
                            // Nothing to do. Continue.
                            continue;
                        }
                        // This was an attempt to use a type parameter outside its scope.
                        ItemRibKind(has_generic_params) => has_generic_params,
                        FnItemRibKind => HasGenericParams::Yes,
                    };

                    if record_used {
                        self.report_error(
                            span,
                            ResolutionError::GenericParamsFromOuterFunction(
                                res,
                                has_generic_params,
                            ),
                        );
                    }
                    return Res::Err;
                }
            }
            Res::Def(DefKind::ConstParam, _) => {
                let mut ribs = ribs.iter().peekable();
                if let Some(Rib { kind: FnItemRibKind, .. }) = ribs.peek() {
                    // When declaring const parameters inside function signatures, the first rib
                    // is always a `FnItemRibKind`. In this case, we can skip it, to avoid it
                    // (spuriously) conflicting with the const param.
                    ribs.next();
                }
                for rib in ribs {
                    let has_generic_params = match rib.kind {
                        ItemRibKind(has_generic_params) => has_generic_params,
                        FnItemRibKind => HasGenericParams::Yes,
                        _ => continue,
                    };

                    // This was an attempt to use a const parameter outside its scope.
                    if record_used {
                        self.report_error(
                            span,
                            ResolutionError::GenericParamsFromOuterFunction(
                                res,
                                has_generic_params,
                            ),
                        );
                    }
                    return Res::Err;
                }
            }
            _ => {}
        }
        res
    }
// Validate a local resolution (from ribs).
Validate a local resolution (from ribs).
Validate a local resolution ( from ribs ) .
fn validate_res_from_ribs(
        &mut self,
        rib_index: usize,
        rib_ident: Ident,
        res: Res,
        record_used: bool,
        span: Span,
        all_ribs: &[Rib<'a>],
    ) -> Res {
        debug!("validate_res_from_ribs({:?})", res);
        let ribs = &all_ribs[rib_index + 1..];
        // An invalid forward use of a type parameter from a previous default.
        if let ForwardTyParamBanRibKind = all_ribs[rib_index].kind {
            if record_used {
                let res_error = if rib_ident.name == kw::SelfUpper {
                    ResolutionError::SelfInTyParamDefault
                } else {
                    ResolutionError::ForwardDeclaredTyParam
                };
                self.report_error(span, res_error);
            }
            assert_eq!(res, Res::Err);
            return Res::Err;
        }
        match res {
            Res::Local(_) => {
                use ResolutionError::*;
                let mut res_err = None;
                for rib in ribs {
                    match rib.kind {
                        NormalRibKind
                        | ClosureOrAsyncRibKind
                        | ModuleRibKind(..)
                        | MacroDefinition(..)
                        | ForwardTyParamBanRibKind => {
                            // Nothing to do. Continue.
                        }
                        ItemRibKind(_) | FnItemRibKind | AssocItemRibKind => {
                            // This was an attempt to access an upvar inside a
                            // named function item. This is not allowed, so we
                            // report an error.
                            if record_used {
                                // We don't immediately trigger a resolve error, because
                                // we want certain other resolution errors (namely those
                                // emitted for `ConstantItemRibKind` below) to take
                                // precedence.
                                res_err = Some(CannotCaptureDynamicEnvironmentInFnItem);
                            }
                        }
                        ConstantItemRibKind => {
                            // Still doesn't deal with upvars
                            if record_used {
                                self.report_error(span, AttemptToUseNonConstantValueInConstant);
                            }
                            return Res::Err;
                        }
                    }
                }
                if let Some(res_err) = res_err {
                    self.report_error(span, res_err);
                    return Res::Err;
                }
            }
            Res::Def(DefKind::TyParam, _) | Res::SelfTy(..) => {
                for rib in ribs {
                    let has_generic_params = match rib.kind {
                        NormalRibKind
                        | ClosureOrAsyncRibKind
                        | AssocItemRibKind
                        | ModuleRibKind(..)
                        | MacroDefinition(..)
                        | ForwardTyParamBanRibKind
                        | ConstantItemRibKind => {
                            // Nothing to do. Continue.
                            continue;
                        }
                        // This was an attempt to use a type parameter outside its scope.
                        ItemRibKind(has_generic_params) => has_generic_params,
                        FnItemRibKind => HasGenericParams::Yes,
                    };
                    if record_used {
                        self.report_error(
                            span,
                            ResolutionError::GenericParamsFromOuterFunction(
                                res,
                                has_generic_params,
                            ),
                        );
                    }
                    return Res::Err;
                }
            }
            Res::Def(DefKind::ConstParam, _) => {
                let mut ribs = ribs.iter().peekable();
                if let Some(Rib { kind: FnItemRibKind, .. }) = ribs.peek() {
                    // When declaring const parameters inside function signatures, the first rib
                    // is always a `FnItemRibKind`. In this case, we can skip it, to avoid it
                    // (spuriously) conflicting with the const param.
                    ribs.next();
                }
                for rib in ribs {
                    let has_generic_params = match rib.kind {
                        ItemRibKind(has_generic_params) => has_generic_params,
                        FnItemRibKind => HasGenericParams::Yes,
                        _ => continue,
                    };
                    // This was an attempt to use a const parameter outside its scope.
                    if record_used {
                        self.report_error(
                            span,
                            ResolutionError::GenericParamsFromOuterFunction(
                                res,
                                has_generic_params,
                            ),
                        );
                    }
                    return Res::Err;
                }
            }
            _ => {}
        }
        res
    }
fn validate_res_from_ribs ( & mut self , rib_index : usize , rib_ident : Ident , res : Res , record_used : bool , span : Span , all_ribs : & [ Rib < ' a > ] , ) -> Res { debug ! ( " " res ) ; let ribs = & all_ribs [ rib_index + 1 .. ] ; // An invalid forward use of a type parameter from a previous default. if let ForwardTyParamBanRibKind = all_ribs [ rib_index ] . kind { if record_used { let res_error = if rib_ident . name == kw :: SelfUpper { ResolutionError :: SelfInTyParamDefault } else { ResolutionError :: ForwardDeclaredTyParam } ; self . report_error ( span , res_error ) ; } assert_eq ! ( res Res Err ) ; return Res :: Err ; } match res { Res :: Local ( _ ) => { use ResolutionError :: * ; let mut res_err = None ; for rib in ribs { match rib . kind { NormalRibKind | ClosureOrAsyncRibKind | ModuleRibKind ( .. ) | MacroDefinition ( .. ) | ForwardTyParamBanRibKind => { // Nothing to do. Continue. } ItemRibKind ( _ ) | FnItemRibKind | AssocItemRibKind => { // This was an attempt to access an upvar inside a // named function item. This is not allowed, so we // report an error. if record_used { // We don't immediately trigger a resolve error, because // we want certain other resolution errors (namely those // emitted for `ConstantItemRibKind` below) to take // precedence. res_err = Some ( CannotCaptureDynamicEnvironmentInFnItem ) ; } } ConstantItemRibKind => { // Still doesn't deal with upvars if record_used { self . report_error ( span , AttemptToUseNonConstantValueInConstant ) ; } return Res :: Err ; } } } if let Some ( res_err ) = res_err { self . report_error ( span , res_err ) ; return Res :: Err ; } } Res :: Def ( DefKind :: TyParam , _ ) | Res :: SelfTy ( .. ) => { for rib in ribs { let has_generic_params = match rib . kind { NormalRibKind | ClosureOrAsyncRibKind | AssocItemRibKind | ModuleRibKind ( .. ) | MacroDefinition ( .. ) | ForwardTyParamBanRibKind | ConstantItemRibKind => { // Nothing to do. Continue. continue ; } // This was an attempt to use a type parameter outside its scope. ItemRibKind ( has_generic_params ) => has_generic_params , FnItemRibKind => HasGenericParams :: Yes , } ; if record_used { self . report_error ( span , ResolutionError :: GenericParamsFromOuterFunction ( res , has_generic_params , ) , ) ; } return Res :: Err ; } } Res :: Def ( DefKind :: ConstParam , _ ) => { let mut ribs = ribs . iter ( ) . peekable ( ) ; if let Some ( Rib { kind : FnItemRibKind , .. } ) = ribs . peek ( ) { // When declaring const parameters inside function signatures, the first rib // is always a `FnItemRibKind`. In this case, we can skip it, to avoid it // (spuriously) conflicting with the const param. ribs . next ( ) ; } for rib in ribs { let has_generic_params = match rib . kind { ItemRibKind ( has_generic_params ) => has_generic_params , FnItemRibKind => HasGenericParams :: Yes , _ => continue , } ; // This was an attempt to use a const parameter outside its scope. if record_used { self . report_error ( span , ResolutionError :: GenericParamsFromOuterFunction ( res , has_generic_params , ) , ) ; } return Res :: Err ; } } _ => { } } res }
Validate a local resolution (from ribs).
Validate a local resolution ( from ribs ) .
&mut self
rib_index
usize
rib_ident
Ident
res
Res
record_used
bool
span
Span
all_ribs
&[Rib<'a>]
&mut self
rib_index
usize
rib_ident
Ident
res
Res
record_used
bool
span
Span
all_ribs
&[Rib<'a>]