apply rustfmt

This commit is contained in:
Oliver Schneider 2017-01-17 19:30:32 +01:00
parent 7b836dd27c
commit 713da45906
No known key found for this signature in database
GPG key ID: 56D6EEA0FC67AC46
21 changed files with 101 additions and 129 deletions

View file

@ -94,14 +94,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
MISREFACTORED_ASSIGN_OP,
expr.span,
"variable appears on both sides of an assignment operation",
|db| {
if let (Some(snip_a), Some(snip_r)) =
(snippet_opt(cx, assignee.span), snippet_opt(cx, rhs.span)) {
db.span_suggestion(expr.span,
|db| if let (Some(snip_a), Some(snip_r)) =
(snippet_opt(cx, assignee.span), snippet_opt(cx, rhs.span)) {
db.span_suggestion(expr.span,
"replace it with",
format!("{} {}= {}", snip_a, op.node.as_str(), snip_r));
}
});
});
};
// lhs op= l op r
if SpanlessEq::new(cx).ignore_fn().eq_expr(lhs, l) {
@ -177,14 +175,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
ASSIGN_OP_PATTERN,
expr.span,
"manual implementation of an assign operation",
|db| {
if let (Some(snip_a), Some(snip_r)) =
(snippet_opt(cx, assignee.span), snippet_opt(cx, rhs.span)) {
db.span_suggestion(expr.span,
|db| if let (Some(snip_a), Some(snip_r)) =
(snippet_opt(cx, assignee.span), snippet_opt(cx, rhs.span)) {
db.span_suggestion(expr.span,
"replace it with",
format!("{} {}= {}", snip_a, op.node.as_str(), snip_r));
}
});
});
}
};
// a = a op b

View file

@ -240,7 +240,7 @@ fn fetch_int_literal(cx: &LateContext, lit: &Expr) -> Option<u128> {
match lit.node {
ExprLit(ref lit_ptr) => {
if let LitKind::Int(value, _) = lit_ptr.node {
Some(value) //TODO: Handle sign
Some(value) // TODO: Handle sign
} else {
None
}

View file

@ -384,11 +384,9 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
NONMINIMAL_BOOL,
e.span,
"this boolean expression can be simplified",
|db| {
for suggestion in &improvements {
db.span_suggestion(e.span, "try", suggest(self.cx, suggestion, &h2q.terminals));
}
});
|db| for suggestion in &improvements {
db.span_suggestion(e.span, "try", suggest(self.cx, suggestion, &h2q.terminals));
});
}
}
}

View file

@ -270,12 +270,10 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
}
},
ExprUnary(op, ref operand) => {
self.expr(operand).and_then(|o| {
match op {
UnNot => constant_not(o),
UnNeg => constant_negate(o),
UnDeref => Some(o),
}
self.expr(operand).and_then(|o| match op {
UnNot => constant_not(o),
UnNeg => constant_negate(o),
UnDeref => Some(o),
})
},
ExprBinary(op, ref left, ref right) => self.binop(op, left, right),

View file

@ -173,8 +173,6 @@ fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item: &Item, trait_ref
EXPL_IMPL_CLONE_ON_COPY,
item.span,
"you are implementing `Clone` explicitly on a `Copy` type",
|db| {
db.span_note(item.span, "consider deriving `Clone` or removing `Copy`");
});
|db| { db.span_note(item.span, "consider deriving `Clone` or removing `Copy`"); });
}
}

View file

@ -305,7 +305,8 @@ fn check_doc(cx: &EarlyContext, valid_idents: &[String], docs: &[(String, Span)]
continue;
}
try!(parser.jump_to('`')); // not a code block, just inline code
// not a code block, just inline code
try!(parser.jump_to('`'));
},
'~' => {
if try!(check_block!(parser, '~', new_line)) {

View file

@ -206,13 +206,11 @@ impl<'a, 'tcx: 'a> EscapeDelegate<'a, 'tcx> {
// overflows.
match ty.sty {
ty::TyBox(inner) => {
self.tcx.infer_ctxt((), Reveal::All).enter(|infcx| {
if let Ok(layout) = inner.layout(&infcx) {
let size = layout.size(&self.target);
size.bytes() > self.too_large_for_stack
} else {
false
}
self.tcx.infer_ctxt((), Reveal::All).enter(|infcx| if let Ok(layout) = inner.layout(&infcx) {
let size = layout.size(&self.target);
size.bytes() > self.too_large_for_stack
} else {
false
})
},
_ => false,

View file

@ -91,11 +91,13 @@ fn check_closure(cx: &LateContext, expr: &Expr) {
return;
}
}
span_lint_and_then(cx, REDUNDANT_CLOSURE, expr.span, "redundant closure found", |db| {
if let Some(snippet) = snippet_opt(cx, caller.span) {
db.span_suggestion(expr.span, "remove closure as shown:", snippet);
}
});
span_lint_and_then(cx,
REDUNDANT_CLOSURE,
expr.span,
"redundant closure found",
|db| if let Some(snippet) = snippet_opt(cx, caller.span) {
db.span_suggestion(expr.span, "remove closure as shown:", snippet);
});
}
}
}

View file

@ -393,15 +393,13 @@ type TypedRanges = Vec<SpannedRange<ConstInt>>;
/// `Uint` and `Int` probably don't make sense.
fn type_ranges(ranges: &[SpannedRange<ConstVal>]) -> TypedRanges {
ranges.iter()
.filter_map(|range| {
if let (ConstVal::Integral(start), ConstVal::Integral(end)) = range.node {
Some(SpannedRange {
span: range.span,
node: (start, end),
})
} else {
None
}
.filter_map(|range| if let (ConstVal::Integral(start), ConstVal::Integral(end)) = range.node {
Some(SpannedRange {
span: range.span,
node: (start, end),
})
} else {
None
})
.collect()
}

View file

@ -1213,9 +1213,7 @@ fn lint_single_char_pattern(cx: &LateContext, expr: &hir::Expr, arg: &hir::Expr)
SINGLE_CHAR_PATTERN,
arg.span,
"single-character string constant used as pattern",
|db| {
db.span_suggestion(expr.span, "try using a char instead:", hint);
});
|db| { db.span_suggestion(expr.span, "try using a char instead:", hint); });
}
}
}

View file

@ -351,13 +351,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
}
fn check_nan(cx: &LateContext, path: &Path, span: Span) {
path.segments.last().map(|seg| {
if &*seg.name.as_str() == "NAN" {
span_lint(cx,
CMP_NAN,
span,
"doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead");
}
path.segments.last().map(|seg| if &*seg.name.as_str() == "NAN" {
span_lint(cx,
CMP_NAN,
span,
"doomed comparison with NAN, use `std::{f32,f64}::is_nan()` instead");
});
}

View file

@ -276,12 +276,10 @@ impl EarlyLintPass for MiscEarly {
REDUNDANT_CLOSURE_CALL,
expr.span,
"Try not to call a closure in the expression where it is declared.",
|db| {
if decl.inputs.is_empty() {
let hint = snippet(cx, block.span, "..").into_owned();
db.span_suggestion(expr.span, "Try doing something like: ", hint);
}
});
|db| if decl.inputs.is_empty() {
let hint = snippet(cx, block.span, "..").into_owned();
db.span_suggestion(expr.span, "Try doing something like: ", hint);
});
}
}
},

View file

@ -74,9 +74,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBool {
NEEDLESS_BOOL,
e.span,
"this if-then-else expression returns a bool literal",
|db| {
db.span_suggestion(e.span, "you can reduce it to", hint);
});
|db| { db.span_suggestion(e.span, "you can reduce it to", hint); });
};
match (fetch_bool_block(then_block), fetch_bool_expr(else_expr)) {
(RetBool(true), RetBool(true)) |
@ -123,9 +121,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison {
BOOL_COMPARISON,
e.span,
"equality checks against true are unnecessary",
|db| {
db.span_suggestion(e.span, "try simplifying it as shown:", hint);
});
|db| { db.span_suggestion(e.span, "try simplifying it as shown:", hint); });
},
(Other, Bool(true)) => {
let hint = snippet(cx, left_side.span, "..").into_owned();
@ -133,9 +129,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison {
BOOL_COMPARISON,
e.span,
"equality checks against true are unnecessary",
|db| {
db.span_suggestion(e.span, "try simplifying it as shown:", hint);
});
|db| { db.span_suggestion(e.span, "try simplifying it as shown:", hint); });
},
(Bool(false), Other) => {
let hint = Sugg::hir(cx, right_side, "..");

View file

@ -120,9 +120,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
return;
}
}
span_lint_and_then(cx, UNNECESSARY_OPERATION, stmt.span, "statement can be reduced", |db| {
db.span_suggestion(stmt.span, "replace it with", snippet);
});
span_lint_and_then(cx,
UNNECESSARY_OPERATION,
stmt.span,
"statement can be reduced",
|db| { db.span_suggestion(stmt.span, "replace it with", snippet); });
}
}
}

View file

@ -74,8 +74,8 @@ fn get_open_options(cx: &LateContext, argument: &Expr, options: &mut Vec<(OpenOp
if lit { Argument::True } else { Argument::False }
} else {
return; // The function is called with a literal
// which is not a boolean literal. This is theoretically
// possible, but not very likely.
// which is not a boolean literal. This is theoretically
// possible, but not very likely.
}
},
_ => Argument::Unknown,

View file

@ -92,11 +92,13 @@ impl ReturnPass {
if in_external_macro(cx, inner_span) {
return;
}
span_lint_and_then(cx, NEEDLESS_RETURN, ret_span, "unneeded return statement", |db| {
if let Some(snippet) = snippet_opt(cx, inner_span) {
db.span_suggestion(ret_span, "remove `return` as shown:", snippet);
}
});
span_lint_and_then(cx,
NEEDLESS_RETURN,
ret_span,
"unneeded return statement",
|db| if let Some(snippet) = snippet_opt(cx, inner_span) {
db.span_suggestion(ret_span, "remove `return` as shown:", snippet);
});
}
// Check for "let x = EXPR; x"

View file

@ -250,9 +250,7 @@ fn lint_shadow<'a, 'tcx: 'a>(
&format!("`{}` is shadowed by itself in `{}`",
snippet(cx, pattern_span, "_"),
snippet(cx, expr.span, "..")),
|db| {
db.span_note(prev_span, "previous binding is here");
});
|db| { db.span_note(prev_span, "previous binding is here"); });
} else if contains_self(cx, name, expr) {
span_lint_and_then(cx,
SHADOW_REUSE,
@ -282,9 +280,7 @@ fn lint_shadow<'a, 'tcx: 'a>(
SHADOW_UNRELATED,
span,
&format!("`{}` shadows a previous declaration", snippet(cx, pattern_span, "_")),
|db| {
db.span_note(prev_span, "previous binding is here");
});
|db| { db.span_note(prev_span, "previous binding is here"); });
}
}

View file

@ -106,17 +106,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
USELESS_TRANSMUTE,
e.span,
"transmute from a reference to a pointer",
|db| {
if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) {
let sugg = if ptr_ty == rty {
arg.as_ty(to_ty)
} else {
arg.as_ty(cx.tcx.mk_ptr(rty)).as_ty(to_ty)
};
|db| if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) {
let sugg = if ptr_ty == rty {
arg.as_ty(to_ty)
} else {
arg.as_ty(cx.tcx.mk_ptr(rty)).as_ty(to_ty)
};
db.span_suggestion(e.span, "try", sugg.to_string());
}
})
db.span_suggestion(e.span, "try", sugg.to_string());
})
},
(&ty::TyInt(_), &TyRawPtr(_)) |
(&ty::TyUint(_), &TyRawPtr(_)) => {
@ -124,11 +122,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
USELESS_TRANSMUTE,
e.span,
"transmute from an integer to a pointer",
|db| {
if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) {
db.span_suggestion(e.span, "try", arg.as_ty(&to_ty.to_string()).to_string());
}
})
|db| if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) {
db.span_suggestion(e.span,
"try",
arg.as_ty(&to_ty.to_string()).to_string());
})
},
(&ty::TyFloat(_), &TyRef(..)) |
(&ty::TyFloat(_), &TyRawPtr(_)) |

View file

@ -445,12 +445,10 @@ fn trim_multiline_inner(s: Cow<str>, ignore_first: bool, ch: char) -> Cow<str> {
if x > 0 {
Cow::Owned(s.lines()
.enumerate()
.map(|(i, l)| {
if (ignore_first && i == 0) || l.is_empty() {
l
} else {
l.split_at(x).1
}
.map(|(i, l)| if (ignore_first && i == 0) || l.is_empty() {
l
} else {
l.split_at(x).1
})
.collect::<Vec<_>>()
.join("\n"))
@ -467,12 +465,10 @@ pub fn get_parent_expr<'c>(cx: &'c LateContext, e: &Expr) -> Option<&'c Expr> {
if node_id == parent_id {
return None;
}
map.find(parent_id).and_then(|node| {
if let Node::NodeExpr(parent) = node {
Some(parent)
} else {
None
}
map.find(parent_id).and_then(|node| if let Node::NodeExpr(parent) = node {
Some(parent)
} else {
None
})
}

View file

@ -258,8 +258,9 @@ pub fn make_assoc(op: AssocOp, lhs: &Sugg, rhs: &Sugg) -> Sugg<'static> {
fn needs_paren(op: &AssocOp, other: &AssocOp, dir: Associativity) -> bool {
other.precedence() < op.precedence() ||
(other.precedence() == op.precedence() &&
((op != other && associativity(op) != dir) || (op == other && associativity(op) != Associativity::Both))) ||
is_shift(op) && is_arith(other) || is_shift(other) && is_arith(op)
((op != other && associativity(op) != dir) ||
(op == other && associativity(op) != Associativity::Both))) || is_shift(op) && is_arith(other) ||
is_shift(other) && is_arith(op)
}
let lhs_paren = if let Sugg::BinOp(ref lop, _) = *lhs {
@ -433,13 +434,11 @@ impl<'a, 'b, 'c, T: LintContext<'c>> DiagnosticBuilderExt<'c, T> for rustc_error
let mut first = true;
let new_item = new_item.lines()
.map(|l| {
if first {
first = false;
format!("{}\n", l)
} else {
format!("{}{}\n", indent, l)
}
.map(|l| if first {
first = false;
format!("{}\n", l)
} else {
format!("{}{}\n", indent, l)
})
.collect::<String>();

View file

@ -81,9 +81,11 @@ fn check_vec_macro(cx: &LateContext, vec_args: &higher::VecArgs, span: Span) {
},
};
span_lint_and_then(cx, USELESS_VEC, span, "useless use of `vec!`", |db| {
db.span_suggestion(span, "you can use a slice directly", snippet);
});
span_lint_and_then(cx,
USELESS_VEC,
span,
"useless use of `vec!`",
|db| { db.span_suggestion(span, "you can use a slice directly", snippet); });
}
/// Return the item type of the vector (ie. the `T` in `Vec<T>`).