@@ -1746,7 +1746,11 @@ impl<'a, 'gcx, 'tcx> AstConv<'gcx, 'tcx> for FnCtxt<'a, 'gcx, 'tcx> {
1746
1746
fn ty_infer_for_def ( & self ,
1747
1747
ty_param_def : & ty:: GenericParamDef ,
1748
1748
span : Span ) -> Ty < ' tcx > {
1749
- self . type_var_for_def ( span, ty_param_def)
1749
+ if let UnpackedKind :: Type ( ty) = self . var_for_def ( span, ty_param_def) {
1750
+ ty
1751
+ } else {
1752
+ unreachable ! ( )
1753
+ }
1750
1754
}
1751
1755
1752
1756
fn projected_ty_from_poly_trait_ref ( & self ,
@@ -4759,17 +4763,26 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
4759
4763
( None , None ) => ( 0 , false )
4760
4764
} ;
4761
4765
let substs = Substs :: for_item ( self . tcx , def. def_id ( ) , |param, substs| {
4766
+ let mut i = param. index as usize ;
4767
+
4768
+ let segment = if i < fn_start {
4769
+ if let GenericParamDefKind :: Type ( _) = param. kind {
4770
+ // Handle Self first, so we can adjust the index to match the AST.
4771
+ if has_self && i == 0 {
4772
+ return opt_self_ty. map ( |ty| UnpackedKind :: Type ( ty) ) . unwrap_or_else ( || {
4773
+ self . var_for_def ( span, param)
4774
+ } ) ;
4775
+ }
4776
+ }
4777
+ i -= has_self as usize ;
4778
+ type_segment
4779
+ } else {
4780
+ i -= fn_start;
4781
+ fn_segment
4782
+ } ;
4783
+
4762
4784
match param. kind {
4763
4785
GenericParamDefKind :: Lifetime => {
4764
- let mut i = param. index as usize ;
4765
-
4766
- let segment = if i < fn_start {
4767
- i -= has_self as usize ;
4768
- type_segment
4769
- } else {
4770
- i -= fn_start;
4771
- fn_segment
4772
- } ;
4773
4786
let lifetimes = segment. map_or ( & [ ] [ ..] , |( s, _) | {
4774
4787
s. parameters . as_ref ( ) . map_or ( & [ ] [ ..] , |p| & p. lifetimes [ ..] )
4775
4788
} ) ;
@@ -4782,21 +4795,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
4782
4795
UnpackedKind :: Lifetime ( lt)
4783
4796
}
4784
4797
GenericParamDefKind :: Type ( _) => {
4785
- let mut i = param. index as usize ;
4786
-
4787
- let segment = if i < fn_start {
4788
- // Handle Self first, so we can adjust the index to match the AST.
4789
- if has_self && i == 0 {
4790
- return UnpackedKind :: Type ( opt_self_ty. unwrap_or_else ( || {
4791
- self . type_var_for_def ( span, param)
4792
- } ) ) ;
4793
- }
4794
- i -= has_self as usize ;
4795
- type_segment
4796
- } else {
4797
- i -= fn_start;
4798
- fn_segment
4799
- } ;
4800
4798
let ( types, infer_types) = segment. map_or ( ( & [ ] [ ..] , true ) , |( s, _) | {
4801
4799
( s. parameters . as_ref ( ) . map_or ( & [ ] [ ..] , |p| & p. types [ ..] ) , s. infer_types )
4802
4800
} ) ;
@@ -4811,24 +4809,23 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
4811
4809
_ => unreachable ! ( )
4812
4810
} ;
4813
4811
4814
- let ty = if let Some ( ast_ty) = types. get ( i) {
4812
+ if let Some ( ast_ty) = types. get ( i) {
4815
4813
// A provided type parameter.
4816
- self . to_ty ( ast_ty)
4814
+ UnpackedKind :: Type ( self . to_ty ( ast_ty) )
4817
4815
} else if !infer_types && has_default {
4818
4816
// No type parameter provided, but a default exists.
4819
4817
let default = self . tcx . type_of ( param. def_id ) ;
4820
- self . normalize_ty (
4818
+ UnpackedKind :: Type ( self . normalize_ty (
4821
4819
span,
4822
4820
default. subst_spanned ( self . tcx , substs, Some ( span) )
4823
- )
4821
+ ) )
4824
4822
} else {
4825
4823
// No type parameters were provided, we can infer all.
4826
4824
// This can also be reached in some error cases:
4827
4825
// We prefer to use inference variables instead of
4828
4826
// TyError to let type inference recover somewhat.
4829
- self . type_var_for_def ( span, param)
4830
- } ;
4831
- UnpackedKind :: Type ( ty)
4827
+ self . var_for_def ( span, param)
4828
+ }
4832
4829
}
4833
4830
}
4834
4831
} ) ;
0 commit comments