1
1
use std:: fmt;
2
2
use std:: rc:: Rc ;
3
3
4
- use rustc_ast_pretty:: pprust:: ty_to_string;
5
4
use rustc_ast:: ast;
5
+ use rustc_ast_pretty:: pprust:: ty_to_string;
6
6
use rustc_span:: symbol;
7
7
8
8
use crate :: module:: path:: ModulePath ;
@@ -15,77 +15,123 @@ use crate::Config;
15
15
pub struct Enum < ' a > {
16
16
pub path : Rc < ModulePath > ,
17
17
pub span : rustc_span:: Span ,
18
-
18
+
19
19
/// Visibility
20
20
pub vis : & ' a ast:: VisibilityKind ,
21
21
pub name : symbol:: Symbol ,
22
22
pub params : Vec < symbol:: Symbol > ,
23
23
pub variants : Vec < ( symbol:: Symbol , Vec < String > ) > ,
24
24
}
25
25
26
- impl < ' a > PartialEq for Enum < ' a > {
26
+ impl < ' a > PartialEq for Enum < ' a > {
27
27
fn eq ( & self , b : & Self ) -> bool {
28
-
29
28
let a = self ;
30
29
31
30
use ast:: VisibilityKind :: * ;
32
31
33
32
let bvis = match ( a. vis , b. vis ) {
34
33
( Public , Public ) => true ,
35
34
( Crate ( _) , Crate ( _) ) => true ,
36
- ( Restricted { .. } , Restricted { .. } ) => true ,
35
+ ( Restricted { .. } , Restricted { .. } ) => true ,
37
36
( Inherited , Inherited ) => true ,
38
37
_ => false ,
39
38
} ;
40
39
41
- a. path == b. path &&
42
- a. name == b. name &&
43
- a. span == b. span &&
44
- a. params == b. params &&
45
- a. variants == b. variants &&
46
- bvis
40
+ a. path == b. path
41
+ && a. name == b. name
42
+ && a. span == b. span
43
+ && a. params == b. params
44
+ && a. variants == b. variants
45
+ && bvis
47
46
}
48
47
}
49
48
50
- impl < ' a > Eq for Enum < ' a > { }
49
+ impl < ' a > Eq for Enum < ' a > { }
51
50
52
-
53
- impl < ' a > From < ( ( & ' a ast:: Item , & ' a Vec < ast:: GenericParam > , & ' a Vec < ast:: Variant > ) , Rc < ModulePath > ) > for Enum < ' a > {
54
- fn from ( ( ( item, params, variants) , path) : ( ( & ' a ast:: Item , & ' a Vec < ast:: GenericParam > , & ' a Vec < ast:: Variant > ) , Rc < ModulePath > ) ) -> Enum < ' a > {
51
+ impl < ' a >
52
+ From < (
53
+ (
54
+ & ' a ast:: Item ,
55
+ & ' a Vec < ast:: GenericParam > ,
56
+ & ' a Vec < ast:: Variant > ,
57
+ ) ,
58
+ Rc < ModulePath > ,
59
+ ) > for Enum < ' a >
60
+ {
61
+ fn from (
62
+ ( ( item, params, variants) , path) : (
63
+ (
64
+ & ' a ast:: Item ,
65
+ & ' a Vec < ast:: GenericParam > ,
66
+ & ' a Vec < ast:: Variant > ,
67
+ ) ,
68
+ Rc < ModulePath > ,
69
+ ) ,
70
+ ) -> Enum < ' a > {
55
71
Enum {
56
72
path : path,
57
73
vis : & item. vis . kind ,
58
74
name : item. ident . name ,
59
75
span : item. span ,
60
- params : params. iter ( )
61
- . map ( |& ast:: GenericParam { attrs : _, ident : symbol:: Ident { name, ..} , ..} | name)
62
- . collect :: < Vec < symbol:: Symbol > > ( ) ,
63
- variants : variants. iter ( )
64
- . map ( |& ast:: Variant { ident : symbol:: Ident { name, ..} , attrs : _, ref data, ..} | {
65
- if let & ast:: VariantData :: Tuple ( ref struct_field, _) = data {
66
- ( name,
67
- struct_field. iter ( )
68
- . filter_map ( |& ast:: FieldDef { span : _, ident : _, vis : _, id : _, ref ty, .. } | Some ( ty_to_string ( & ty) ) )
69
- . collect :: < Vec < String > > ( ) )
70
- } else {
71
- ( name, Vec :: new ( ) )
72
- }
73
- } )
74
- . collect :: < Vec < ( symbol:: Symbol , Vec < String > ) > > ( ) ,
76
+ params : params
77
+ . iter ( )
78
+ . map (
79
+ |& ast:: GenericParam {
80
+ attrs : _,
81
+ ident : symbol:: Ident { name, .. } ,
82
+ ..
83
+ } | name,
84
+ )
85
+ . collect :: < Vec < symbol:: Symbol > > ( ) ,
86
+ variants : variants
87
+ . iter ( )
88
+ . map (
89
+ |& ast:: Variant {
90
+ ident : symbol:: Ident { name, .. } ,
91
+ attrs : _,
92
+ ref data,
93
+ ..
94
+ } | {
95
+ if let & ast:: VariantData :: Tuple ( ref struct_field, _) = data {
96
+ (
97
+ name,
98
+ struct_field
99
+ . iter ( )
100
+ . filter_map (
101
+ |& ast:: FieldDef {
102
+ span : _,
103
+ ident : _,
104
+ vis : _,
105
+ id : _,
106
+ ref ty,
107
+ ..
108
+ } | {
109
+ Some ( ty_to_string ( & ty) )
110
+ } ,
111
+ )
112
+ . collect :: < Vec < String > > ( ) ,
113
+ )
114
+ } else {
115
+ ( name, Vec :: new ( ) )
116
+ }
117
+ } ,
118
+ )
119
+ . collect :: < Vec < ( symbol:: Symbol , Vec < String > ) > > ( ) ,
75
120
}
76
121
}
77
122
}
78
123
79
- impl < ' a > fmt:: Display for Enum < ' a > {
124
+ impl < ' a > fmt:: Display for Enum < ' a > {
80
125
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
81
-
82
126
let include_variants = !self . variants . is_empty ( ) && Config :: global ( ) . include_fields ;
83
127
84
128
if !include_variants {
85
- write ! ( f,
86
- "<tr><td bgcolor=\" {bgcolor}\" ><b>{name}</b></td></tr>" ,
87
- bgcolor = Config :: global( ) . enum_header_bgcolor,
88
- name = self . name)
129
+ write ! (
130
+ f,
131
+ "<tr><td bgcolor=\" {bgcolor}\" ><b>{name}</b></td></tr>" ,
132
+ bgcolor = Config :: global( ) . enum_header_bgcolor,
133
+ name = self . name
134
+ )
89
135
} else {
90
136
write ! ( f, "<tr><td bgcolor=\" {header_bgcolor}\" ><b>{name}</b></td></tr><tr><td align=\" left\" bgcolor=\" {fields_bgcolor}\" >{variants}<br align=\" left\" /></td></tr>" ,
91
137
header_bgcolor = Config :: global( ) . enum_header_bgcolor,
@@ -105,4 +151,4 @@ impl <'a>fmt::Display for Enum<'a> {
105
151
)
106
152
}
107
153
}
108
- }
154
+ }
0 commit comments