use syntax::ast::*;
use syntax::codemap::Span;
use syntax::visit::FnKind;
-use utils::{constants, in_external_macro, snippet, snippet_opt, span_help_and_lint, span_lint, span_lint_and_then};
+use crate::utils::{constants, in_external_macro, snippet, snippet_opt, span_help_and_lint, span_lint, span_lint_and_then};
/// **What it does:** Checks for structure field patterns bound to wildcards.
///
/// ```rust
/// let { a: _, b: ref b, c: _ } = ..
/// ```
-declare_lint! {
+declare_clippy_lint! {
pub UNNEEDED_FIELD_PATTERN,
- Warn,
+ style,
"struct fields bound to a wildcard instead of using `..`"
}
/// ```rust
/// fn foo(a: i32, _a: i32) {}
/// ```
-declare_lint! {
+declare_clippy_lint! {
pub DUPLICATE_UNDERSCORE_ARGUMENT,
- Warn,
+ style,
"function arguments having names which only differ by an underscore"
}
/// ```rust
/// (|| 42)()
/// ```
-declare_lint! {
+declare_clippy_lint! {
pub REDUNDANT_CLOSURE_CALL,
- Warn,
+ complexity,
"throwaway closures called in the expression they are defined"
}
/// ```rust
/// --x;
/// ```
-declare_lint! {
+declare_clippy_lint! {
pub DOUBLE_NEG,
- Warn,
+ style,
"`--x`, which is a double negation of `x` and not a pre-decrement as in C/C++"
}
/// ```rust
/// let y = 0x1a9BAcD;
/// ```
-declare_lint! {
+declare_clippy_lint! {
pub MIXED_CASE_HEX_LITERALS,
- Warn,
+ style,
"hex literals whose letter digits are not consistently upper- or lowercased"
}
/// ```rust
/// let y = 123832i32;
/// ```
-declare_lint! {
+declare_clippy_lint! {
pub UNSEPARATED_LITERAL_SUFFIX,
- Allow,
+ pedantic,
"literals whose suffix is not separated by an underscore"
}
/// ```
///
/// prints `83` (as `83 == 0o123` while `123 == 0o173`).
-declare_lint! {
+declare_clippy_lint! {
pub ZERO_PREFIXED_LITERAL,
- Warn,
+ complexity,
"integer literals starting with `0`"
}
/// }
/// }
/// ```
-declare_lint! {
+declare_clippy_lint! {
pub BUILTIN_TYPE_SHADOW,
- Warn,
+ style,
"shadowing a builtin type"
}
impl EarlyLintPass for MiscEarly {
fn check_generics(&mut self, cx: &EarlyContext, gen: &Generics) {
for param in &gen.params {
- if let GenericParam::Type(ref ty) = *param {
- let name = ty.ident.name.as_str();
+ if let GenericParamKind::Type { .. } = param.kind {
+ let name = param.ident.name.as_str();
if constants::BUILTIN_TYPES.contains(&&*name) {
span_lint(
cx,
BUILTIN_TYPE_SHADOW,
- ty.span,
+ param.ident.span,
&format!("This generic shadows the built-in type `{}`", name),
);
}
let type_name = npat.segments
.last()
.expect("A path must have at least one segment")
- .identifier
+ .ident
.name;
for field in pfields {
let mut registered_names: HashMap<String, Span> = HashMap::new();
for arg in &decl.inputs {
- if let PatKind::Ident(_, sp_ident, None) = arg.pat.node {
- let arg_name = sp_ident.node.to_string();
+ if let PatKind::Ident(_, ident, None) = arg.pat.node {
+ let arg_name = ident.name.to_string();
if arg_name.starts_with('_') {
if let Some(correspondence) = registered_names.get(&arg_name[1..]) {
}
match expr.node {
ExprKind::Call(ref paren, _) => if let ExprKind::Paren(ref closure) = paren.node {
- if let ExprKind::Closure(_, _, ref decl, ref block, _) = closure.node {
+ if let ExprKind::Closure(_, _, _, ref decl, ref block, _) = closure.node {
span_lint_and_then(
cx,
REDUNDANT_CLOSURE_CALL,
if_chain! {
if let StmtKind::Local(ref local) = w[0].node;
if let Option::Some(ref t) = local.init;
- if let ExprKind::Closure(_, _, _, _, _) = t.node;
- if let PatKind::Ident(_, sp_ident, _) = local.pat.node;
+ if let ExprKind::Closure(..) = t.node;
+ if let PatKind::Ident(_, ident, _) = local.pat.node;
if let StmtKind::Semi(ref second) = w[1].node;
if let ExprKind::Assign(_, ref call) = second.node;
if let ExprKind::Call(ref closure, _) = call.node;
if let ExprKind::Path(_, ref path) = closure.node;
then {
- if sp_ident.node == (&path.segments[0]).identifier {
+ if ident == path.segments[0].ident {
span_lint(
cx,
REDUNDANT_CLOSURE_CALL,
}
impl MiscEarly {
- fn check_lit(&self, cx: &EarlyContext, lit: &Lit) {
+ fn check_lit(self, cx: &EarlyContext, lit: &Lit) {
if_chain! {
if let LitKind::Int(value, ..) = lit.node;
if let Some(src) = snippet_opt(cx, lit.span);
let mut seen = (false, false);
for ch in src.chars() {
match ch {
- 'a' ... 'f' => seen.0 = true,
- 'A' ... 'F' => seen.1 = true,
+ 'a' ..= 'f' => seen.0 = true,
+ 'A' ..= 'F' => seen.1 = true,
'i' | 'u' => break, // start of suffix already
_ => ()
}