|
1 | 1 | //! A group of attributes that can be attached to Rust code in order
|
2 | 2 | //! to generate a clippy lint detecting said code automatically.
|
3 | 3 |
|
4 |
| -use crate::utils::get_attr; |
| 4 | +use crate::utils::{get_attr, higher}; |
5 | 5 | use rustc::hir;
|
6 | 6 | use rustc::hir::intravisit::{NestedVisitorMap, Visitor};
|
7 | 7 | use rustc::hir::{BindingAnnotation, Expr, ExprKind, Pat, PatKind, QPath, Stmt, StmtKind, TyKind};
|
@@ -187,6 +187,32 @@ struct PrintVisitor {
|
187 | 187 | impl<'tcx> Visitor<'tcx> for PrintVisitor {
|
188 | 188 | #[allow(clippy::too_many_lines)]
|
189 | 189 | fn visit_expr(&mut self, expr: &Expr) {
|
| 190 | + // handle if desugarings |
| 191 | + // TODO add more desugarings here |
| 192 | + if let Some((cond, then, opt_else)) = higher::if_block(&expr) { |
| 193 | + let cond_pat = self.next("cond"); |
| 194 | + let then_pat = self.next("then"); |
| 195 | + if let Some(else_) = opt_else { |
| 196 | + let else_pat = self.next("else_"); |
| 197 | + println!( |
| 198 | + " if let Some((ref {}, ref {}, Some({}))) = higher::if_block(&{});", |
| 199 | + cond_pat, then_pat, else_pat, self.current |
| 200 | + ); |
| 201 | + self.current = else_pat; |
| 202 | + self.visit_expr(else_); |
| 203 | + } else { |
| 204 | + println!( |
| 205 | + " if let Some((ref {}, ref {}, None)) = higher::if_block(&{});", |
| 206 | + cond_pat, then_pat, self.current |
| 207 | + ); |
| 208 | + } |
| 209 | + self.current = cond_pat; |
| 210 | + self.visit_expr(cond); |
| 211 | + self.current = then_pat; |
| 212 | + self.visit_expr(then); |
| 213 | + return; |
| 214 | + } |
| 215 | + |
190 | 216 | print!(" if let ExprKind::");
|
191 | 217 | let current = format!("{}.node", self.current);
|
192 | 218 | match expr.node {
|
|
0 commit comments