@@ -1661,35 +1661,30 @@ fn ty_generics_for_type(ccx: &CrateCtxt,
1661
1661
fn ty_generics_for_trait ( ccx : & CrateCtxt ,
1662
1662
trait_id : ast:: NodeId ,
1663
1663
substs : & subst:: Substs ,
1664
- generics : & ast:: Generics ,
1664
+ ast_generics : & ast:: Generics ,
1665
1665
items : & [ ast:: TraitItem ] )
1666
1666
-> ty:: Generics {
1667
1667
let mut generics =
1668
1668
ty_generics ( ccx,
1669
1669
subst:: TypeSpace ,
1670
- generics . lifetimes . as_slice ( ) ,
1671
- generics . ty_params . as_slice ( ) ,
1670
+ ast_generics . lifetimes . as_slice ( ) ,
1671
+ ast_generics . ty_params . as_slice ( ) ,
1672
1672
ty:: Generics :: empty ( ) ,
1673
- & generics . where_clause ,
1673
+ & ast_generics . where_clause ,
1674
1674
DontCreateTypeParametersForAssociatedTypes ) ;
1675
1675
1676
1676
// Add in type parameters for any associated types.
1677
1677
for item in items. iter ( ) {
1678
1678
match * item {
1679
1679
ast:: TypeTraitItem ( ref associated_type) => {
1680
- let def = ty:: TypeParameterDef {
1681
- space : subst:: TypeSpace ,
1682
- index : generics. types . len ( subst:: TypeSpace ) ,
1683
- name : associated_type. ty_param . ident . name ,
1684
- def_id : local_def ( associated_type. ty_param . id ) ,
1685
- bounds : ty:: ParamBounds {
1686
- builtin_bounds : ty:: empty_builtin_bounds ( ) ,
1687
- trait_bounds : Vec :: new ( ) ,
1688
- region_bounds : Vec :: new ( ) ,
1689
- } ,
1690
- associated_with : Some ( local_def ( trait_id) ) ,
1691
- default : None ,
1692
- } ;
1680
+ let def =
1681
+ get_or_create_type_parameter_def (
1682
+ ccx,
1683
+ subst:: TypeSpace ,
1684
+ & associated_type. ty_param ,
1685
+ generics. types . len ( subst:: TypeSpace ) ,
1686
+ & ast_generics. where_clause ,
1687
+ Some ( local_def ( trait_id) ) ) ;
1693
1688
ccx. tcx . ty_param_defs . borrow_mut ( ) . insert ( associated_type. ty_param . id ,
1694
1689
def. clone ( ) ) ;
1695
1690
generics. types . push ( subst:: TypeSpace , def) ;
@@ -1960,7 +1955,8 @@ fn ty_generics<'tcx,AC>(this: &AC,
1960
1955
space,
1961
1956
param,
1962
1957
i,
1963
- where_clause) ;
1958
+ where_clause,
1959
+ None ) ;
1964
1960
debug ! ( "ty_generics: def for type param: {}, {}" ,
1965
1961
def. repr( this. tcx( ) ) ,
1966
1962
space) ;
@@ -1980,63 +1976,64 @@ fn ty_generics<'tcx,AC>(this: &AC,
1980
1976
}
1981
1977
1982
1978
return result;
1979
+ }
1983
1980
1984
- fn get_or_create_type_parameter_def < ' tcx , AC > (
1985
- this : & AC ,
1986
- space : subst:: ParamSpace ,
1987
- param : & ast:: TyParam ,
1988
- index : uint ,
1989
- where_clause : & ast:: WhereClause )
1990
- -> ty:: TypeParameterDef
1991
- where AC : AstConv < ' tcx > {
1992
- match this. tcx ( ) . ty_param_defs . borrow ( ) . find ( & param. id ) {
1993
- Some ( d) => { return ( * d) . clone ( ) ; }
1994
- None => { }
1995
- }
1996
-
1997
- let param_ty = ty:: ParamTy :: new ( space, index, local_def ( param. id ) ) ;
1998
- let bounds = compute_bounds ( this,
1999
- param. ident . name ,
2000
- param_ty,
2001
- param. bounds . as_slice ( ) ,
2002
- & param. unbound ,
2003
- param. span ,
2004
- where_clause) ;
2005
- let default = match param. default {
2006
- None => None ,
2007
- Some ( ref path) => {
2008
- let ty = ast_ty_to_ty ( this, & ExplicitRscope , & * * path) ;
2009
- let cur_idx = index;
2010
-
2011
- ty:: walk_ty ( ty, |t| {
2012
- match ty:: get ( t) . sty {
2013
- ty:: ty_param( p) => if p. idx > cur_idx {
1981
+ fn get_or_create_type_parameter_def < ' tcx , AC > ( this : & AC ,
1982
+ space : subst:: ParamSpace ,
1983
+ param : & ast:: TyParam ,
1984
+ index : uint ,
1985
+ where_clause : & ast:: WhereClause ,
1986
+ associated_with : Option < ast:: DefId > )
1987
+ -> ty:: TypeParameterDef
1988
+ where AC : AstConv < ' tcx >
1989
+ {
1990
+ match this. tcx ( ) . ty_param_defs . borrow ( ) . find ( & param. id ) {
1991
+ Some ( d) => { return ( * d) . clone ( ) ; }
1992
+ None => { }
1993
+ }
1994
+
1995
+ let param_ty = ty:: ParamTy :: new ( space, index, local_def ( param. id ) ) ;
1996
+ let bounds = compute_bounds ( this,
1997
+ param. ident . name ,
1998
+ param_ty,
1999
+ param. bounds . as_slice ( ) ,
2000
+ & param. unbound ,
2001
+ param. span ,
2002
+ where_clause) ;
2003
+ let default = match param. default {
2004
+ None => None ,
2005
+ Some ( ref path) => {
2006
+ let ty = ast_ty_to_ty ( this, & ExplicitRscope , & * * path) ;
2007
+ let cur_idx = index;
2008
+
2009
+ ty:: walk_ty ( ty, |t| {
2010
+ match ty:: get ( t) . sty {
2011
+ ty:: ty_param( p) => if p. idx > cur_idx {
2014
2012
span_err ! ( this. tcx( ) . sess, path. span, E0128 ,
2015
2013
"type parameters with a default cannot use \
2016
2014
forward declared identifiers") ;
2017
2015
} ,
2018
2016
_ => { }
2019
2017
}
2020
- } ) ;
2018
+ } ) ;
2021
2019
2022
- Some ( ty)
2023
- }
2024
- } ;
2020
+ Some ( ty)
2021
+ }
2022
+ } ;
2025
2023
2026
- let def = ty:: TypeParameterDef {
2027
- space : space,
2028
- index : index,
2029
- name : param. ident . name ,
2030
- def_id : local_def ( param. id ) ,
2031
- associated_with : None ,
2032
- bounds : bounds,
2033
- default : default
2034
- } ;
2024
+ let def = ty:: TypeParameterDef {
2025
+ space : space,
2026
+ index : index,
2027
+ name : param. ident . name ,
2028
+ def_id : local_def ( param. id ) ,
2029
+ associated_with : associated_with ,
2030
+ bounds : bounds,
2031
+ default : default
2032
+ } ;
2035
2033
2036
- this. tcx ( ) . ty_param_defs . borrow_mut ( ) . insert ( param. id , def. clone ( ) ) ;
2034
+ this. tcx ( ) . ty_param_defs . borrow_mut ( ) . insert ( param. id , def. clone ( ) ) ;
2037
2035
2038
- def
2039
- }
2036
+ def
2040
2037
}
2041
2038
2042
2039
fn compute_bounds < ' tcx , AC > ( this : & AC ,
0 commit comments