More initial work
This commit is contained in:
parent
9e3be6ae49
commit
2a97aadacf
1 changed files with 46 additions and 10 deletions
|
@ -35,19 +35,55 @@ impl LintPass for UnitExpr {
|
||||||
impl EarlyLintPass for UnitExpr {
|
impl EarlyLintPass for UnitExpr {
|
||||||
fn check_expr(&mut self, cx: &EarlyContext, expr: &Expr) {
|
fn check_expr(&mut self, cx: &EarlyContext, expr: &Expr) {
|
||||||
if let ExprKind::Assign(ref left, ref right) = expr.node {
|
if let ExprKind::Assign(ref left, ref right) = expr.node {
|
||||||
unimplemented!();
|
if is_unit_expr(right){
|
||||||
}
|
span_lint_and_sugg(
|
||||||
if let ExprKind::MethodCall(ref path, ref args) = expr.node {
|
cx,
|
||||||
unimplemented!();
|
UNIT_EXPR,
|
||||||
}
|
right.span,
|
||||||
if let ExprKind::Call(ref path, ref args) = expr.node{
|
"trailing semicolons can be tricky",
|
||||||
unimplemented!();
|
"remove the last semicolon",
|
||||||
|
"TODO".to_owned()
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// if let ExprKind::MethodCall(ref path, ref args) = expr.node {
|
||||||
|
// unimplemented!();
|
||||||
|
// }
|
||||||
|
// if let ExprKind::Call(ref path, ref args) = expr.node{
|
||||||
|
// unimplemented!();
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_stmt(&mut self, cx: &EarlyContext, stmt: &Stmt) {
|
fn check_stmt(&mut self, cx: &EarlyContext, stmt: &Stmt) {
|
||||||
if let StmtKind::Local(ref data) = stmt.node{
|
if let StmtKind::Local(ref local) = stmt.node{
|
||||||
unimplemented!();
|
if local.pat.node == PatKind::Wild {return;}
|
||||||
}
|
if let Some(ref expr) = local.init{
|
||||||
|
if is_unit_expr(expr){
|
||||||
|
span_lint_and_sugg(
|
||||||
|
cx,
|
||||||
|
UNIT_EXPR,
|
||||||
|
local.span,
|
||||||
|
"trailing semicolons can be tricky",
|
||||||
|
"remove the last semicolon",
|
||||||
|
"TODO".to_owned()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_unit_expr(expr: &Expr)->bool{
|
||||||
|
match expr.node{
|
||||||
|
ExprKind::Block(ref next) => {
|
||||||
|
let ref final_stmt = &next.stmts[next.stmts.len()-1];
|
||||||
|
if let StmtKind::Expr(_) = final_stmt.node{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => return false,
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue