Skip to content

Commit ce2c4dd

Browse files
committed
finish destructuring items, add comment for expr destructuring
1 parent 6078517 commit ce2c4dd

File tree

2 files changed

+219
-37
lines changed

2 files changed

+219
-37
lines changed

clippy_lints/src/excessive_indentation.rs

Lines changed: 78 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_session::{declare_tool_lint, impl_lint_pass};
1010
use rustc_span::CharPos;
1111
use rustc_span::Pos;
1212
use rustc_span::Span;
13+
use thin_vec::ThinVec;
1314

1415
// TODO: This still needs to be implemented.
1516
declare_clippy_lint! {
@@ -41,8 +42,8 @@ pub struct ExcessiveIndentation {
4142
}
4243

4344
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);
4647
}
4748
}
4849

@@ -55,6 +56,12 @@ impl<'i> IndentationGuard<'i> {
5556
}
5657
}
5758

59+
impl<'i> Drop for IndentationGuard<'i> {
60+
fn drop(&mut self) {
61+
*self.0 -= 1;
62+
}
63+
}
64+
5865
struct IndentationVisitor {
5966
indent: u64,
6067
}
@@ -79,7 +86,39 @@ impl Visitor<'_> for IndentationVisitor {
7986
}
8087

8188
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...
83122
}
84123

85124
fn visit_fn(&mut self, fk: FnKind<'_>, _: Span, _: NodeId) {
@@ -104,33 +143,44 @@ impl Visitor<'_> for IndentationVisitor {
104143
}
105144
}
106145

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+
_ => (),
130180
}
131-
},
132-
_ => (),
181+
}
133182
}
183+
_ => (),
134184
}
135185
}
136186
}

0 commit comments

Comments
 (0)