fn create_substs_for_ast_path(&self,
        rscope: &RegionScope,
        span: Span,
        def_id: DefId,
        parameters: &hir::PathParameters,
        self_ty: Option<Ty<'tcx>>)
        -> (&'tcx Substs<'tcx>, Vec<ConvertedBinding<'tcx>>)
    {
        let tcx = self.tcx();

        debug!("create_substs_for_ast_path(def_id={:?}, self_ty={:?}, \
               parameters={:?})",
               def_id, self_ty, parameters);

        let (lifetimes, num_types_provided, infer_types) = match *parameters {
            hir::AngleBracketedParameters(ref data) => {
                (&data.lifetimes[..], data.types.len(), data.infer_types)
            }
            hir::ParenthesizedParameters(_) => (&[][..], 1, false)
        };

        // If the type is parameterized by this region, then replace this
        // region with the current anon region binding (in other words,
        // whatever & would get replaced with).
        let decl_generics = match self.get_generics(span, def_id) {
            Ok(generics) => generics,
            Err(ErrorReported) => {
                // No convenient way to recover from a cycle here. Just bail. Sorry!
                self.tcx().sess.abort_if_errors();
                bug!("ErrorReported returned, but no errors reports?")
            }
        };
        let expected_num_region_params = decl_generics.regions.len();
        let supplied_num_region_params = lifetimes.len();
        let regions = if expected_num_region_params == supplied_num_region_params {
            lifetimes.iter().map(|l| *ast_region_to_region(tcx, l)).collect()
        } else {
            let anon_regions =
                rscope.anon_regions(span, expected_num_region_params);

            if supplied_num_region_params != 0 || anon_regions.is_err() {
                report_lifetime_number_error(tcx, span,
                                             supplied_num_region_params,
                                             expected_num_region_params);
            }

            match anon_regions {
                Ok(anon_regions) => anon_regions,
                Err(_) => (0..expected_num_region_params).map(|_| ty::ReStatic).collect()
            }
        };

        // If a self-type was declared, one should be provided.
        assert_eq!(decl_generics.has_self, self_ty.is_some());

        // Check the number of type parameters supplied by the user.
        let ty_param_defs = &decl_generics.types[self_ty.is_some() as usize..];
        if !infer_types || num_types_provided > ty_param_defs.len() {
            check_type_argument_count(tcx, span, num_types_provided, ty_param_defs);
        }

        let is_object = self_ty.map_or(false, |ty| ty.sty == TRAIT_OBJECT_DUMMY_SELF);
        let default_needs_object_self = |p: &ty::TypeParameterDef<'tcx>| {
            if let Some(ref default) = p.default {
                if is_object && default.has_self_ty() {
                    // There is no suitable inference default for a type parameter
                    // that references self, in an object type.
                    return true;
                }
            }

            false
        };

        let mut output_assoc_binding = None;
        let substs = Substs::for_item(tcx, def_id, |def, _| {
            let i = def.index as usize - self_ty.is_some() as usize;
            tcx.mk_region(regions[i])
        }, |def, substs| {
            let i = def.index as usize;

            // Handle Self first, so we can adjust the index to match the AST.
            if let (0, Some(ty)) = (i, self_ty) {
                return ty;
            }

            let i = i - self_ty.is_some() as usize - decl_generics.regions.len();
            if i < num_types_provided {
                // A provided type parameter.
                match *parameters {
                    hir::AngleBracketedParameters(ref data) => {
                        self.ast_ty_arg_to_ty(rscope, Some(def), substs, &data.types[i])
                    }
                    hir::ParenthesizedParameters(ref data) => {
                        assert_eq!(i, 0);
                        let (ty, assoc) =
                            self.convert_parenthesized_parameters(rscope, substs, data);
                        output_assoc_binding = Some(assoc);
                        ty
                    }
                }
            } else if infer_types {
                // No type parameters were provided, we can infer all.
                let ty_var = if !default_needs_object_self(def) {
                    self.ty_infer_for_def(def, substs, span)
                } else {
                    self.ty_infer(span)
                };
                ty_var
            } else if let Some(default) = def.default {
                // No type parameter provided, but a default exists.

                // If we are converting an object type, then the
                // `Self` parameter is unknown. However, some of the
                // other type parameters may reference `Self` in their
                // defaults. This will lead to an ICE if we are not
                // careful!
                if default_needs_object_self(def) {
                    struct_span_err!(tcx.sess, span, E0393,
                                     "the type parameter `{}` must be explicitly specified",
                                     def.name)
                        .span_label(span, &format!("missing reference to `{}`", def.name))
                        .note(&format!("because of the default `Self` reference, \
                                        type parameters must be specified on object types"))
                        .emit();
                    tcx.types.err
                } else {
                    // This is a default type parameter.
                    default.subst_spanned(tcx, substs, Some(span))
                }
            } else {
                // We've already errored above about the mismatch.
                tcx.types.err
            }
        });

        let assoc_bindings = match *parameters {
            hir::AngleBracketedParameters(ref data) => {
                data.bindings.iter().map(|b| {
                    ConvertedBinding {
                        item_name: b.name,
                        ty: self.ast_ty_to_ty(rscope, &b.ty),
                        span: b.span
                    }
                }).collect()
            }
            hir::ParenthesizedParameters(ref data) => {
                vec![output_assoc_binding.unwrap_or_else(|| {
                    // This is an error condition, but we should
                    // get the associated type binding anyway.
                    self.convert_parenthesized_parameters(rscope, substs, data).1
                })]
            }
        };

        debug!("create_substs_for_ast_path(decl_generics={:?}, self_ty={:?}) -> {:?}",
               decl_generics, self_ty, substs);

        (substs, assoc_bindings)
    }
/// Given the type/region arguments provided to some path (along with
/// an implicit Self, if this is a trait reference) returns the complete
/// set of substitutions. This may involve applying defaulted type parameters.
///
/// Note that the type listing given here is *exactly* what the user provided.
Given the type/region arguments provided to some path (along with
an implicit Self, if this is a trait reference) returns the complete
set of substitutions. This may involve applying defaulted type parameters.

Note that the type listing given here is *exactly* what the user provided.
Given the type / region arguments provided to some path ( along with an implicit Self if this is a trait reference ) returns the complete set of substitutions . This may involve applying defaulted type parameters . Note that the type listing given here is * exactly * what the user provided .
fn create_substs_for_ast_path(&self,
        rscope: &RegionScope,
        span: Span,
        def_id: DefId,
        parameters: &hir::PathParameters,
        self_ty: Option<Ty<'tcx>>)
        -> (&'tcx Substs<'tcx>, Vec<ConvertedBinding<'tcx>>)
    {
        let tcx = self.tcx();
        debug!("create_substs_for_ast_path(def_id={:?}, self_ty={:?}, \
               parameters={:?})",
               def_id, self_ty, parameters);
        let (lifetimes, num_types_provided, infer_types) = match *parameters {
            hir::AngleBracketedParameters(ref data) => {
                (&data.lifetimes[..], data.types.len(), data.infer_types)
            }
            hir::ParenthesizedParameters(_) => (&[][..], 1, false)
        };
        // If the type is parameterized by this region, then replace this
        // region with the current anon region binding (in other words,
        // whatever & would get replaced with).
        let decl_generics = match self.get_generics(span, def_id) {
            Ok(generics) => generics,
            Err(ErrorReported) => {
                // No convenient way to recover from a cycle here. Just bail. Sorry!
                self.tcx().sess.abort_if_errors();
                bug!("ErrorReported returned, but no errors reports?")
            }
        };
        let expected_num_region_params = decl_generics.regions.len();
        let supplied_num_region_params = lifetimes.len();
        let regions = if expected_num_region_params == supplied_num_region_params {
            lifetimes.iter().map(|l| *ast_region_to_region(tcx, l)).collect()
        } else {
            let anon_regions =
                rscope.anon_regions(span, expected_num_region_params);
            if supplied_num_region_params != 0 || anon_regions.is_err() {
                report_lifetime_number_error(tcx, span,
                                             supplied_num_region_params,
                                             expected_num_region_params);
            }
            match anon_regions {
                Ok(anon_regions) => anon_regions,
                Err(_) => (0..expected_num_region_params).map(|_| ty::ReStatic).collect()
            }
        };
        // If a self-type was declared, one should be provided.
        assert_eq!(decl_generics.has_self, self_ty.is_some());
        // Check the number of type parameters supplied by the user.
        let ty_param_defs = &decl_generics.types[self_ty.is_some() as usize..];
        if !infer_types || num_types_provided > ty_param_defs.len() {
            check_type_argument_count(tcx, span, num_types_provided, ty_param_defs);
        }
        let is_object = self_ty.map_or(false, |ty| ty.sty == TRAIT_OBJECT_DUMMY_SELF);
        let default_needs_object_self = |p: &ty::TypeParameterDef<'tcx>| {
            if let Some(ref default) = p.default {
                if is_object && default.has_self_ty() {
                    // There is no suitable inference default for a type parameter
                    // that references self, in an object type.
                    return true;
                }
            }
            false
        };
        let mut output_assoc_binding = None;
        let substs = Substs::for_item(tcx, def_id, |def, _| {
            let i = def.index as usize - self_ty.is_some() as usize;
            tcx.mk_region(regions[i])
        }, |def, substs| {
            let i = def.index as usize;
            // Handle Self first, so we can adjust the index to match the AST.
            if let (0, Some(ty)) = (i, self_ty) {
                return ty;
            }
            let i = i - self_ty.is_some() as usize - decl_generics.regions.len();
            if i < num_types_provided {
                // A provided type parameter.
                match *parameters {
                    hir::AngleBracketedParameters(ref data) => {
                        self.ast_ty_arg_to_ty(rscope, Some(def), substs, &data.types[i])
                    }
                    hir::ParenthesizedParameters(ref data) => {
                        assert_eq!(i, 0);
                        let (ty, assoc) =
                            self.convert_parenthesized_parameters(rscope, substs, data);
                        output_assoc_binding = Some(assoc);
                        ty
                    }
                }
            } else if infer_types {
                // No type parameters were provided, we can infer all.
                let ty_var = if !default_needs_object_self(def) {
                    self.ty_infer_for_def(def, substs, span)
                } else {
                    self.ty_infer(span)
                };
                ty_var
            } else if let Some(default) = def.default {
                // No type parameter provided, but a default exists.
                // If we are converting an object type, then the
                // `Self` parameter is unknown. However, some of the
                // other type parameters may reference `Self` in their
                // defaults. This will lead to an ICE if we are not
                // careful!
                if default_needs_object_self(def) {
                    struct_span_err!(tcx.sess, span, E0393,
                                     "the type parameter `{}` must be explicitly specified",
                                     def.name)
                        .span_label(span, &format!("missing reference to `{}`", def.name))
                        .note(&format!("because of the default `Self` reference, \
                                        type parameters must be specified on object types"))
                        .emit();
                    tcx.types.err
                } else {
                    // This is a default type parameter.
                    default.subst_spanned(tcx, substs, Some(span))
                }
            } else {
                // We've already errored above about the mismatch.
                tcx.types.err
            }
        });
        let assoc_bindings = match *parameters {
            hir::AngleBracketedParameters(ref data) => {
                data.bindings.iter().map(|b| {
                    ConvertedBinding {
                        item_name: b.name,
                        ty: self.ast_ty_to_ty(rscope, &b.ty),
                        span: b.span
                    }
                }).collect()
            }
            hir::ParenthesizedParameters(ref data) => {
                vec![output_assoc_binding.unwrap_or_else(|| {
                    // This is an error condition, but we should
                    // get the associated type binding anyway.
                    self.convert_parenthesized_parameters(rscope, substs, data).1
                })]
            }
        };
        debug!("create_substs_for_ast_path(decl_generics={:?}, self_ty={:?}) -> {:?}",
               decl_generics, self_ty, substs);
        (substs, assoc_bindings)
    }
fn create_substs_for_ast_path ( & self , rscope : & RegionScope , span : Span , def_id : DefId , parameters : & hir :: PathParameters , self_ty : Option < Ty < ' tcx > > ) -> ( & ' tcx Substs < ' tcx > , Vec < ConvertedBinding < ' tcx > > ) { let tcx = self . tcx ( ) ; debug ! ( " \
 " def_id self_ty parameters ) ; let ( lifetimes , num_types_provided , infer_types ) = match * parameters { hir :: AngleBracketedParameters ( ref data ) => { ( & data . lifetimes [ .. ] , data . types . len ( ) , data . infer_types ) } hir :: ParenthesizedParameters ( _ ) => ( & [ ] [ .. ] , 1 , false ) } ; // If the type is parameterized by this region, then replace this // region with the current anon region binding (in other words, // whatever & would get replaced with). let decl_generics = match self . get_generics ( span , def_id ) { Ok ( generics ) => generics , Err ( ErrorReported ) => { // No convenient way to recover from a cycle here. Just bail. Sorry! self . tcx ( ) . sess . abort_if_errors ( ) ; bug ! ( " " ) } } ; let expected_num_region_params = decl_generics . regions . len ( ) ; let supplied_num_region_params = lifetimes . len ( ) ; let regions = if expected_num_region_params == supplied_num_region_params { lifetimes . iter ( ) . map ( | l | * ast_region_to_region ( tcx , l ) ) . collect ( ) } else { let anon_regions = rscope . anon_regions ( span , expected_num_region_params ) ; if supplied_num_region_params != 0 || anon_regions . is_err ( ) { report_lifetime_number_error ( tcx , span , supplied_num_region_params , expected_num_region_params ) ; } match anon_regions { Ok ( anon_regions ) => anon_regions , Err ( _ ) => ( 0 .. expected_num_region_params ) . map ( | _ | ty :: ReStatic ) . collect ( ) } } ; // If a self-type was declared, one should be provided. assert_eq ! ( decl_generics has_self self_ty is_some ( ) ) ; // Check the number of type parameters supplied by the user. let ty_param_defs = & decl_generics . types [ self_ty . is_some ( ) as usize .. ] ; if ! infer_types || num_types_provided > ty_param_defs . len ( ) { check_type_argument_count ( tcx , span , num_types_provided , ty_param_defs ) ; } let is_object = self_ty . map_or ( false , | ty | ty . sty == TRAIT_OBJECT_DUMMY_SELF ) ; let default_needs_object_self = | p : & ty :: TypeParameterDef < ' tcx > | { if let Some ( ref default ) = p . default { if is_object && default . has_self_ty ( ) { // There is no suitable inference default for a type parameter // that references self, in an object type. return true ; } } false } ; let mut output_assoc_binding = None ; let substs = Substs :: for_item ( tcx , def_id , | def , _ | { let i = def . index as usize - self_ty . is_some ( ) as usize ; tcx . mk_region ( regions [ i ] ) } , | def , substs | { let i = def . index as usize ; // Handle Self first, so we can adjust the index to match the AST. if let ( 0 , Some ( ty ) ) = ( i , self_ty ) { return ty ; } let i = i - self_ty . is_some ( ) as usize - decl_generics . regions . len ( ) ; if i < num_types_provided { // A provided type parameter. match * parameters { hir :: AngleBracketedParameters ( ref data ) => { self . ast_ty_arg_to_ty ( rscope , Some ( def ) , substs , & data . types [ i ] ) } hir :: ParenthesizedParameters ( ref data ) => { assert_eq ! ( i 0 ) ; let ( ty , assoc ) = self . convert_parenthesized_parameters ( rscope , substs , data ) ; output_assoc_binding = Some ( assoc ) ; ty } } } else if infer_types { // No type parameters were provided, we can infer all. let ty_var = if ! default_needs_object_self ( def ) { self . ty_infer_for_def ( def , substs , span ) } else { self . ty_infer ( span ) } ; ty_var } else if let Some ( default ) = def . default { // No type parameter provided, but a default exists. // If we are converting an object type, then the // `Self` parameter is unknown. However, some of the // other type parameters may reference `Self` in their // defaults. This will lead to an ICE if we are not // careful! if default_needs_object_self ( def ) { struct_span_err ! ( tcx sess span E0393 " " def name ) . span_label ( span , & format ! ( " " def name ) ) . note ( & format ! ( " \
 " ) ) . emit ( ) ; tcx . types . err } else { // This is a default type parameter. default . subst_spanned ( tcx , substs , Some ( span ) ) } } else { // We've already errored above about the mismatch. tcx . types . err } } ) ; let assoc_bindings = match * parameters { hir :: AngleBracketedParameters ( ref data ) => { data . bindings . iter ( ) . map ( | b | { ConvertedBinding { item_name : b . name , ty : self . ast_ty_to_ty ( rscope , & b . ty ) , span : b . span } } ) . collect ( ) } hir :: ParenthesizedParameters ( ref data ) => { vec ! [ output_assoc_binding unwrap_or_else ( { // This is an error condition, but we should // get the associated type binding anyway. self convert_parenthesized_parameters ( rscope substs data ) 1 } ) ] } } ; debug ! ( " " decl_generics self_ty substs ) ; ( substs , assoc_bindings ) }
Given the type/region arguments provided to some path (along with
an implicit Self, if this is a trait reference) returns the complete
set of substitutions.
Given the type / region arguments provided to some path ( along with an implicit Self if this is a trait reference ) returns the complete set of substitutions .
&self
rscope
&RegionScope
span
Span
def_id
DefId
parameters
&hir::PathParameters
self_ty
Option<Ty<'tcx>>