@@ -1661,35 +1661,30 @@ fn ty_generics_for_type(ccx: &CrateCtxt,
16611661fn ty_generics_for_trait ( ccx : & CrateCtxt ,
16621662 trait_id : ast:: NodeId ,
16631663 substs : & subst:: Substs ,
1664- generics : & ast:: Generics ,
1664+ ast_generics : & ast:: Generics ,
16651665 items : & [ ast:: TraitItem ] )
16661666 -> ty:: Generics {
16671667 let mut generics =
16681668 ty_generics ( ccx,
16691669 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 ( ) ,
16721672 ty:: Generics :: empty ( ) ,
1673- & generics . where_clause ,
1673+ & ast_generics . where_clause ,
16741674 DontCreateTypeParametersForAssociatedTypes ) ;
16751675
16761676 // Add in type parameters for any associated types.
16771677 for item in items. iter ( ) {
16781678 match * item {
16791679 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) ) ) ;
16931688 ccx. tcx . ty_param_defs . borrow_mut ( ) . insert ( associated_type. ty_param . id ,
16941689 def. clone ( ) ) ;
16951690 generics. types . push ( subst:: TypeSpace , def) ;
@@ -1960,7 +1955,8 @@ fn ty_generics<'tcx,AC>(this: &AC,
19601955 space,
19611956 param,
19621957 i,
1963- where_clause) ;
1958+ where_clause,
1959+ None ) ;
19641960 debug ! ( "ty_generics: def for type param: {}, {}" ,
19651961 def. repr( this. tcx( ) ) ,
19661962 space) ;
@@ -1980,63 +1976,64 @@ fn ty_generics<'tcx,AC>(this: &AC,
19801976 }
19811977
19821978 return result;
1979+ }
19831980
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 {
20142012 span_err ! ( this. tcx( ) . sess, path. span, E0128 ,
20152013 "type parameters with a default cannot use \
20162014 forward declared identifiers") ;
20172015 } ,
20182016 _ => { }
20192017 }
2020- } ) ;
2018+ } ) ;
20212019
2022- Some ( ty)
2023- }
2024- } ;
2020+ Some ( ty)
2021+ }
2022+ } ;
20252023
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+ } ;
20352033
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 ( ) ) ;
20372035
2038- def
2039- }
2036+ def
20402037}
20412038
20422039fn compute_bounds < ' tcx , AC > ( this : & AC ,
0 commit comments