pub fn def_to_ty(&self,
                     rscope: &RegionScope,
                     opt_self_ty: Option<Ty<'tcx>>,
                     path: &hir::Path,
                     path_id: ast::NodeId,
                     permit_variants: bool)
                     -> Ty<'tcx> {
        let tcx = self.tcx();

        debug!("base_def_to_ty(def={:?}, opt_self_ty={:?}, path_segments={:?})",
               path.def, opt_self_ty, path.segments);

        let span = path.span;
        match path.def {
            Def::Trait(trait_def_id) => {
                // N.B. this case overlaps somewhat with
                // TyTraitObject, see that fn for details

                assert_eq!(opt_self_ty, None);
                tcx.prohibit_type_params(path.segments.split_last().unwrap().1);

                self.trait_path_to_object_type(rscope,
                                               span,
                                               trait_def_id,
                                               path_id,
                                               path.segments.last().unwrap(),
                                               span,
                                               partition_bounds(&[]))
            }
            Def::Enum(did) | Def::TyAlias(did) | Def::Struct(did) | Def::Union(did) => {
                assert_eq!(opt_self_ty, None);
                tcx.prohibit_type_params(path.segments.split_last().unwrap().1);
                self.ast_path_to_ty(rscope, span, did, path.segments.last().unwrap())
            }
            Def::Variant(did) if permit_variants => {
                // Convert "variant type" as if it were a real type.
                // The resulting `Ty` is type of the variant's enum for now.
                assert_eq!(opt_self_ty, None);
                tcx.prohibit_type_params(path.segments.split_last().unwrap().1);
                self.ast_path_to_ty(rscope,
                                    span,
                                    tcx.parent_def_id(did).unwrap(),
                                    path.segments.last().unwrap())
            }
            Def::TyParam(did) => {
                assert_eq!(opt_self_ty, None);
                tcx.prohibit_type_params(&path.segments);

                let node_id = tcx.hir.as_local_node_id(did).unwrap();
                let param = tcx.ty_param_defs.borrow().get(&node_id)
                               .map(ty::ParamTy::for_def);
                if let Some(p) = param {
                    p.to_ty(tcx)
                } else {
                    // Only while computing defaults of earlier type
                    // parameters can a type parameter be missing its def.
                    struct_span_err!(tcx.sess, span, E0128,
                                     "type parameters with a default cannot use \
                                      forward declared identifiers")
                        .span_label(span, &format!("defaulted type parameters \
                                                    cannot be forward declared"))
                        .emit();
                    tcx.types.err
                }
            }
            Def::SelfTy(_, Some(def_id)) => {
                // Self in impl (we know the concrete type).

                assert_eq!(opt_self_ty, None);
                tcx.prohibit_type_params(&path.segments);

                // FIXME: Self type is not always computed when we are here because type parameter
                // bounds may affect Self type and have to be converted before it.
                let ty = if def_id.is_local() {
                    tcx.item_types.borrow().get(&def_id).cloned()
                } else {
                    Some(tcx.item_type(def_id))
                };
                if let Some(ty) = ty {
                    if let Some(free_substs) = self.get_free_substs() {
                        ty.subst(tcx, free_substs)
                    } else {
                        ty
                    }
                } else {
                    tcx.sess.span_err(span, "`Self` type is used before it's determined");
                    tcx.types.err
                }
            }
            Def::SelfTy(Some(_), None) => {
                // Self in trait.
                assert_eq!(opt_self_ty, None);
                tcx.prohibit_type_params(&path.segments);
                tcx.mk_self_type()
            }
            Def::AssociatedTy(def_id) => {
                tcx.prohibit_type_params(&path.segments[..path.segments.len()-2]);
                let trait_did = tcx.parent_def_id(def_id).unwrap();
                self.qpath_to_ty(rscope,
                                 span,
                                 opt_self_ty,
                                 trait_did,
                                 &path.segments[path.segments.len()-2],
                                 path.segments.last().unwrap())
            }
            Def::PrimTy(prim_ty) => {
                assert_eq!(opt_self_ty, None);
                tcx.prim_ty_to_ty(&path.segments, prim_ty)
            }
            Def::Err => {
                self.set_tainted_by_errors();
                return self.tcx().types.err;
            }
            _ => span_bug!(span, "unexpected definition: {:?}", path.def)
        }
    }
// Check a type Path and convert it to a Ty.
Check a type Path and convert it to a Ty.
Check a type Path and convert it to a Ty .
pub fn def_to_ty(&self,
                     rscope: &RegionScope,
                     opt_self_ty: Option<Ty<'tcx>>,
                     path: &hir::Path,
                     path_id: ast::NodeId,
                     permit_variants: bool)
                     -> Ty<'tcx> {
        let tcx = self.tcx();
        debug!("base_def_to_ty(def={:?}, opt_self_ty={:?}, path_segments={:?})",
               path.def, opt_self_ty, path.segments);
        let span = path.span;
        match path.def {
            Def::Trait(trait_def_id) => {
                // N.B. this case overlaps somewhat with
                // TyTraitObject, see that fn for details
                assert_eq!(opt_self_ty, None);
                tcx.prohibit_type_params(path.segments.split_last().unwrap().1);
                self.trait_path_to_object_type(rscope,
                                               span,
                                               trait_def_id,
                                               path_id,
                                               path.segments.last().unwrap(),
                                               span,
                                               partition_bounds(&[]))
            }
            Def::Enum(did) | Def::TyAlias(did) | Def::Struct(did) | Def::Union(did) => {
                assert_eq!(opt_self_ty, None);
                tcx.prohibit_type_params(path.segments.split_last().unwrap().1);
                self.ast_path_to_ty(rscope, span, did, path.segments.last().unwrap())
            }
            Def::Variant(did) if permit_variants => {
                // Convert "variant type" as if it were a real type.
                // The resulting `Ty` is type of the variant's enum for now.
                assert_eq!(opt_self_ty, None);
                tcx.prohibit_type_params(path.segments.split_last().unwrap().1);
                self.ast_path_to_ty(rscope,
                                    span,
                                    tcx.parent_def_id(did).unwrap(),
                                    path.segments.last().unwrap())
            }
            Def::TyParam(did) => {
                assert_eq!(opt_self_ty, None);
                tcx.prohibit_type_params(&path.segments);
                let node_id = tcx.hir.as_local_node_id(did).unwrap();
                let param = tcx.ty_param_defs.borrow().get(&node_id)
                               .map(ty::ParamTy::for_def);
                if let Some(p) = param {
                    p.to_ty(tcx)
                } else {
                    // Only while computing defaults of earlier type
                    // parameters can a type parameter be missing its def.
                    struct_span_err!(tcx.sess, span, E0128,
                                     "type parameters with a default cannot use \
                                      forward declared identifiers")
                        .span_label(span, &format!("defaulted type parameters \
                                                    cannot be forward declared"))
                        .emit();
                    tcx.types.err
                }
            }
            Def::SelfTy(_, Some(def_id)) => {
                // Self in impl (we know the concrete type).
                assert_eq!(opt_self_ty, None);
                tcx.prohibit_type_params(&path.segments);
                // FIXME: Self type is not always computed when we are here because type parameter
                // bounds may affect Self type and have to be converted before it.
                let ty = if def_id.is_local() {
                    tcx.item_types.borrow().get(&def_id).cloned()
                } else {
                    Some(tcx.item_type(def_id))
                };
                if let Some(ty) = ty {
                    if let Some(free_substs) = self.get_free_substs() {
                        ty.subst(tcx, free_substs)
                    } else {
                        ty
                    }
                } else {
                    tcx.sess.span_err(span, "`Self` type is used before it's determined");
                    tcx.types.err
                }
            }
            Def::SelfTy(Some(_), None) => {
                // Self in trait.
                assert_eq!(opt_self_ty, None);
                tcx.prohibit_type_params(&path.segments);
                tcx.mk_self_type()
            }
            Def::AssociatedTy(def_id) => {
                tcx.prohibit_type_params(&path.segments[..path.segments.len()-2]);
                let trait_did = tcx.parent_def_id(def_id).unwrap();
                self.qpath_to_ty(rscope,
                                 span,
                                 opt_self_ty,
                                 trait_did,
                                 &path.segments[path.segments.len()-2],
                                 path.segments.last().unwrap())
            }
            Def::PrimTy(prim_ty) => {
                assert_eq!(opt_self_ty, None);
                tcx.prim_ty_to_ty(&path.segments, prim_ty)
            }
            Def::Err => {
                self.set_tainted_by_errors();
                return self.tcx().types.err;
            }
            _ => span_bug!(span, "unexpected definition: {:?}", path.def)
        }
    }
pub fn def_to_ty ( & self , rscope : & RegionScope , opt_self_ty : Option < Ty < ' tcx > > , path : & hir :: Path , path_id : ast :: NodeId , permit_variants : bool ) -> Ty < ' tcx > { let tcx = self . tcx ( ) ; debug ! ( " " path def opt_self_ty path segments ) ; let span = path . span ; match path . def { Def :: Trait ( trait_def_id ) => { // N.B. this case overlaps somewhat with // TyTraitObject, see that fn for details assert_eq ! ( opt_self_ty None ) ; tcx . prohibit_type_params ( path . segments . split_last ( ) . unwrap ( ) . 1 ) ; self . trait_path_to_object_type ( rscope , span , trait_def_id , path_id , path . segments . last ( ) . unwrap ( ) , span , partition_bounds ( & [ ] ) ) } Def :: Enum ( did ) | Def :: TyAlias ( did ) | Def :: Struct ( did ) | Def :: Union ( did ) => { assert_eq ! ( opt_self_ty None ) ; tcx . prohibit_type_params ( path . segments . split_last ( ) . unwrap ( ) . 1 ) ; self . ast_path_to_ty ( rscope , span , did , path . segments . last ( ) . unwrap ( ) ) } Def :: Variant ( did ) if permit_variants => { // Convert "variant type" as if it were a real type. // The resulting `Ty` is type of the variant's enum for now. assert_eq ! ( opt_self_ty None ) ; tcx . prohibit_type_params ( path . segments . split_last ( ) . unwrap ( ) . 1 ) ; self . ast_path_to_ty ( rscope , span , tcx . parent_def_id ( did ) . unwrap ( ) , path . segments . last ( ) . unwrap ( ) ) } Def :: TyParam ( did ) => { assert_eq ! ( opt_self_ty None ) ; tcx . prohibit_type_params ( & path . segments ) ; let node_id = tcx . hir . as_local_node_id ( did ) . unwrap ( ) ; let param = tcx . ty_param_defs . borrow ( ) . get ( & node_id ) . map ( ty :: ParamTy :: for_def ) ; if let Some ( p ) = param { p . to_ty ( tcx ) } else { // Only while computing defaults of earlier type // parameters can a type parameter be missing its def. struct_span_err ! ( tcx sess span E0128 " \
 " ) . span_label ( span , & format ! ( " \
 " ) ) . emit ( ) ; tcx . types . err } } Def :: SelfTy ( _ , Some ( def_id ) ) => { // Self in impl (we know the concrete type). assert_eq ! ( opt_self_ty None ) ; tcx . prohibit_type_params ( & path . segments ) ; // FIXME: Self type is not always computed when we are here because type parameter // bounds may affect Self type and have to be converted before it. let ty = if def_id . is_local ( ) { tcx . item_types . borrow ( ) . get ( & def_id ) . cloned ( ) } else { Some ( tcx . item_type ( def_id ) ) } ; if let Some ( ty ) = ty { if let Some ( free_substs ) = self . get_free_substs ( ) { ty . subst ( tcx , free_substs ) } else { ty } } else { tcx . sess . span_err ( span , " " ) ; tcx . types . err } } Def :: SelfTy ( Some ( _ ) , None ) => { // Self in trait. assert_eq ! ( opt_self_ty None ) ; tcx . prohibit_type_params ( & path . segments ) ; tcx . mk_self_type ( ) } Def :: AssociatedTy ( def_id ) => { tcx . prohibit_type_params ( & path . segments [ .. path . segments . len ( ) - 2 ] ) ; let trait_did = tcx . parent_def_id ( def_id ) . unwrap ( ) ; self . qpath_to_ty ( rscope , span , opt_self_ty , trait_did , & path . segments [ path . segments . len ( ) - 2 ] , path . segments . last ( ) . unwrap ( ) ) } Def :: PrimTy ( prim_ty ) => { assert_eq ! ( opt_self_ty None ) ; tcx . prim_ty_to_ty ( & path . segments , prim_ty ) } Def :: Err => { self . set_tainted_by_errors ( ) ; return self . tcx ( ) . types . err ; } _ => span_bug ! ( span " " path def ) } }
Check a type Path and convert it to a Ty.
Check a type Path and convert it to a Ty .
&self
rscope
&RegionScope
opt_self_ty
Option<Ty<'tcx>>
path
&hir::Path
path_id
ast::NodeId
permit_variants
bool