@@ -35,6 +35,8 @@ pub struct VisSpace(pub Option<ast::Visibility>);
35
35
pub struct FnStyleSpace ( pub ast:: FnStyle ) ;
36
36
/// Wrapper struct for properly emitting a method declaration.
37
37
pub struct Method < ' a > ( pub & ' a clean:: SelfTy , pub & ' a clean:: FnDecl ) ;
38
+ /// Similar to VisSpace, but used for mutability
39
+ pub struct MutableSpace ( pub clean:: Mutability ) ;
38
40
39
41
impl VisSpace {
40
42
pub fn get ( & self ) -> Option < ast:: Visibility > {
@@ -438,24 +440,14 @@ impl fmt::Show for clean::Type {
438
440
clean:: Unique ( ref t) => write ! ( f, "~{}" , * * t) ,
439
441
clean:: Managed ( ref t) => write ! ( f, "@{}" , * * t) ,
440
442
clean:: RawPointer ( m, ref t) => {
441
- write ! ( f, "*{}{}" ,
442
- match m {
443
- clean:: Mutable => "mut " ,
444
- clean:: Immutable => "" ,
445
- } , * * t)
443
+ write ! ( f, "*{}{}" , MutableSpace ( m) , * * t)
446
444
}
447
445
clean:: BorrowedRef { lifetime : ref l, mutability, type_ : ref ty} => {
448
446
let lt = match * l {
449
447
Some ( ref l) => format ! ( "{} " , * l) ,
450
448
_ => "" . to_string( ) ,
451
449
} ;
452
- write ! ( f, "&{}{}{}" ,
453
- lt,
454
- match mutability {
455
- clean:: Mutable => "mut " ,
456
- clean:: Immutable => "" ,
457
- } ,
458
- * * ty)
450
+ write ! ( f, "&{}{}{}" , lt, MutableSpace ( mutability) , * * ty)
459
451
}
460
452
}
461
453
}
@@ -494,17 +486,13 @@ impl<'a> fmt::Show for Method<'a> {
494
486
clean : : SelfStatic => { } ,
495
487
clean:: SelfValue => args. push_str( "self" ) ,
496
488
clean:: SelfOwned => args. push_str( "~self" ) ,
497
- clean:: SelfBorrowed ( Some ( ref lt) , clean:: Immutable ) => {
498
- args. push_str( format ! ( "&{} self" , * lt) . as_slice( ) ) ;
499
- }
500
- clean:: SelfBorrowed ( Some ( ref lt) , clean:: Mutable ) => {
501
- args. push_str( format ! ( "&{} mut self" , * lt) . as_slice( ) ) ;
502
- }
503
- clean:: SelfBorrowed ( None , clean:: Mutable ) => {
504
- args. push_str( "&mut self" ) ;
489
+ clean:: SelfBorrowed ( Some ( ref lt) , mtbl) => {
490
+ args. push_str( format ! ( "&{} {}self" , * lt,
491
+ MutableSpace ( mtbl) ) . as_slice( ) ) ;
505
492
}
506
- clean:: SelfBorrowed ( None , clean:: Immutable ) => {
507
- args. push_str( "&self" ) ;
493
+ clean:: SelfBorrowed ( None , mtbl) => {
494
+ args. push_str( format ! ( "&{}self" ,
495
+ MutableSpace ( mtbl) ) . as_slice( ) ) ;
508
496
}
509
497
}
510
498
for ( i, input) in d. inputs. values. iter( ) . enumerate( ) {
@@ -605,3 +593,12 @@ impl fmt::Show for clean::ViewListIdent {
605
593
}
606
594
}
607
595
}
596
+
597
+ impl fmt:: Show for MutableSpace {
598
+ fn fmt( & self , f: & mut fmt:: Formatter ) -> fmt:: Result {
599
+ match * self {
600
+ MutableSpace ( clean:: Immutable ) => Ok ( ( ) ) ,
601
+ MutableSpace ( clean:: Mutable ) => write ! ( f, "mut " ) ,
602
+ }
603
+ }
604
+ }
0 commit comments