@@ -100,10 +100,7 @@ impl<T: Clean<U>, U> Clean<U> for Rc<T> {
100
100
101
101
impl < T : Clean < U > , U > Clean < Option < U > > for Option < T > {
102
102
fn clean ( & self , cx : & DocContext ) -> Option < U > {
103
- match self {
104
- & None => None ,
105
- & Some ( ref v) => Some ( v. clean ( cx) )
106
- }
103
+ self . as_ref ( ) . map ( |v| v. clean ( cx) )
107
104
}
108
105
}
109
106
@@ -332,27 +329,20 @@ impl Item {
332
329
}
333
330
334
331
pub fn stability_class ( & self ) -> String {
335
- match self . stability {
336
- Some ( ref s) => {
337
- let mut base = match s. level {
338
- stability:: Unstable => "unstable" . to_string ( ) ,
339
- stability:: Stable => String :: new ( ) ,
340
- } ;
341
- if !s. deprecated_since . is_empty ( ) {
342
- base. push_str ( " deprecated" ) ;
343
- }
344
- base
332
+ self . stability . as_ref ( ) . map ( |ref s| {
333
+ let mut base = match s. level {
334
+ stability:: Unstable => "unstable" . to_string ( ) ,
335
+ stability:: Stable => String :: new ( ) ,
336
+ } ;
337
+ if !s. deprecated_since . is_empty ( ) {
338
+ base. push_str ( " deprecated" ) ;
345
339
}
346
- _ => String :: new ( ) ,
347
- }
340
+ base
341
+ } ) . unwrap_or ( String :: new ( ) )
348
342
}
349
343
350
344
pub fn stable_since ( & self ) -> Option < & str > {
351
- if let Some ( ref s) = self . stability {
352
- return Some ( & s. since [ ..] ) ;
353
- }
354
-
355
- None
345
+ self . stability . as_ref ( ) . map ( |s| & s. since [ ..] )
356
346
}
357
347
}
358
348
@@ -711,7 +701,7 @@ impl<'tcx> Clean<TyParamBound> for ty::TraitRef<'tcx> {
711
701
if let & ty:: Region :: ReLateBound ( _, _) = * reg {
712
702
debug ! ( " hit an ReLateBound {:?}" , reg) ;
713
703
if let Some ( lt) = reg. clean ( cx) {
714
- late_bounds. push ( lt)
704
+ late_bounds. push ( lt) ;
715
705
}
716
706
}
717
707
}
@@ -780,8 +770,7 @@ impl Clean<Option<Lifetime>> for ty::Region {
780
770
fn clean ( & self , cx : & DocContext ) -> Option < Lifetime > {
781
771
match * self {
782
772
ty:: ReStatic => Some ( Lifetime :: statik ( ) ) ,
783
- ty:: ReLateBound ( _, ty:: BrNamed ( _, name) ) =>
784
- Some ( Lifetime ( name. to_string ( ) ) ) ,
773
+ ty:: ReLateBound ( _, ty:: BrNamed ( _, name) ) => Some ( Lifetime ( name. to_string ( ) ) ) ,
785
774
ty:: ReEarlyBound ( ref data) => Some ( Lifetime ( data. name . clean ( cx) ) ) ,
786
775
787
776
ty:: ReLateBound ( ..) |
@@ -1151,12 +1140,12 @@ impl<'tcx> Clean<Type> for ty::FnOutput<'tcx> {
1151
1140
impl < ' a , ' tcx > Clean < FnDecl > for ( DefId , & ' a ty:: PolyFnSig < ' tcx > ) {
1152
1141
fn clean ( & self , cx : & DocContext ) -> FnDecl {
1153
1142
let ( did, sig) = * self ;
1154
- let mut names = if let Some ( _ ) = cx. map . as_local_node_id ( did) {
1143
+ let mut names = if cx. map . as_local_node_id ( did) . is_some ( ) {
1155
1144
vec ! [ ] . into_iter ( )
1156
1145
} else {
1157
1146
cx. tcx ( ) . sess . cstore . method_arg_names ( did) . into_iter ( )
1158
1147
} . peekable ( ) ;
1159
- if names. peek ( ) . map ( |s| & * * s ) == Some ( "self" ) {
1148
+ if let Some ( "self" ) = names. peek ( ) . map ( |s| & s [ .. ] ) {
1160
1149
let _ = names. next ( ) ;
1161
1150
}
1162
1151
FnDecl {
@@ -1627,15 +1616,9 @@ impl Clean<Type> for hir::Ty {
1627
1616
}
1628
1617
}
1629
1618
TyBareFn ( ref barefn) => BareFunction ( box barefn. clean ( cx) ) ,
1630
- TyPolyTraitRef ( ref bounds) => {
1631
- PolyTraitRef ( bounds. clean ( cx) )
1632
- } ,
1633
- TyInfer => {
1634
- Infer
1635
- } ,
1636
- TyTypeof ( ..) => {
1637
- panic ! ( "Unimplemented type {:?}" , self . node)
1638
- } ,
1619
+ TyPolyTraitRef ( ref bounds) => PolyTraitRef ( bounds. clean ( cx) ) ,
1620
+ TyInfer => Infer ,
1621
+ TyTypeof ( ..) => panic ! ( "Unimplemented type {:?}" , self . node) ,
1639
1622
}
1640
1623
}
1641
1624
}
@@ -2253,7 +2236,7 @@ impl Clean<Vec<Item>> for doctree::Impl {
2253
2236
polarity : Some ( self . polarity . clean ( cx) ) ,
2254
2237
} ) ,
2255
2238
} ) ;
2256
- return ret;
2239
+ ret
2257
2240
}
2258
2241
}
2259
2242
@@ -2393,9 +2376,8 @@ impl Clean<Vec<Item>> for doctree::Import {
2393
2376
}
2394
2377
hir:: ViewPathSimple ( name, ref p) => {
2395
2378
if !denied {
2396
- match inline:: try_inline ( cx, self . id , Some ( name) ) {
2397
- Some ( items) => return items,
2398
- None => { }
2379
+ if let Some ( items) = inline:: try_inline ( cx, self . id , Some ( name) ) {
2380
+ return items;
2399
2381
}
2400
2382
}
2401
2383
( vec ! [ ] , SimpleImport ( name. clean ( cx) ,
@@ -2460,9 +2442,8 @@ impl Clean<Vec<Item>> for hir::ForeignMod {
2460
2442
fn clean ( & self , cx : & DocContext ) -> Vec < Item > {
2461
2443
let mut items = self . items . clean ( cx) ;
2462
2444
for item in & mut items {
2463
- match item. inner {
2464
- ForeignFunctionItem ( ref mut f) => f. abi = self . abi ,
2465
- _ => { }
2445
+ if let ForeignFunctionItem ( ref mut f) = item. inner {
2446
+ f. abi = self . abi ;
2466
2447
}
2467
2448
}
2468
2449
items
@@ -2598,11 +2579,7 @@ fn resolve_type(cx: &DocContext,
2598
2579
} ;
2599
2580
}
2600
2581
} ;
2601
- let def = match tcx. def_map . borrow ( ) . get ( & id) {
2602
- Some ( k) => k. full_def ( ) ,
2603
- None => panic ! ( "unresolved id not in defmap" )
2604
- } ;
2605
-
2582
+ let def = tcx. def_map . borrow ( ) . get ( & id) . expect ( "unresolved id not in defmap" ) . full_def ( ) ;
2606
2583
debug ! ( "resolve_type: def={:?}" , def) ;
2607
2584
2608
2585
let is_generic = match def {
@@ -2659,7 +2636,7 @@ fn register_def(cx: &DocContext, def: Def) -> DefId {
2659
2636
let t = inline:: build_external_trait ( cx, tcx, did) ;
2660
2637
cx. external_traits . borrow_mut ( ) . as_mut ( ) . unwrap ( ) . insert ( did, t) ;
2661
2638
}
2662
- return did;
2639
+ did
2663
2640
}
2664
2641
2665
2642
fn resolve_use_source ( cx : & DocContext , path : Path , id : ast:: NodeId ) -> ImportSource {
@@ -2732,12 +2709,10 @@ impl Clean<Stability> for attr::Stability {
2732
2709
_=> "" . to_string ( ) ,
2733
2710
} ,
2734
2711
reason : {
2735
- if let Some ( ref depr) = self . rustc_depr {
2736
- depr. reason . to_string ( )
2737
- } else if let attr:: Unstable { reason : Some ( ref reason) , ..} = self . level {
2738
- reason. to_string ( )
2739
- } else {
2740
- "" . to_string ( )
2712
+ match ( & self . rustc_depr , & self . level ) {
2713
+ ( & Some ( ref depr) , _) => depr. reason . to_string ( ) ,
2714
+ ( & None , & attr:: Unstable { reason : Some ( ref reason) , ..} ) => reason. to_string ( ) ,
2715
+ _ => "" . to_string ( ) ,
2741
2716
}
2742
2717
} ,
2743
2718
issue : match self . level {
0 commit comments