@@ -21,7 +21,7 @@ use rustc::hir::{self, GenericArg, HirVec};
21
21
use rustc:: hir:: def:: { self , Def , CtorKind } ;
22
22
use rustc:: hir:: def_id:: { CrateNum , DefId , CRATE_DEF_INDEX , LOCAL_CRATE } ;
23
23
use rustc:: hir:: map:: DisambiguatedDefPathData ;
24
- use rustc:: ty:: subst:: { Kind , InternalSubsts , SubstsRef } ;
24
+ use rustc:: ty:: subst:: { Kind , InternalSubsts , SubstsRef , UnpackedKind } ;
25
25
use rustc:: ty:: { self , DefIdTree , TyCtxt , Region , RegionVid , Ty , AdtKind } ;
26
26
use rustc:: ty:: fold:: TypeFolder ;
27
27
use rustc:: ty:: layout:: VariantIdx ;
@@ -1089,42 +1089,48 @@ impl Clean<GenericBound> for hir::GenericBound {
1089
1089
}
1090
1090
}
1091
1091
1092
- fn external_generic_args ( cx : & DocContext < ' _ > , trait_did : Option < DefId > , has_self : bool ,
1093
- bindings : Vec < TypeBinding > , substs : SubstsRef < ' _ > ) -> GenericArgs {
1094
- let lifetimes = substs. regions ( ) . filter_map ( |v| v. clean ( cx) ) . collect ( ) ;
1095
- let types = substs. types ( ) . skip ( has_self as usize ) . collect :: < Vec < _ > > ( ) ;
1092
+ fn external_generic_args (
1093
+ cx : & DocContext < ' _ > ,
1094
+ trait_did : Option < DefId > ,
1095
+ has_self : bool ,
1096
+ bindings : Vec < TypeBinding > ,
1097
+ substs : SubstsRef < ' _ > ,
1098
+ ) -> GenericArgs {
1099
+ let mut skip_self = has_self;
1100
+ let mut first_ty_sty = None ;
1101
+ let args: Vec < _ > = substs. iter ( ) . filter_map ( |kind| match kind. unpack ( ) {
1102
+ UnpackedKind :: Lifetime ( lt) => {
1103
+ lt. clean ( cx) . and_then ( |lt| Some ( GenericArg :: Lifetime ( lt) ) )
1104
+ }
1105
+ UnpackedKind :: Type ( _) if skip_self => {
1106
+ skip_self = false ;
1107
+ None
1108
+ }
1109
+ UnpackedKind :: Type ( ty) => {
1110
+ first_ty_sty = Some ( & ty. sty ) ;
1111
+ Some ( GenericArg :: Type ( ty. clean ( cx) ) )
1112
+ }
1113
+ UnpackedKind :: Const ( ct) => Some ( GenericArg :: Const ( ct. clean ( cx) ) ) ,
1114
+ } ) . collect ( ) ;
1096
1115
1097
1116
match trait_did {
1098
1117
// Attempt to sugar an external path like Fn<(A, B,), C> to Fn(A, B) -> C
1099
1118
Some ( did) if cx. tcx . lang_items ( ) . fn_trait_kind ( did) . is_some ( ) => {
1100
- assert_eq ! ( types. len( ) , 1 ) ;
1101
- let inputs = match types[ 0 ] . sty {
1102
- ty:: Tuple ( ref tys) => tys. iter ( ) . map ( |t| t. clean ( cx) ) . collect ( ) ,
1103
- _ => {
1104
- return GenericArgs :: AngleBracketed {
1105
- lifetimes,
1106
- types : types. clean ( cx) ,
1107
- bindings,
1108
- }
1109
- }
1119
+ assert ! ( first_ty_sty. is_some( ) ) ;
1120
+ let inputs = match first_ty_sty {
1121
+ Some ( ty:: Tuple ( ref tys) ) => tys. iter ( ) . map ( |t| t. clean ( cx) ) . collect ( ) ,
1122
+ _ => return GenericArgs :: AngleBracketed { args, bindings } ,
1110
1123
} ;
1111
1124
let output = None ;
1112
1125
// FIXME(#20299) return type comes from a projection now
1113
1126
// match types[1].sty {
1114
1127
// ty::Tuple(ref v) if v.is_empty() => None, // -> ()
1115
1128
// _ => Some(types[1].clean(cx))
1116
1129
// };
1117
- GenericArgs :: Parenthesized {
1118
- inputs,
1119
- output,
1120
- }
1130
+ GenericArgs :: Parenthesized { inputs, output }
1121
1131
} ,
1122
1132
_ => {
1123
- GenericArgs :: AngleBracketed {
1124
- lifetimes,
1125
- types : types. clean ( cx) ,
1126
- bindings,
1127
- }
1133
+ GenericArgs :: AngleBracketed { args, bindings }
1128
1134
}
1129
1135
}
1130
1136
}
@@ -1462,7 +1468,7 @@ impl GenericParamDef {
1462
1468
}
1463
1469
}
1464
1470
1465
- impl < ' tcx > Clean < GenericParamDef > for ty:: GenericParamDef {
1471
+ impl Clean < GenericParamDef > for ty:: GenericParamDef {
1466
1472
fn clean ( & self , cx : & DocContext < ' _ > ) -> GenericParamDef {
1467
1473
let ( name, kind) = match self . kind {
1468
1474
ty:: GenericParamDefKind :: Lifetime => {
@@ -1484,7 +1490,10 @@ impl<'tcx> Clean<GenericParamDef> for ty::GenericParamDef {
1484
1490
} )
1485
1491
}
1486
1492
ty:: GenericParamDefKind :: Const { .. } => {
1487
- unimplemented ! ( ) // FIXME(const_generics)
1493
+ ( self . name . clean ( cx) , GenericParamDefKind :: Const {
1494
+ did : self . def_id ,
1495
+ ty : cx. tcx . type_of ( self . def_id ) . clean ( cx) ,
1496
+ } )
1488
1497
}
1489
1498
} ;
1490
1499
@@ -1685,9 +1694,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics,
1685
1694
. flat_map ( |param| match param. kind {
1686
1695
ty:: GenericParamDefKind :: Lifetime => Some ( param. clean ( cx) ) ,
1687
1696
ty:: GenericParamDefKind :: Type { .. } => None ,
1688
- ty:: GenericParamDefKind :: Const { .. } => {
1689
- unimplemented ! ( ) // FIXME(const_generics)
1690
- }
1697
+ ty:: GenericParamDefKind :: Const { .. } => Some ( param. clean ( cx) ) ,
1691
1698
} ) . chain ( simplify:: ty_params ( stripped_typarams) . into_iter ( ) )
1692
1699
. collect ( ) ,
1693
1700
where_predicates : simplify:: where_clauses ( cx, where_predicates) ,
@@ -2365,12 +2372,15 @@ impl Type {
2365
2372
}
2366
2373
}
2367
2374
2368
- pub fn generics ( & self ) -> Option < & [ Type ] > {
2375
+ pub fn generics ( & self ) -> Option < Vec < Type > > {
2369
2376
match * self {
2370
2377
ResolvedPath { ref path, .. } => {
2371
2378
path. segments . last ( ) . and_then ( |seg| {
2372
- if let GenericArgs :: AngleBracketed { ref types, .. } = seg. args {
2373
- Some ( & * * types)
2379
+ if let GenericArgs :: AngleBracketed { ref args, .. } = seg. args {
2380
+ Some ( args. iter ( ) . filter_map ( |arg| match arg {
2381
+ GenericArg :: Type ( ty) => Some ( ty. clone ( ) ) ,
2382
+ _ => None ,
2383
+ } ) . collect ( ) )
2374
2384
} else {
2375
2385
None
2376
2386
}
@@ -3267,8 +3277,7 @@ impl fmt::Display for GenericArg {
3267
3277
#[ derive( Clone , RustcEncodable , RustcDecodable , PartialEq , Eq , Debug , Hash ) ]
3268
3278
pub enum GenericArgs {
3269
3279
AngleBracketed {
3270
- lifetimes : Vec < Lifetime > ,
3271
- types : Vec < Type > ,
3280
+ args : Vec < GenericArg > ,
3272
3281
bindings : Vec < TypeBinding > ,
3273
3282
} ,
3274
3283
Parenthesized {
@@ -3286,27 +3295,19 @@ impl Clean<GenericArgs> for hir::GenericArgs {
3286
3295
output : if output != Type :: Tuple ( Vec :: new ( ) ) { Some ( output) } else { None }
3287
3296
}
3288
3297
} else {
3289
- let ( mut lifetimes, mut types) = ( vec ! [ ] , vec ! [ ] ) ;
3290
- let mut elided_lifetimes = true ;
3291
- for arg in & self . args {
3292
- match arg {
3293
- GenericArg :: Lifetime ( lt) => {
3294
- if !lt. is_elided ( ) {
3295
- elided_lifetimes = false ;
3296
- }
3297
- lifetimes. push ( lt. clean ( cx) ) ;
3298
- }
3299
- GenericArg :: Type ( ty) => {
3300
- types. push ( ty. clean ( cx) ) ;
3301
- }
3302
- GenericArg :: Const ( ..) => {
3303
- unimplemented ! ( ) // FIXME(const_generics)
3304
- }
3305
- }
3306
- }
3298
+ let elide_lifetimes = self . args . iter ( ) . all ( |arg| match arg {
3299
+ hir:: GenericArg :: Lifetime ( lt) => lt. is_elided ( ) ,
3300
+ _ => true ,
3301
+ } ) ;
3307
3302
GenericArgs :: AngleBracketed {
3308
- lifetimes : if elided_lifetimes { vec ! [ ] } else { lifetimes } ,
3309
- types,
3303
+ args : self . args . iter ( ) . filter_map ( |arg| match arg {
3304
+ hir:: GenericArg :: Lifetime ( lt) if !elide_lifetimes => {
3305
+ Some ( GenericArg :: Lifetime ( lt. clean ( cx) ) )
3306
+ }
3307
+ hir:: GenericArg :: Lifetime ( _) => None ,
3308
+ hir:: GenericArg :: Type ( ty) => Some ( GenericArg :: Type ( ty. clean ( cx) ) ) ,
3309
+ hir:: GenericArg :: Const ( ct) => Some ( GenericArg :: Const ( ct. clean ( cx) ) ) ,
3310
+ } ) . collect ( ) ,
3310
3311
bindings : self . bindings . clean ( cx) ,
3311
3312
}
3312
3313
}
@@ -3358,9 +3359,8 @@ fn strip_path(path: &Path) -> Path {
3358
3359
PathSegment {
3359
3360
name : s. name . clone ( ) ,
3360
3361
args : GenericArgs :: AngleBracketed {
3361
- lifetimes : Vec :: new ( ) ,
3362
- types : Vec :: new ( ) ,
3363
- bindings : Vec :: new ( ) ,
3362
+ args : vec ! [ ] ,
3363
+ bindings : vec ! [ ] ,
3364
3364
}
3365
3365
}
3366
3366
} ) . collect ( ) ;
@@ -3511,7 +3511,7 @@ impl Clean<Item> for doctree::Static {
3511
3511
}
3512
3512
}
3513
3513
3514
- #[ derive( Clone , RustcEncodable , RustcDecodable , Debug ) ]
3514
+ #[ derive( Clone , PartialEq , Eq , Hash , RustcEncodable , RustcDecodable , Debug ) ]
3515
3515
pub struct Constant {
3516
3516
pub type_ : Type ,
3517
3517
pub expr : String ,
0 commit comments