@@ -10,6 +10,7 @@ use rustc_session::{declare_tool_lint, impl_lint_pass};
10
10
use rustc_span:: CharPos ;
11
11
use rustc_span:: Pos ;
12
12
use rustc_span:: Span ;
13
+ use thin_vec:: ThinVec ;
13
14
14
15
// TODO: This still needs to be implemented.
15
16
declare_clippy_lint ! {
@@ -41,8 +42,8 @@ pub struct ExcessiveIndentation {
41
42
}
42
43
43
44
impl EarlyLintPass for ExcessiveIndentation {
44
- fn check_crate ( & mut self , cx : & EarlyContext < ' _ > , krate : & Crate ) {
45
- IndentationVisitor { indent : 0 } . visit_crate ( krate ) ;
45
+ fn check_item ( & mut self , cx : & EarlyContext < ' _ > , item : & Item ) {
46
+ IndentationVisitor { indent : 0 } . visit_item ( item ) ;
46
47
}
47
48
}
48
49
@@ -55,6 +56,12 @@ impl<'i> IndentationGuard<'i> {
55
56
}
56
57
}
57
58
59
+ impl < ' i > Drop for IndentationGuard < ' i > {
60
+ fn drop ( & mut self ) {
61
+ * self . 0 -= 1 ;
62
+ }
63
+ }
64
+
58
65
struct IndentationVisitor {
59
66
indent : u64 ,
60
67
}
@@ -79,7 +86,39 @@ impl Visitor<'_> for IndentationVisitor {
79
86
}
80
87
81
88
fn visit_expr ( & mut self , expr : & Expr ) {
82
- todo ! ( ) ;
89
+ // TODO:
90
+ // Array ❌
91
+ // ConstBlock ❌
92
+ // Call ❌
93
+ // MethodCall ❌
94
+ // Tup ❌
95
+ // Binary ❌
96
+ // Unary ❌
97
+ // Let ❌
98
+ // If ❌
99
+ // While ❌
100
+ // ForLoop ❌
101
+ // Loop ❌
102
+ // Match ❌
103
+ // Closure ❌
104
+ // Block ❌
105
+ // Async ❌
106
+ // Await ❌
107
+ // TryBlock ❌
108
+ // Assign ❌
109
+ // AssignOp ❌
110
+ // Index ❌
111
+ // Range ❌
112
+ // AddrOf ❌
113
+ // Break ❌
114
+ // Continue ❌
115
+ // Ret ❌
116
+ // Struct ❌
117
+ // Repeat ❌
118
+ // Try ❌
119
+ // Yield ❌
120
+ // Yeet ❌
121
+ // We want to destructure these until we find a Block, over, and over, and over again...
83
122
}
84
123
85
124
fn visit_fn ( & mut self , fk : FnKind < ' _ > , _: Span , _: NodeId ) {
@@ -104,33 +143,44 @@ impl Visitor<'_> for IndentationVisitor {
104
143
}
105
144
}
106
145
107
- fn visit_crate ( & mut self , krate : & Crate ) {
108
- for item in & krate. items {
109
- match & item. kind {
110
- // TODO:
111
- // Use ✅
112
- // Static ✅
113
- // Const ✅
114
- // Fn ❌
115
- // Mod ❌
116
- // ForeignMod ✅
117
- // Enum ❌
118
- // Struct ❌
119
- // Union ❌
120
- // Trait ❌
121
- // Impl ❌
122
- // Others should never increase indentation (unless your formatting is really weird), so they won't be included.
123
- ItemKind :: Use ( use_tree) => self . visit_use_tree ( use_tree, NodeId :: MAX , bool:: default ( ) ) ,
124
- ItemKind :: Static ( static_item) if let Some ( expr) = static_item. expr . as_ref ( ) => self . visit_expr ( & * expr) ,
125
- ItemKind :: Const ( const_item) if let Some ( expr) = const_item. expr . as_ref ( ) => self . visit_expr ( & * expr) ,
126
- ItemKind :: Fn ( fk) if let Some ( block) = fk. body . as_ref ( ) => self . visit_block ( block) ,
127
- ItemKind :: ForeignMod ( foreign_mod) => {
128
- for item in & foreign_mod. items {
129
- self . visit_foreign_item ( item)
146
+ fn visit_item ( & mut self , item : & Item ) {
147
+ match & item. kind {
148
+ ItemKind :: Use ( use_tree) => self . visit_use_tree ( use_tree, NodeId :: MAX , bool:: default ( ) ) ,
149
+ ItemKind :: Static ( static_item) if let Some ( expr) = static_item. expr . as_ref ( ) => self . visit_expr ( & * expr) ,
150
+ ItemKind :: Const ( const_item) if let Some ( expr) = const_item. expr . as_ref ( ) => self . visit_expr ( & * expr) ,
151
+ ItemKind :: Fn ( fk) if let Some ( block) = fk. body . as_ref ( ) => self . visit_block ( block) ,
152
+ ItemKind :: Mod ( .., mod_kind) if let ModKind :: Loaded ( items, inline, ..) = mod_kind => {
153
+ for item in items {
154
+ self . visit_item ( item) ;
155
+ }
156
+ }
157
+ ItemKind :: ForeignMod ( foreign_mod) => {
158
+ for item in & foreign_mod. items {
159
+ self . visit_foreign_item ( item)
160
+ }
161
+ } ,
162
+ // TODO: These 2 are duplicated
163
+ ItemKind :: Trait ( trit) => {
164
+ for item in & trit. items {
165
+ match & item. kind {
166
+ // TODO: This is copied from above, is this necessary?
167
+ AssocItemKind :: Const ( const_item) if let Some ( expr) = const_item. expr . as_ref ( ) => self . visit_expr ( & * expr) ,
168
+ AssocItemKind :: Fn ( fk) if let Some ( block) = fk. body . as_ref ( ) => self . visit_block ( block) ,
169
+ _ => ( ) ,
170
+ }
171
+ }
172
+ }
173
+ ItemKind :: Impl ( imp) => {
174
+ for item in & imp. items {
175
+ match & item. kind {
176
+ // TODO: This is copied from above, is this necessary?
177
+ AssocItemKind :: Const ( const_item) if let Some ( expr) = const_item. expr . as_ref ( ) => self . visit_expr ( & * expr) ,
178
+ AssocItemKind :: Fn ( fk) if let Some ( block) = fk. body . as_ref ( ) => self . visit_block ( block) ,
179
+ _ => ( ) ,
130
180
}
131
- } ,
132
- _ => ( ) ,
181
+ }
133
182
}
183
+ _ => ( ) ,
134
184
}
135
185
}
136
186
}
0 commit comments