@@ -21,9 +21,9 @@ use hir::def_id::DefId;
21
21
use middle:: free_region:: RegionRelations ;
22
22
use middle:: region;
23
23
use middle:: lang_items;
24
- use ty:: subst:: Substs ;
24
+ use ty:: subst:: { Kind , Substs } ;
25
25
use ty:: { TyVid , IntVid , FloatVid } ;
26
- use ty:: { self , Ty , TyCtxt } ;
26
+ use ty:: { self , Ty , TyCtxt , GenericParamDefKind } ;
27
27
use ty:: error:: { ExpectedFound , TypeError , UnconstrainedNumeric } ;
28
28
use ty:: fold:: TypeFoldable ;
29
29
use ty:: relate:: RelateResult ;
@@ -905,34 +905,35 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
905
905
self . next_region_var ( RegionVariableOrigin :: NLL ( origin) )
906
906
}
907
907
908
- /// Create a region inference variable for the given
909
- /// region parameter definition.
910
- pub fn region_var_for_def ( & self ,
911
- span : Span ,
912
- def : & ty:: RegionParameterDef )
913
- -> ty:: Region < ' tcx > {
914
- self . next_region_var ( EarlyBoundRegion ( span, def. name ) )
915
- }
916
-
917
- /// Create a type inference variable for the given
918
- /// type parameter definition. The substitutions are
919
- /// for actual parameters that may be referred to by
920
- /// the default of this type parameter, if it exists.
921
- /// E.g. `struct Foo<A, B, C = (A, B)>(...);` when
922
- /// used in a path such as `Foo::<T, U>::new()` will
923
- /// use an inference variable for `C` with `[T, U]`
924
- /// as the substitutions for the default, `(T, U)`.
925
- pub fn type_var_for_def ( & self ,
926
- span : Span ,
927
- def : & ty:: TypeParameterDef )
928
- -> Ty < ' tcx > {
929
- let ty_var_id = self . type_variables
930
- . borrow_mut ( )
931
- . new_var ( self . universe ( ) ,
932
- false ,
933
- TypeVariableOrigin :: TypeParameterDefinition ( span, def. name ) ) ;
934
-
935
- self . tcx . mk_var ( ty_var_id)
908
+ pub fn var_for_def ( & self ,
909
+ span : Span ,
910
+ param : & ty:: GenericParamDef )
911
+ -> Kind < ' tcx > {
912
+ match param. kind {
913
+ GenericParamDefKind :: Lifetime => {
914
+ // Create a region inference variable for the given
915
+ // region parameter definition.
916
+ self . next_region_var ( EarlyBoundRegion ( span, param. name ) ) . into ( )
917
+ }
918
+ GenericParamDefKind :: Type ( _) => {
919
+ // Create a type inference variable for the given
920
+ // type parameter definition. The substitutions are
921
+ // for actual parameters that may be referred to by
922
+ // the default of this type parameter, if it exists.
923
+ // E.g. `struct Foo<A, B, C = (A, B)>(...);` when
924
+ // used in a path such as `Foo::<T, U>::new()` will
925
+ // use an inference variable for `C` with `[T, U]`
926
+ // as the substitutions for the default, `(T, U)`.
927
+ let ty_var_id =
928
+ self . type_variables
929
+ . borrow_mut ( )
930
+ . new_var ( self . universe ( ) ,
931
+ false ,
932
+ TypeVariableOrigin :: TypeParameterDefinition ( span, param. name ) ) ;
933
+
934
+ self . tcx . mk_var ( ty_var_id) . into ( )
935
+ }
936
+ }
936
937
}
937
938
938
939
/// Given a set of generics defined on a type or impl, returns a substitution mapping each
@@ -941,10 +942,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
941
942
span : Span ,
942
943
def_id : DefId )
943
944
-> & ' tcx Substs < ' tcx > {
944
- Substs :: for_item ( self . tcx , def_id, |def, _| {
945
- self . region_var_for_def ( span, def)
946
- } , |def, _| {
947
- self . type_var_for_def ( span, def)
945
+ Substs :: for_item ( self . tcx , def_id, |param, _| {
946
+ self . var_for_def ( span, param)
948
947
} )
949
948
}
950
949
0 commit comments