fn resolve_qpath(
        &mut self,
        id: NodeId,
        qself: Option<&QSelf>,
        path: &[Segment],
        ns: Namespace,
        span: Span,
        crate_lint: CrateLint,
    ) -> Result<Option<PartialRes>, Spanned<ResolutionError<'a>>> {
        debug!(
            "resolve_qpath(id={:?}, qself={:?}, path={:?}, ns={:?}, span={:?})",
            id, qself, path, ns, span,
        );

        if let Some(qself) = qself {
            if qself.position == 0 {
                // This is a case like `<T>::B`, where there is no
                // trait to resolve.  In that case, we leave the `B`
                // segment to be resolved by type-check.
                return Ok(Some(PartialRes::with_unresolved_segments(
                    Res::Def(DefKind::Mod, DefId::local(CRATE_DEF_INDEX)),
                    path.len(),
                )));
            }

            // Make sure `A::B` in `<T as A::B>::C` is a trait item.
            //
            // Currently, `path` names the full item (`A::B::C`, in
            // our example).  so we extract the prefix of that that is
            // the trait (the slice upto and including
            // `qself.position`). And then we recursively resolve that,
            // but with `qself` set to `None`.
            //
            // However, setting `qself` to none (but not changing the
            // span) loses the information about where this path
            // *actually* appears, so for the purposes of the crate
            // lint we pass along information that this is the trait
            // name from a fully qualified path, and this also
            // contains the full span (the `CrateLint::QPathTrait`).
            let ns = if qself.position + 1 == path.len() { ns } else { TypeNS };
            let partial_res = self.smart_resolve_path_fragment(
                id,
                None,
                &path[..=qself.position],
                span,
                PathSource::TraitItem(ns),
                CrateLint::QPathTrait { qpath_id: id, qpath_span: qself.path_span },
            );

            // The remaining segments (the `C` in our example) will
            // have to be resolved by type-check, since that requires doing
            // trait resolution.
            return Ok(Some(PartialRes::with_unresolved_segments(
                partial_res.base_res(),
                partial_res.unresolved_segments() + path.len() - qself.position - 1,
            )));
        }

        let result = match self.resolve_path(&path, Some(ns), true, span, crate_lint) {
            PathResult::NonModule(path_res) => path_res,
            PathResult::Module(ModuleOrUniformRoot::Module(module)) if !module.is_normal() => {
                PartialRes::new(module.res().unwrap())
            }
            // In `a(::assoc_item)*` `a` cannot be a module. If `a` does resolve to a module we
            // don't report an error right away, but try to fallback to a primitive type.
            // So, we are still able to successfully resolve something like
            //
            // use std::u8; // bring module u8 in scope
            // fn f() -> u8 { // OK, resolves to primitive u8, not to std::u8
            //     u8::max_value() // OK, resolves to associated function <u8>::max_value,
            //                     // not to non-existent std::u8::max_value
            // }
            //
            // Such behavior is required for backward compatibility.
            // The same fallback is used when `a` resolves to nothing.
            PathResult::Module(ModuleOrUniformRoot::Module(_)) | PathResult::Failed { .. }
                if (ns == TypeNS || path.len() > 1)
                    && self
                        .r
                        .primitive_type_table
                        .primitive_types
                        .contains_key(&path[0].ident.name) =>
            {
                let prim = self.r.primitive_type_table.primitive_types[&path[0].ident.name];
                PartialRes::with_unresolved_segments(Res::PrimTy(prim), path.len() - 1)
            }
            PathResult::Module(ModuleOrUniformRoot::Module(module)) => {
                PartialRes::new(module.res().unwrap())
            }
            PathResult::Failed { is_error_from_last_segment: false, span, label, suggestion } => {
                return Err(respan(span, ResolutionError::FailedToResolve { label, suggestion }));
            }
            PathResult::Module(..) | PathResult::Failed { .. } => return Ok(None),
            PathResult::Indeterminate => bug!("indeterminate path result in resolve_qpath"),
        };

        if path.len() > 1
            && result.base_res() != Res::Err
            && path[0].ident.name != kw::PathRoot
            && path[0].ident.name != kw::DollarCrate
        {
            let unqualified_result = {
                match self.resolve_path(
                    &[*path.last().unwrap()],
                    Some(ns),
                    false,
                    span,
                    CrateLint::No,
                ) {
                    PathResult::NonModule(path_res) => path_res.base_res(),
                    PathResult::Module(ModuleOrUniformRoot::Module(module)) => {
                        module.res().unwrap()
                    }
                    _ => return Ok(Some(result)),
                }
            };
            if result.base_res() == unqualified_result {
                let lint = lint::builtin::UNUSED_QUALIFICATIONS;
                self.r.lint_buffer.buffer_lint(lint, id, span, "unnecessary qualification")
            }
        }

        Ok(Some(result))
    }
/// Handles paths that may refer to associated items.
Handles paths that may refer to associated items.
Handles paths that may refer to associated items .
fn resolve_qpath(
        &mut self,
        id: NodeId,
        qself: Option<&QSelf>,
        path: &[Segment],
        ns: Namespace,
        span: Span,
        crate_lint: CrateLint,
    ) -> Result<Option<PartialRes>, Spanned<ResolutionError<'a>>> {
        debug!(
            "resolve_qpath(id={:?}, qself={:?}, path={:?}, ns={:?}, span={:?})",
            id, qself, path, ns, span,
        );
        if let Some(qself) = qself {
            if qself.position == 0 {
                // This is a case like `<T>::B`, where there is no
                // trait to resolve.  In that case, we leave the `B`
                // segment to be resolved by type-check.
                return Ok(Some(PartialRes::with_unresolved_segments(
                    Res::Def(DefKind::Mod, DefId::local(CRATE_DEF_INDEX)),
                    path.len(),
                )));
            }
            // Make sure `A::B` in `<T as A::B>::C` is a trait item.
            //
            // Currently, `path` names the full item (`A::B::C`, in
            // our example).  so we extract the prefix of that that is
            // the trait (the slice upto and including
            // `qself.position`). And then we recursively resolve that,
            // but with `qself` set to `None`.
            //
            // However, setting `qself` to none (but not changing the
            // span) loses the information about where this path
            // *actually* appears, so for the purposes of the crate
            // lint we pass along information that this is the trait
            // name from a fully qualified path, and this also
            // contains the full span (the `CrateLint::QPathTrait`).
            let ns = if qself.position + 1 == path.len() { ns } else { TypeNS };
            let partial_res = self.smart_resolve_path_fragment(
                id,
                None,
                &path[..=qself.position],
                span,
                PathSource::TraitItem(ns),
                CrateLint::QPathTrait { qpath_id: id, qpath_span: qself.path_span },
            );
            // The remaining segments (the `C` in our example) will
            // have to be resolved by type-check, since that requires doing
            // trait resolution.
            return Ok(Some(PartialRes::with_unresolved_segments(
                partial_res.base_res(),
                partial_res.unresolved_segments() + path.len() - qself.position - 1,
            )));
        }
        let result = match self.resolve_path(&path, Some(ns), true, span, crate_lint) {
            PathResult::NonModule(path_res) => path_res,
            PathResult::Module(ModuleOrUniformRoot::Module(module)) if !module.is_normal() => {
                PartialRes::new(module.res().unwrap())
            }
            // In `a(::assoc_item)*` `a` cannot be a module. If `a` does resolve to a module we
            // don't report an error right away, but try to fallback to a primitive type.
            // So, we are still able to successfully resolve something like
            //
            // use std::u8; // bring module u8 in scope
            // fn f() -> u8 { // OK, resolves to primitive u8, not to std::u8
            //     u8::max_value() // OK, resolves to associated function <u8>::max_value,
            //                     // not to non-existent std::u8::max_value
            // }
            //
            // Such behavior is required for backward compatibility.
            // The same fallback is used when `a` resolves to nothing.
            PathResult::Module(ModuleOrUniformRoot::Module(_)) | PathResult::Failed { .. }
                if (ns == TypeNS || path.len() > 1)
                    && self
                        .r
                        .primitive_type_table
                        .primitive_types
                        .contains_key(&path[0].ident.name) =>
            {
                let prim = self.r.primitive_type_table.primitive_types[&path[0].ident.name];
                PartialRes::with_unresolved_segments(Res::PrimTy(prim), path.len() - 1)
            }
            PathResult::Module(ModuleOrUniformRoot::Module(module)) => {
                PartialRes::new(module.res().unwrap())
            }
            PathResult::Failed { is_error_from_last_segment: false, span, label, suggestion } => {
                return Err(respan(span, ResolutionError::FailedToResolve { label, suggestion }));
            }
            PathResult::Module(..) | PathResult::Failed { .. } => return Ok(None),
            PathResult::Indeterminate => bug!("indeterminate path result in resolve_qpath"),
        };
        if path.len() > 1
            && result.base_res() != Res::Err
            && path[0].ident.name != kw::PathRoot
            && path[0].ident.name != kw::DollarCrate
        {
            let unqualified_result = {
                match self.resolve_path(
                    &[*path.last().unwrap()],
                    Some(ns),
                    false,
                    span,
                    CrateLint::No,
                ) {
                    PathResult::NonModule(path_res) => path_res.base_res(),
                    PathResult::Module(ModuleOrUniformRoot::Module(module)) => {
                        module.res().unwrap()
                    }
                    _ => return Ok(Some(result)),
                }
            };
            if result.base_res() == unqualified_result {
                let lint = lint::builtin::UNUSED_QUALIFICATIONS;
                self.r.lint_buffer.buffer_lint(lint, id, span, "unnecessary qualification")
            }
        }
        Ok(Some(result))
    }
fn resolve_qpath ( & mut self , id : NodeId , qself : Option < & QSelf > , path : & [ Segment ] , ns : Namespace , span : Span , crate_lint : CrateLint , ) -> Result < Option < PartialRes > , Spanned < ResolutionError < ' a > > > { debug ! ( " " id qself path ns span ) ; if let Some ( qself ) = qself { if qself . position == 0 { // This is a case like `<T>::B`, where there is no // trait to resolve.  In that case, we leave the `B` // segment to be resolved by type-check. return Ok ( Some ( PartialRes :: with_unresolved_segments ( Res :: Def ( DefKind :: Mod , DefId :: local ( CRATE_DEF_INDEX ) ) , path . len ( ) , ) ) ) ; } // Make sure `A::B` in `<T as A::B>::C` is a trait item. // // Currently, `path` names the full item (`A::B::C`, in // our example).  so we extract the prefix of that that is // the trait (the slice upto and including // `qself.position`). And then we recursively resolve that, // but with `qself` set to `None`. // // However, setting `qself` to none (but not changing the // span) loses the information about where this path // *actually* appears, so for the purposes of the crate // lint we pass along information that this is the trait // name from a fully qualified path, and this also // contains the full span (the `CrateLint::QPathTrait`). let ns = if qself . position + 1 == path . len ( ) { ns } else { TypeNS } ; let partial_res = self . smart_resolve_path_fragment ( id , None , & path [ .. = qself . position ] , span , PathSource :: TraitItem ( ns ) , CrateLint :: QPathTrait { qpath_id : id , qpath_span : qself . path_span } , ) ; // The remaining segments (the `C` in our example) will // have to be resolved by type-check, since that requires doing // trait resolution. return Ok ( Some ( PartialRes :: with_unresolved_segments ( partial_res . base_res ( ) , partial_res . unresolved_segments ( ) + path . len ( ) - qself . position - 1 , ) ) ) ; } let result = match self . resolve_path ( & path , Some ( ns ) , true , span , crate_lint ) { PathResult :: NonModule ( path_res ) => path_res , PathResult :: Module ( ModuleOrUniformRoot :: Module ( module ) ) if ! module . is_normal ( ) => { PartialRes :: new ( module . res ( ) . unwrap ( ) ) } // In `a(::assoc_item)*` `a` cannot be a module. If `a` does resolve to a module we // don't report an error right away, but try to fallback to a primitive type. // So, we are still able to successfully resolve something like // // use std::u8; // bring module u8 in scope // fn f() -> u8 { // OK, resolves to primitive u8, not to std::u8 //     u8::max_value() // OK, resolves to associated function <u8>::max_value, //                     // not to non-existent std::u8::max_value // } // // Such behavior is required for backward compatibility. // The same fallback is used when `a` resolves to nothing. PathResult :: Module ( ModuleOrUniformRoot :: Module ( _ ) ) | PathResult :: Failed { .. } if ( ns == TypeNS || path . len ( ) > 1 ) && self . r . primitive_type_table . primitive_types . contains_key ( & path [ 0 ] . ident . name ) => { let prim = self . r . primitive_type_table . primitive_types [ & path [ 0 ] . ident . name ] ; PartialRes :: with_unresolved_segments ( Res :: PrimTy ( prim ) , path . len ( ) - 1 ) } PathResult :: Module ( ModuleOrUniformRoot :: Module ( module ) ) => { PartialRes :: new ( module . res ( ) . unwrap ( ) ) } PathResult :: Failed { is_error_from_last_segment : false , span , label , suggestion } => { return Err ( respan ( span , ResolutionError :: FailedToResolve { label , suggestion } ) ) ; } PathResult :: Module ( .. ) | PathResult :: Failed { .. } => return Ok ( None ) , PathResult :: Indeterminate => bug ! ( " " ) , } ; if path . len ( ) > 1 && result . base_res ( ) != Res :: Err && path [ 0 ] . ident . name != kw :: PathRoot && path [ 0 ] . ident . name != kw :: DollarCrate { let unqualified_result = { match self . resolve_path ( & [ * path . last ( ) . unwrap ( ) ] , Some ( ns ) , false , span , CrateLint :: No , ) { PathResult :: NonModule ( path_res ) => path_res . base_res ( ) , PathResult :: Module ( ModuleOrUniformRoot :: Module ( module ) ) => { module . res ( ) . unwrap ( ) } _ => return Ok ( Some ( result ) ) , } } ; if result . base_res ( ) == unqualified_result { let lint = lint :: builtin :: UNUSED_QUALIFICATIONS ; self . r . lint_buffer . buffer_lint ( lint , id , span , " " ) } } Ok ( Some ( result ) ) }
Handles paths that may refer to associated items.
Handles paths that may refer to associated items .
&mut self
id
NodeId
qself
Option<&QSelf>
path
&[Segment]
ns
Namespace
span
Span
crate_lint
CrateLint
&mut self
id
NodeId
qself
Option<&QSelf>
path
&[Segment]
ns
Namespace
span
Span
crate_lint
CrateLint