Run rustfmt

This commit is contained in:
Michael Wright 2019-01-20 12:49:45 +02:00
parent f51f0178dd
commit 8747691bea
7 changed files with 48 additions and 46 deletions

View file

@ -121,20 +121,20 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
let id = map.hir_to_node_id(cmt.hir_id);
if let Some(Node::Stmt(st)) = map.find(map.get_parent_node(id)) {
if let StmtKind::Local(ref loc) = st.node {
if let Some(ref ex) = loc.init {
if let ExprKind::Box(..) = ex.node {
if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
// let x = box (...)
self.set.insert(consume_pat.id);
}
// TODO Box::new
// TODO vec![]
// TODO "foo".to_owned() and friends
if let Some(ref ex) = loc.init {
if let ExprKind::Box(..) = ex.node {
if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
// let x = box (...)
self.set.insert(consume_pat.id);
}
// TODO Box::new
// TODO vec![]
// TODO "foo".to_owned() and friends
}
}
}
}
}
if let Categorization::Local(lid) = cmt.cat {
if self.set.contains(&lid) {
// let y = x where x is known

View file

@ -90,9 +90,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EvalOrderDependence {
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) {
match stmt.node {
StmtKind::Local(ref local) => {
if let Local { init: Some(ref e), .. } = **local {
DivergenceVisitor { cx }.visit_expr(e);
}
if let Local { init: Some(ref e), .. } = **local {
DivergenceVisitor { cx }.visit_expr(e);
}
},
StmtKind::Expr(ref e) | StmtKind::Semi(ref e) => DivergenceVisitor { cx }.maybe_walk_expr(e),
StmtKind::Item(..) => {},
@ -271,9 +271,10 @@ fn check_stmt<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, stmt: &'tcx Stmt) -> St
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => check_expr(vis, expr),
// If the declaration is of a local variable, check its initializer
// expression if it has one. Otherwise, keep going.
StmtKind::Local(ref local) => {
local.init.as_ref().map_or(StopEarly::KeepGoing, |expr| check_expr(vis, expr))
},
StmtKind::Local(ref local) => local
.init
.as_ref()
.map_or(StopEarly::KeepGoing, |expr| check_expr(vis, expr)),
_ => StopEarly::KeepGoing,
}
}

View file

@ -1971,11 +1971,11 @@ fn extract_expr_from_first_stmt(block: &Block) -> Option<&Expr> {
return None;
}
if let StmtKind::Local(ref local) = block.stmts[0].node {
if let Some(ref expr) = local.init {
Some(expr)
} else {
None
}
if let Some(ref expr) = local.init {
Some(expr)
} else {
None
}
} else {
None
}

View file

@ -1337,10 +1337,10 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::Exp
},
hir::Node::Stmt(stmt) => {
if let hir::StmtKind::Local(ref loc) = stmt.node {
if let hir::PatKind::Ref(..) = loc.pat.node {
// let ref y = *x borrows x, let ref y = x.clone() does not
return;
}
if let hir::PatKind::Ref(..) = loc.pat.node {
// let ref y = *x borrows x, let ref y = x.clone() does not
return;
}
}
},
_ => {},

View file

@ -133,22 +133,22 @@ fn check_local<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, local: &'tcx Local, binding
if higher::is_from_for_desugar(local) {
return;
}
let Local {
ref pat,
ref ty,
ref init,
span,
..
} = *local;
if let Some(ref t) = *ty {
check_ty(cx, t, bindings)
}
if let Some(ref o) = *init {
check_expr(cx, o, bindings);
check_pat(cx, pat, Some(o), span, bindings);
} else {
check_pat(cx, pat, None, span, bindings);
}
let Local {
ref pat,
ref ty,
ref init,
span,
..
} = *local;
if let Some(ref t) = *ty {
check_ty(cx, t, bindings)
}
if let Some(ref o) = *init {
check_expr(cx, o, bindings);
check_pat(cx, pat, Some(o), span, bindings);
} else {
check_pat(cx, pat, None, span, bindings);
}
}
fn is_binding(cx: &LateContext<'_, '_>, pat_id: HirId) -> bool {

View file

@ -43,13 +43,14 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
/// Check whether two statements are the same.
pub fn eq_stmt(&mut self, left: &Stmt, right: &Stmt) -> bool {
match (&left.node, &right.node) {
(&StmtKind::Local(ref l), &StmtKind::Local(ref r)) =>
(&StmtKind::Local(ref l), &StmtKind::Local(ref r)) => {
self.eq_pat(&l.pat, &r.pat)
&& both(&l.ty, &r.ty, |l, r| self.eq_ty(l, r))
&& both(&l.init, &r.init, |l, r| self.eq_expr(l, r))
,
(&StmtKind::Expr(ref l), &StmtKind::Expr(ref r))
| (&StmtKind::Semi(ref l), &StmtKind::Semi(ref r)) => self.eq_expr(l, r),
},
(&StmtKind::Expr(ref l), &StmtKind::Expr(ref r)) | (&StmtKind::Semi(ref l), &StmtKind::Semi(ref r)) => {
self.eq_expr(l, r)
},
_ => false,
}
}
@ -649,7 +650,7 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
StmtKind::Item(..) => {
let c: fn(_) -> _ = StmtKind::Item;
c.hash(&mut self.s);
}
},
StmtKind::Expr(ref expr) => {
let c: fn(_) -> _ = StmtKind::Expr;
c.hash(&mut self.s);

View file

@ -130,7 +130,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
println!("init expression:");
print_expr(cx, e, 0);
}
}
},
hir::StmtKind::Item(_) => println!("item decl"),
hir::StmtKind::Expr(ref e) | hir::StmtKind::Semi(ref e) => print_expr(cx, e, 0),
}