Fix some formatting issues

This commit is contained in:
flip1995 2018-11-27 21:49:09 +01:00
parent 1751d2496d
commit 63fa5d24e1
No known key found for this signature in database
GPG Key ID: E8E897A5870E41C2
14 changed files with 120 additions and 139 deletions

View File

@ -49,44 +49,44 @@ impl LintPass for DefaultTraitAccess {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if_chain! {
if let ExprKind::Call(ref path, ..) = expr.node;
if !any_parent_is_automatically_derived(cx.tcx, expr.id);
if let ExprKind::Path(ref qpath) = path.node;
if let Some(def_id) = opt_def_id(cx.tables.qpath_def(qpath, path.hir_id));
if match_def_path(cx.tcx, def_id, &paths::DEFAULT_TRAIT_METHOD);
then {
match qpath {
QPath::Resolved(..) => {
if_chain! {
// Detect and ignore <Foo as Default>::default() because these calls do
// explicitly name the type.
if let ExprKind::Call(ref method, ref _args) = expr.node;
if let ExprKind::Path(ref p) = method.node;
if let QPath::Resolved(Some(_ty), _path) = p;
then {
return;
}
}
// TODO: Work out a way to put "whatever the imported way of referencing
// this type in this file" rather than a fully-qualified type.
let expr_ty = cx.tables.expr_ty(expr);
if let TyKind::Adt(..) = expr_ty.sty {
let replacement = format!("{}::default()", expr_ty);
span_lint_and_sugg(
cx,
DEFAULT_TRAIT_ACCESS,
expr.span,
&format!("Calling {} is more clear than this expression", replacement),
"try",
replacement,
Applicability::Unspecified, // First resolve the TODO above
);
if let ExprKind::Call(ref path, ..) = expr.node;
if !any_parent_is_automatically_derived(cx.tcx, expr.id);
if let ExprKind::Path(ref qpath) = path.node;
if let Some(def_id) = opt_def_id(cx.tables.qpath_def(qpath, path.hir_id));
if match_def_path(cx.tcx, def_id, &paths::DEFAULT_TRAIT_METHOD);
then {
match qpath {
QPath::Resolved(..) => {
if_chain! {
// Detect and ignore <Foo as Default>::default() because these calls do
// explicitly name the type.
if let ExprKind::Call(ref method, ref _args) = expr.node;
if let ExprKind::Path(ref p) = method.node;
if let QPath::Resolved(Some(_ty), _path) = p;
then {
return;
}
}
},
QPath::TypeRelative(..) => {},
}
}
// TODO: Work out a way to put "whatever the imported way of referencing
// this type in this file" rather than a fully-qualified type.
let expr_ty = cx.tables.expr_ty(expr);
if let TyKind::Adt(..) = expr_ty.sty {
let replacement = format!("{}::default()", expr_ty);
span_lint_and_sugg(
cx,
DEFAULT_TRAIT_ACCESS,
expr.span,
&format!("Calling {} is more clear than this expression", replacement),
"try",
replacement,
Applicability::Unspecified, // First resolve the TODO above
);
}
},
QPath::TypeRelative(..) => {},
}
}
}
}
}

View File

@ -27,10 +27,9 @@ use if_chain::if_chain;
/// writeln!(&mut io::stderr(), "foo: {:?}", bar).unwrap();
/// ```
declare_clippy_lint! {
pub EXPLICIT_WRITE,
complexity,
"using the `write!()` family of functions instead of the `print!()` family \
of functions, when using the latter would work"
pub EXPLICIT_WRITE,
complexity,
"using the `write!()` family of functions instead of the `print!()` family of functions, when using the latter would work"
}
#[derive(Copy, Clone, Debug)]

View File

@ -249,10 +249,9 @@ declare_clippy_lint! {
/// vec.iter().map(|x| /* some operation returning () */).collect::<Vec<_>>();
/// ```
declare_clippy_lint! {
pub UNUSED_COLLECT,
perf,
"`collect()`ing an iterator without using the result; this is usually better \
written as a for loop"
pub UNUSED_COLLECT,
perf,
"`collect()`ing an iterator without using the result; this is usually better written as a for loop"
}
/// **What it does:** Checks for functions collecting an iterator when collect

View File

@ -81,7 +81,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, name, None) => {
match closure_expr.node {
hir::ExprKind::Unary(hir::UnOp::UnDeref, ref inner) => {
if !cx.tables.expr_ty(inner).is_box() => {
if !cx.tables.expr_ty(inner).is_box() {
lint(cx, e.span, args[0].span, name, inner);
}
},

View File

@ -40,10 +40,9 @@ use std::collections::Bound;
/// }
/// ```
declare_clippy_lint! {
pub SINGLE_MATCH,
style,
"a match statement with a single nontrivial arm (i.e. where the other arm \
is `_ => {}`) instead of `if let`"
pub SINGLE_MATCH,
style,
"a match statement with a single nontrivial arm (i.e. where the other arm is `_ => {}`) instead of `if let`"
}
/// **What it does:** Checks for matches with a two arms where an `if let` will
@ -61,10 +60,9 @@ style,
/// }
/// ```
declare_clippy_lint! {
pub SINGLE_MATCH_ELSE,
pedantic,
"a match statement with a two arms where the second arm's pattern is a wildcard \
instead of `if let`"
pub SINGLE_MATCH_ELSE,
pedantic,
"a match statement with a two arms where the second arm's pattern is a wildcard instead of `if let`"
}
/// **What it does:** Checks for matches where all arms match a reference,

View File

@ -131,10 +131,9 @@ declare_clippy_lint! {
/// }
/// ```
declare_clippy_lint! {
pub WRONG_SELF_CONVENTION,
style,
"defining a method named with an established prefix (like \"into_\") that takes \
`self` with the wrong convention"
pub WRONG_SELF_CONVENTION,
style,
"defining a method named with an established prefix (like \"into_\") that takes `self` with the wrong convention"
}
/// **What it does:** This is the same as
@ -155,10 +154,9 @@ style,
/// }
/// ```
declare_clippy_lint! {
pub WRONG_PUB_SELF_CONVENTION,
restriction,
"defining a public method named with an established prefix (like \"into_\") that takes \
`self` with the wrong convention"
pub WRONG_PUB_SELF_CONVENTION,
restriction,
"defining a public method named with an established prefix (like \"into_\") that takes `self` with the wrong convention"
}
/// **What it does:** Checks for usage of `ok().expect(..)`.
@ -173,10 +171,9 @@ restriction,
/// x.ok().expect("why did I do this again?")
/// ```
declare_clippy_lint! {
pub OK_EXPECT,
style,
"using `ok().expect()`, which gives worse error messages than \
calling `expect` directly on the Result"
pub OK_EXPECT,
style,
"using `ok().expect()`, which gives worse error messages than calling `expect` directly on the Result"
}
/// **What it does:** Checks for usage of `_.map(_).unwrap_or(_)`.
@ -209,10 +206,9 @@ pedantic,
/// x.map(|a| a + 1).unwrap_or_else(some_function)
/// ```
declare_clippy_lint! {
pub OPTION_MAP_UNWRAP_OR_ELSE,
pedantic,
"using `Option.map(f).unwrap_or_else(g)`, which is more succinctly expressed as \
`map_or_else(g, f)`"
pub OPTION_MAP_UNWRAP_OR_ELSE,
pedantic,
"using `Option.map(f).unwrap_or_else(g)`, which is more succinctly expressed as `map_or_else(g, f)`"
}
/// **What it does:** Checks for usage of `result.map(_).unwrap_or_else(_)`.
@ -227,10 +223,9 @@ pedantic,
/// x.map(|a| a + 1).unwrap_or_else(some_function)
/// ```
declare_clippy_lint! {
pub RESULT_MAP_UNWRAP_OR_ELSE,
pedantic,
"using `Result.map(f).unwrap_or_else(g)`, which is more succinctly expressed as \
`.ok().map_or_else(g, f)`"
pub RESULT_MAP_UNWRAP_OR_ELSE,
pedantic,
"using `Result.map(f).unwrap_or_else(g)`, which is more succinctly expressed as `.ok().map_or_else(g, f)`"
}
/// **What it does:** Checks for usage of `_.map_or(None, _)`.
@ -245,10 +240,9 @@ pedantic,
/// opt.map_or(None, |a| a + 1)
/// ```
declare_clippy_lint! {
pub OPTION_MAP_OR_NONE,
style,
"using `Option.map_or(None, f)`, which is more succinctly expressed as \
`and_then(f)`"
pub OPTION_MAP_OR_NONE,
style,
"using `Option.map_or(None, f)`, which is more succinctly expressed as `and_then(f)`"
}
/// **What it does:** Checks for usage of `_.filter(_).next()`.
@ -280,10 +274,9 @@ declare_clippy_lint! {
/// iter.map(|x| x.iter()).flatten()
/// ```
declare_clippy_lint! {
pub MAP_FLATTEN,
pedantic,
"using combinations of `flatten` and `map` which can usually be written as a \
single method call"
pub MAP_FLATTEN,
pedantic,
"using combinations of `flatten` and `map` which can usually be written as a single method call"
}
/// **What it does:** Checks for usage of `_.filter(_).map(_)`,
@ -300,10 +293,9 @@ pedantic,
/// iter.filter(|x| x == 0).map(|x| x * 2)
/// ```
declare_clippy_lint! {
pub FILTER_MAP,
pedantic,
"using combinations of `filter`, `map`, `filter_map` and `flat_map` which can \
usually be written as a single method call"
pub FILTER_MAP,
pedantic,
"using combinations of `filter`, `map`, `filter_map` and `flat_map` which can usually be written as a single method call"
}
/// **What it does:** Checks for an iterator search (such as `find()`,
@ -319,10 +311,9 @@ pedantic,
/// iter.find(|x| x == 0).is_some()
/// ```
declare_clippy_lint! {
pub SEARCH_IS_SOME,
complexity,
"using an iterator search followed by `is_some()`, which is more succinctly \
expressed as a call to `any()`"
pub SEARCH_IS_SOME,
complexity,
"using an iterator search followed by `is_some()`, which is more succinctly expressed as a call to `any()`"
}
/// **What it does:** Checks for usage of `.chars().next()` on a `str` to check
@ -485,10 +476,9 @@ declare_clippy_lint! {
/// **Example:**
/// `_.split("x")` could be `_.split('x')`
declare_clippy_lint! {
pub SINGLE_CHAR_PATTERN,
perf,
"using a single-character str where a char could be used, e.g. \
`_.split(\"x\")`"
pub SINGLE_CHAR_PATTERN,
perf,
"using a single-character str where a char could be used, e.g. `_.split(\"x\")`"
}
/// **What it does:** Checks for getting the inner pointer of a temporary

View File

@ -27,10 +27,9 @@ use crate::utils::span_lint;
/// my_vec.push(&mut value)
/// ```
declare_clippy_lint! {
pub UNNECESSARY_MUT_PASSED,
style,
"an argument passed as a mutable reference although the callee only demands an \
immutable reference"
pub UNNECESSARY_MUT_PASSED,
style,
"an argument passed as a mutable reference although the callee only demands an immutable reference"
}
#[derive(Copy, Clone)]

View File

@ -40,10 +40,9 @@ use crate::utils::{in_macro, snippet_with_applicability, span_lint, span_lint_an
/// }
/// ```
declare_clippy_lint! {
pub NEEDLESS_BOOL,
complexity,
"if-statements with plain booleans in the then- and else-clause, e.g. \
`if p { true } else { false }`"
pub NEEDLESS_BOOL,
complexity,
"if-statements with plain booleans in the then- and else-clause, e.g. `if p { true } else { false }`"
}
/// **What it does:** Checks for expressions of the form `x == true` (or vice

View File

@ -54,10 +54,9 @@ use std::borrow::Cow;
/// fn foo(&Vec<u32>) { .. }
/// ```
declare_clippy_lint! {
pub PTR_ARG,
style,
"fn arguments of the type `&Vec<...>` or `&String`, suggesting to use `&[...]` or `&str` \
instead, respectively"
pub PTR_ARG,
style,
"fn arguments of the type `&Vec<...>` or `&String`, suggesting to use `&[...]` or `&str` instead, respectively"
}
/// **What it does:** This lint checks for equality comparisons with `ptr::null`

View File

@ -65,10 +65,9 @@ declare_clippy_lint! {
/// }
/// ```
declare_clippy_lint! {
pub LET_AND_RETURN,
style,
"creating a let-binding and then immediately returning it like `let x = expr; x` at \
the end of a block"
pub LET_AND_RETURN,
style,
"creating a let-binding and then immediately returning it like `let x = expr; x` at the end of a block"
}
/// **What it does:** Checks for unit (`()`) expressions that can be removed.

View File

@ -56,10 +56,9 @@ declare_clippy_lint! {
/// let y = x + 1;
/// ```
declare_clippy_lint! {
pub SHADOW_REUSE,
restriction,
"rebinding a name to an expression that re-uses the original value, e.g. \
`let x = x + 1`"
pub SHADOW_REUSE,
restriction,
"rebinding a name to an expression that re-uses the original value, e.g. `let x = x + 1`"
}
/// **What it does:** Checks for bindings that shadow other bindings already in

View File

@ -81,7 +81,8 @@ declare_clippy_lint! {
/// **Example:**
/// ```rust
/// let _: &T = std::mem::transmute(p); // where p: *const T
/// // can be written:
///
/// // can be written:
/// let _: &T = &*p;
/// ```
declare_clippy_lint! {
@ -108,7 +109,8 @@ declare_clippy_lint! {
/// **Example:**
/// ```rust
/// let _: char = std::mem::transmute(x); // where x: u32
/// // should be:
///
/// // should be:
/// let _ = std::char::from_u32(x).unwrap();
/// ```
declare_clippy_lint! {
@ -135,7 +137,8 @@ declare_clippy_lint! {
/// **Example:**
/// ```rust
/// let _: &str = std::mem::transmute(b); // where b: &[u8]
/// // should be:
///
/// // should be:
/// let _ = std::str::from_utf8(b).unwrap();
/// ```
declare_clippy_lint! {
@ -153,7 +156,8 @@ declare_clippy_lint! {
/// **Example:**
/// ```rust
/// let _: bool = std::mem::transmute(x); // where x: u8
/// // should be:
///
/// // should be:
/// let _: bool = x != 0;
/// ```
declare_clippy_lint! {
@ -171,7 +175,8 @@ declare_clippy_lint! {
/// **Example:**
/// ```rust
/// let _: f32 = std::mem::transmute(x); // where x: u32
/// // should be:
///
/// // should be:
/// let _: f32 = f32::from_bits(x);
/// ```
declare_clippy_lint! {

View File

@ -117,10 +117,9 @@ declare_clippy_lint! {
/// let x = LinkedList::new();
/// ```
declare_clippy_lint! {
pub LINKEDLIST,
pedantic,
"usage of LinkedList, usually a vector is faster, or a more specialized data \
structure like a VecDeque"
pub LINKEDLIST,
pedantic,
"usage of LinkedList, usually a vector is faster, or a more specialized data structure like a VecDeque"
}
/// **What it does:** Checks for use of `&Box<T>` anywhere in the code.
@ -668,10 +667,9 @@ declare_clippy_lint! {
/// }
/// ```
declare_clippy_lint! {
pub CAST_POSSIBLE_TRUNCATION,
pedantic,
"casts that may cause truncation of the value, e.g. `x as u8` where `x: u32`, \
or `x as i32` where `x: f32`"
pub CAST_POSSIBLE_TRUNCATION,
pedantic,
"casts that may cause truncation of the value, e.g. `x as u8` where `x: u32`, or `x as i32` where `x: f32`"
}
/// **What it does:** Checks for casts from an unsigned type to a signed type of
@ -692,10 +690,9 @@ pedantic,
/// u32::MAX as i32 // will yield a value of `-1`
/// ```
declare_clippy_lint! {
pub CAST_POSSIBLE_WRAP,
pedantic,
"casts that may cause wrapping around the value, e.g. `x as i32` where `x: u32` \
and `x > i32::MAX`"
pub CAST_POSSIBLE_WRAP,
pedantic,
"casts that may cause wrapping around the value, e.g. `x as i32` where `x: u32` and `x > i32::MAX`"
}
/// **What it does:** Checks for on casts between numerical types that may

View File

@ -45,10 +45,9 @@ declare_clippy_lint! {
/// let x = "Hä?"
/// ```
declare_clippy_lint! {
pub NON_ASCII_LITERAL,
pedantic,
"using any literal non-ASCII chars in a string literal instead of \
using the `\\u` escape"
pub NON_ASCII_LITERAL,
pedantic,
"using any literal non-ASCII chars in a string literal instead of using the `\\u` escape"
}
/// **What it does:** Checks for string literals that contain Unicode in a form
@ -63,10 +62,9 @@ pedantic,
/// **Example:** You may not see it, but “à” and “à” aren't the same string. The
/// former when escaped is actually `"a\u{300}"` while the latter is `"\u{e0}"`.
declare_clippy_lint! {
pub UNICODE_NOT_NFC,
pedantic,
"using a unicode literal not in NFC normal form (see \
[unicode tr15](http://www.unicode.org/reports/tr15/) for further information)"
pub UNICODE_NOT_NFC,
pedantic,
"using a unicode literal not in NFC normal form (see [unicode tr15](http://www.unicode.org/reports/tr15/) for further information)"
}
#[derive(Copy, Clone)]