mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 07:00:55 +00:00
Merge branch 'master' into issue2894
This commit is contained in:
commit
5e23fcec0b
143 changed files with 878 additions and 792 deletions
|
@ -48,8 +48,6 @@ matrix:
|
|||
- env: INTEGRATION=serde-rs/serde
|
||||
- env: INTEGRATION=Geal/nom
|
||||
- env: INTEGRATION=hyperium/hyper
|
||||
- env: INTEGRATION=rust-lang/cargo
|
||||
- env: INTEGRATION=rust-lang-nursery/rls
|
||||
|
||||
script:
|
||||
- |
|
||||
|
|
|
@ -21,8 +21,8 @@ edition = "2018"
|
|||
[dependencies]
|
||||
cargo_metadata = "0.5"
|
||||
itertools = "0.7"
|
||||
lazy_static = "1.0"
|
||||
matches = "0.1.2"
|
||||
lazy_static = "1.0.2"
|
||||
matches = "0.1.7"
|
||||
quine-mc_cluskey = "0.2.2"
|
||||
regex-syntax = "0.6"
|
||||
semver = "0.9.0"
|
||||
|
@ -32,7 +32,7 @@ toml = "0.4"
|
|||
unicode-normalization = "0.1"
|
||||
pulldown-cmark = "0.1"
|
||||
url = "1.7.0"
|
||||
if_chain = "0.1"
|
||||
if_chain = "0.1.3"
|
||||
|
||||
[features]
|
||||
debugging = []
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use crate::utils::span_lint;
|
||||
use rustc::hir::*;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use std::f64::consts as f64;
|
||||
use syntax::ast::{FloatTy, Lit, LitKind};
|
||||
use syntax::symbol;
|
||||
|
@ -69,7 +70,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_lit(cx: &LateContext, lit: &Lit, e: &Expr) {
|
||||
fn check_lit(cx: &LateContext<'_, '_>, lit: &Lit, e: &Expr) {
|
||||
match lit.node {
|
||||
LitKind::Float(s, FloatTy::F32) => check_known_consts(cx, e, s, "f32"),
|
||||
LitKind::Float(s, FloatTy::F64) => check_known_consts(cx, e, s, "f64"),
|
||||
|
@ -78,7 +79,7 @@ fn check_lit(cx: &LateContext, lit: &Lit, e: &Expr) {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_known_consts(cx: &LateContext, e: &Expr, s: symbol::Symbol, module: &str) {
|
||||
fn check_known_consts(cx: &LateContext<'_, '_>, e: &Expr, s: symbol::Symbol, module: &str) {
|
||||
let s = s.as_str();
|
||||
if s.parse::<f64>().is_ok() {
|
||||
for &(constant, name, min_digits) in KNOWN_CONSTS {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use crate::utils::span_lint;
|
||||
use rustc::hir;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use syntax::codemap::Span;
|
||||
|
||||
/// **What it does:** Checks for plain integer arithmetic.
|
||||
|
|
|
@ -3,6 +3,8 @@ use crate::utils::{higher, sugg};
|
|||
use rustc::hir;
|
||||
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use syntax::ast;
|
||||
|
||||
/// **What it does:** Checks for compound assignment operations (`+=` and
|
||||
|
@ -49,8 +51,10 @@ declare_clippy_lint! {
|
|||
/// **Why is this bad?** Most likely these are bugs where one meant to write `a
|
||||
/// op= b`.
|
||||
///
|
||||
/// **Known problems:** Someone might actually mean `a op= a op b`, but that
|
||||
/// should rather be written as `a = (2 * a) op b` where applicable.
|
||||
/// **Known problems:** Clippy cannot know for sure if `a op= a op b` should have
|
||||
/// been `a = a op a op b` or `a = a op b`/`a op= b`. Therefore it suggests both.
|
||||
/// If `a op= a op b` is really the correct behaviour it should be
|
||||
/// written as `a = a op a op b` as it's less confusing.
|
||||
///
|
||||
/// **Example:**
|
||||
/// ```rust
|
||||
|
|
|
@ -7,6 +7,8 @@ use crate::utils::{
|
|||
};
|
||||
use rustc::hir::*;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use rustc::ty::{self, TyCtxt};
|
||||
use semver::Version;
|
||||
use syntax::ast::{AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem, NestedMetaItemKind};
|
||||
|
@ -39,22 +41,31 @@ declare_clippy_lint! {
|
|||
}
|
||||
|
||||
/// **What it does:** Checks for `extern crate` and `use` items annotated with
|
||||
/// lint attributes
|
||||
/// lint attributes.
|
||||
///
|
||||
/// This lint whitelists `#[allow(unused_imports)]` and `#[allow(deprecated)]` on
|
||||
/// `use` items and `#[allow(unused_imports)]` on `extern crate` items with a
|
||||
/// `#[macro_use]` attribute.
|
||||
///
|
||||
/// **Why is this bad?** Lint attributes have no effect on crate imports. Most
|
||||
/// likely a `!` was
|
||||
/// forgotten
|
||||
/// likely a `!` was forgotten.
|
||||
///
|
||||
/// **Known problems:** Technically one might allow `unused_import` on a `use`
|
||||
/// item,
|
||||
/// but it's easier to remove the unused item.
|
||||
/// **Known problems:** None.
|
||||
///
|
||||
/// **Example:**
|
||||
/// ```rust
|
||||
/// // Bad
|
||||
/// #[deny(dead_code)]
|
||||
/// extern crate foo;
|
||||
/// #[allow(unused_import)]
|
||||
/// #[forbid(dead_code)]
|
||||
/// use foo::bar;
|
||||
///
|
||||
/// // Ok
|
||||
/// #[allow(unused_imports)]
|
||||
/// use foo::baz;
|
||||
/// #[allow(unused_imports)]
|
||||
/// #[macro_use]
|
||||
/// extern crate baz;
|
||||
/// ```
|
||||
declare_clippy_lint! {
|
||||
pub USELESS_ATTRIBUTE,
|
||||
|
@ -154,17 +165,26 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
|
|||
check_attrs(cx, item.span, item.name, &item.attrs)
|
||||
}
|
||||
match item.node {
|
||||
ItemKind::ExternCrate(_) | ItemKind::Use(_, _) => {
|
||||
ItemKind::ExternCrate(..) | ItemKind::Use(..) => {
|
||||
let skip_unused_imports = item.attrs.iter().any(|attr| attr.name() == "macro_use");
|
||||
|
||||
for attr in &item.attrs {
|
||||
if let Some(ref lint_list) = attr.meta_item_list() {
|
||||
match &*attr.name().as_str() {
|
||||
"allow" | "warn" | "deny" | "forbid" => {
|
||||
// whitelist `unused_imports` and `deprecated`
|
||||
// whitelist `unused_imports` and `deprecated` for `use` items
|
||||
// and `unused_imports` for `extern crate` items with `macro_use`
|
||||
for lint in lint_list {
|
||||
if is_word(lint, "unused_imports") || is_word(lint, "deprecated") {
|
||||
if let ItemKind::Use(_, _) = item.node {
|
||||
return;
|
||||
}
|
||||
match item.node {
|
||||
ItemKind::Use(..) => if is_word(lint, "unused_imports")
|
||||
|| is_word(lint, "deprecated") {
|
||||
return
|
||||
},
|
||||
ItemKind::ExternCrate(..) => if is_word(lint, "unused_imports")
|
||||
&& skip_unused_imports {
|
||||
return
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
let line_span = last_line_of_span(cx, attr.span);
|
||||
|
@ -206,7 +226,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_relevant_item(tcx: TyCtxt, item: &Item) -> bool {
|
||||
fn is_relevant_item(tcx: TyCtxt<'_, '_, '_>, item: &Item) -> bool {
|
||||
if let ItemKind::Fn(_, _, _, eid) = item.node {
|
||||
is_relevant_expr(tcx, tcx.body_tables(eid), &tcx.hir.body(eid).value)
|
||||
} else {
|
||||
|
@ -214,14 +234,14 @@ fn is_relevant_item(tcx: TyCtxt, item: &Item) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_relevant_impl(tcx: TyCtxt, item: &ImplItem) -> bool {
|
||||
fn is_relevant_impl(tcx: TyCtxt<'_, '_, '_>, item: &ImplItem) -> bool {
|
||||
match item.node {
|
||||
ImplItemKind::Method(_, eid) => is_relevant_expr(tcx, tcx.body_tables(eid), &tcx.hir.body(eid).value),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn is_relevant_trait(tcx: TyCtxt, item: &TraitItem) -> bool {
|
||||
fn is_relevant_trait(tcx: TyCtxt<'_, '_, '_>, item: &TraitItem) -> bool {
|
||||
match item.node {
|
||||
TraitItemKind::Method(_, TraitMethod::Required(_)) => true,
|
||||
TraitItemKind::Method(_, TraitMethod::Provided(eid)) => {
|
||||
|
@ -231,7 +251,7 @@ fn is_relevant_trait(tcx: TyCtxt, item: &TraitItem) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_relevant_block(tcx: TyCtxt, tables: &ty::TypeckTables, block: &Block) -> bool {
|
||||
fn is_relevant_block(tcx: TyCtxt<'_, '_, '_>, tables: &ty::TypeckTables<'_>, block: &Block) -> bool {
|
||||
if let Some(stmt) = block.stmts.first() {
|
||||
match stmt.node {
|
||||
StmtKind::Decl(_, _) => true,
|
||||
|
@ -242,7 +262,7 @@ fn is_relevant_block(tcx: TyCtxt, tables: &ty::TypeckTables, block: &Block) -> b
|
|||
}
|
||||
}
|
||||
|
||||
fn is_relevant_expr(tcx: TyCtxt, tables: &ty::TypeckTables, expr: &Expr) -> bool {
|
||||
fn is_relevant_expr(tcx: TyCtxt<'_, '_, '_>, tables: &ty::TypeckTables<'_>, expr: &Expr) -> bool {
|
||||
match expr.node {
|
||||
ExprKind::Block(ref block, _) => is_relevant_block(tcx, tables, block),
|
||||
ExprKind::Ret(Some(ref e)) => is_relevant_expr(tcx, tables, e),
|
||||
|
@ -260,7 +280,7 @@ fn is_relevant_expr(tcx: TyCtxt, tables: &ty::TypeckTables, expr: &Expr) -> bool
|
|||
}
|
||||
}
|
||||
|
||||
fn check_attrs(cx: &LateContext, span: Span, name: Name, attrs: &[Attribute]) {
|
||||
fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attribute]) {
|
||||
if in_macro(span) {
|
||||
return;
|
||||
}
|
||||
|
@ -311,7 +331,7 @@ fn check_attrs(cx: &LateContext, span: Span, name: Name, attrs: &[Attribute]) {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_semver(cx: &LateContext, span: Span, lit: &Lit) {
|
||||
fn check_semver(cx: &LateContext<'_, '_>, span: Span, lit: &Lit) {
|
||||
if let LitKind::Str(ref is, _) = lit.node {
|
||||
if Version::parse(&is.as_str()).is_ok() {
|
||||
return;
|
||||
|
@ -338,7 +358,7 @@ fn is_word(nmi: &NestedMetaItem, expected: &str) -> bool {
|
|||
// sources that the user has no control over.
|
||||
// For some reason these attributes don't have any expansion info on them, so
|
||||
// we have to check it this way until there is a better way.
|
||||
fn is_present_in_source(cx: &LateContext, span: Span) -> bool {
|
||||
fn is_present_in_source(cx: &LateContext<'_, '_>, span: Span) -> bool {
|
||||
if let Some(snippet) = snippet_opt(cx, span) {
|
||||
if snippet.is_empty() {
|
||||
return false;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use rustc::hir::*;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use syntax::ast::LitKind;
|
||||
use syntax::codemap::Span;
|
||||
use crate::utils::{span_lint, span_lint_and_then};
|
||||
|
@ -156,7 +158,7 @@ fn invert_cmp(cmp: BinOpKind) -> BinOpKind {
|
|||
}
|
||||
|
||||
|
||||
fn check_compare(cx: &LateContext, bit_op: &Expr, cmp_op: BinOpKind, cmp_value: u128, span: Span) {
|
||||
fn check_compare(cx: &LateContext<'_, '_>, bit_op: &Expr, cmp_op: BinOpKind, cmp_value: u128, span: Span) {
|
||||
if let ExprKind::Binary(ref op, ref left, ref right) = bit_op.node {
|
||||
if op.node != BinOpKind::BitAnd && op.node != BinOpKind::BitOr {
|
||||
return;
|
||||
|
@ -167,7 +169,7 @@ fn check_compare(cx: &LateContext, bit_op: &Expr, cmp_op: BinOpKind, cmp_value:
|
|||
}
|
||||
}
|
||||
|
||||
fn check_bit_mask(cx: &LateContext, bit_op: BinOpKind, cmp_op: BinOpKind, mask_value: u128, cmp_value: u128, span: Span) {
|
||||
fn check_bit_mask(cx: &LateContext<'_, '_>, bit_op: BinOpKind, cmp_op: BinOpKind, mask_value: u128, cmp_value: u128, span: Span) {
|
||||
match cmp_op {
|
||||
BinOpKind::Eq | BinOpKind::Ne => match bit_op {
|
||||
BinOpKind::BitAnd => if mask_value & cmp_value != cmp_value {
|
||||
|
@ -268,7 +270,7 @@ fn check_bit_mask(cx: &LateContext, bit_op: BinOpKind, cmp_op: BinOpKind, mask_v
|
|||
}
|
||||
}
|
||||
|
||||
fn check_ineffective_lt(cx: &LateContext, span: Span, m: u128, c: u128, op: &str) {
|
||||
fn check_ineffective_lt(cx: &LateContext<'_, '_>, span: Span, m: u128, c: u128, op: &str) {
|
||||
if c.is_power_of_two() && m < c {
|
||||
span_lint(
|
||||
cx,
|
||||
|
@ -284,7 +286,7 @@ fn check_ineffective_lt(cx: &LateContext, span: Span, m: u128, c: u128, op: &str
|
|||
}
|
||||
}
|
||||
|
||||
fn check_ineffective_gt(cx: &LateContext, span: Span, m: u128, c: u128, op: &str) {
|
||||
fn check_ineffective_gt(cx: &LateContext<'_, '_>, span: Span, m: u128, c: u128, op: &str) {
|
||||
if (c + 1).is_power_of_two() && m <= c {
|
||||
span_lint(
|
||||
cx,
|
||||
|
@ -300,7 +302,7 @@ fn check_ineffective_gt(cx: &LateContext, span: Span, m: u128, c: u128, op: &str
|
|||
}
|
||||
}
|
||||
|
||||
fn fetch_int_literal(cx: &LateContext, lit: &Expr) -> Option<u128> {
|
||||
fn fetch_int_literal(cx: &LateContext<'_, '_>, lit: &Expr) -> Option<u128> {
|
||||
match constant(cx, cx.tables, lit)?.0 {
|
||||
Constant::Int(n) => Some(n),
|
||||
_ => None,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use rustc::hir::*;
|
||||
use crate::utils::span_lint;
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
use matches::matches;
|
||||
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use rustc::hir::*;
|
||||
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
|
||||
use crate::utils::*;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use rustc::hir::*;
|
||||
use rustc::hir::intravisit::*;
|
||||
use syntax::ast::{LitKind, NodeId, DUMMY_NODE_ID};
|
||||
|
@ -274,7 +275,7 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
|
|||
}
|
||||
|
||||
// The boolean part of the return indicates whether some simplifications have been applied.
|
||||
fn suggest(cx: &LateContext, suggestion: &Bool, terminals: &[&Expr]) -> (String, bool) {
|
||||
fn suggest(cx: &LateContext<'_, '_>, suggestion: &Bool, terminals: &[&Expr]) -> (String, bool) {
|
||||
let mut suggest_context = SuggestContext {
|
||||
terminals,
|
||||
cx,
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use rustc::hir::*;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use rustc::ty;
|
||||
use syntax::ast::{Name, UintTy};
|
||||
use crate::utils::{contains_name, get_pat_name, match_type, paths, single_segment_path, snippet, span_lint_and_sugg,
|
||||
|
@ -36,7 +38,7 @@ impl LintPass for ByteCount {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
|
||||
fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr) {
|
||||
if_chain! {
|
||||
if let ExprKind::MethodCall(ref count, _, ref count_args) = expr.node;
|
||||
if count.ident.name == "count";
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
//! This lint is **warn** by default
|
||||
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use syntax::ast;
|
||||
|
||||
use crate::utils::{in_macro, snippet_block, span_lint_and_sugg, span_lint_and_then};
|
||||
|
@ -78,14 +80,14 @@ impl LintPass for CollapsibleIf {
|
|||
}
|
||||
|
||||
impl EarlyLintPass for CollapsibleIf {
|
||||
fn check_expr(&mut self, cx: &EarlyContext, expr: &ast::Expr) {
|
||||
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) {
|
||||
if !in_macro(expr.span) {
|
||||
check_if(cx, expr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn check_if(cx: &EarlyContext, expr: &ast::Expr) {
|
||||
fn check_if(cx: &EarlyContext<'_>, expr: &ast::Expr) {
|
||||
match expr.node {
|
||||
ast::ExprKind::If(ref check, ref then, ref else_) => if let Some(ref else_) = *else_ {
|
||||
check_collapsible_maybe_if_let(cx, else_);
|
||||
|
@ -99,7 +101,7 @@ fn check_if(cx: &EarlyContext, expr: &ast::Expr) {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_collapsible_maybe_if_let(cx: &EarlyContext, else_: &ast::Expr) {
|
||||
fn check_collapsible_maybe_if_let(cx: &EarlyContext<'_>, else_: &ast::Expr) {
|
||||
if_chain! {
|
||||
if let ast::ExprKind::Block(ref block, _) = else_.node;
|
||||
if let Some(else_) = expr_block(block);
|
||||
|
@ -120,7 +122,7 @@ fn check_collapsible_maybe_if_let(cx: &EarlyContext, else_: &ast::Expr) {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_collapsible_no_if_let(cx: &EarlyContext, expr: &ast::Expr, check: &ast::Expr, then: &ast::Block) {
|
||||
fn check_collapsible_no_if_let(cx: &EarlyContext<'_>, expr: &ast::Expr, check: &ast::Expr, then: &ast::Block) {
|
||||
if_chain! {
|
||||
if let Some(inner) = expr_block(then);
|
||||
if let ast::ExprKind::If(ref check_inner, ref content, None) = inner.node;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use syntax::ast::*;
|
||||
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use crate::utils::{in_macro, snippet, span_lint_and_then};
|
||||
|
||||
/// **What it does:** Checks for constants with an explicit `'static` lifetime.
|
||||
|
@ -34,7 +35,7 @@ impl LintPass for StaticConst {
|
|||
|
||||
impl StaticConst {
|
||||
// Recursively visit types
|
||||
fn visit_type(&mut self, ty: &Ty, cx: &EarlyContext) {
|
||||
fn visit_type(&mut self, ty: &Ty, cx: &EarlyContext<'_>) {
|
||||
match ty.node {
|
||||
// Be careful of nested structures (arrays and tuples)
|
||||
TyKind::Array(ref ty, _) => {
|
||||
|
@ -78,7 +79,7 @@ impl StaticConst {
|
|||
}
|
||||
|
||||
impl EarlyLintPass for StaticConst {
|
||||
fn check_item(&mut self, cx: &EarlyContext, item: &Item) {
|
||||
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
|
||||
if !in_macro(item.span) {
|
||||
// Match only constants...
|
||||
if let ItemKind::Const(ref var_type, _) = item.node {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#![allow(float_cmp)]
|
||||
|
||||
use rustc::lint::LateContext;
|
||||
use rustc::{span_bug, bug};
|
||||
use rustc::hir::def::Def;
|
||||
use rustc::hir::*;
|
||||
use rustc::ty::{self, Ty, TyCtxt, Instance};
|
||||
|
@ -122,7 +123,7 @@ impl Hash for Constant {
|
|||
}
|
||||
|
||||
impl Constant {
|
||||
pub fn partial_cmp(tcx: TyCtxt, cmp_type: &ty::TypeVariants, left: &Self, right: &Self) -> Option<Ordering> {
|
||||
pub fn partial_cmp(tcx: TyCtxt<'_, '_, '_>, cmp_type: &ty::TypeVariants<'_>, left: &Self, right: &Self) -> Option<Ordering> {
|
||||
match (left, right) {
|
||||
(&Constant::Str(ref ls), &Constant::Str(ref rs)) => Some(ls.cmp(rs)),
|
||||
(&Constant::Char(ref l), &Constant::Char(ref r)) => Some(l.cmp(r)),
|
||||
|
@ -235,7 +236,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
|
|||
}
|
||||
}
|
||||
|
||||
fn constant_not(&self, o: &Constant, ty: ty::Ty) -> Option<Constant> {
|
||||
fn constant_not(&self, o: &Constant, ty: ty::Ty<'_>) -> Option<Constant> {
|
||||
use self::Constant::*;
|
||||
match *o {
|
||||
Bool(b) => Some(Bool(!b)),
|
||||
|
@ -251,7 +252,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
|
|||
}
|
||||
}
|
||||
|
||||
fn constant_negate(&self, o: &Constant, ty: ty::Ty) -> Option<Constant> {
|
||||
fn constant_negate(&self, o: &Constant, ty: ty::Ty<'_>) -> Option<Constant> {
|
||||
use self::Constant::*;
|
||||
match *o {
|
||||
Int(value) => {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use rustc::ty::Ty;
|
||||
use rustc::hir::*;
|
||||
use std::collections::HashMap;
|
||||
|
@ -133,7 +134,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyAndPaste {
|
|||
}
|
||||
|
||||
/// Implementation of `IF_SAME_THEN_ELSE`.
|
||||
fn lint_same_then_else(cx: &LateContext, blocks: &[&Block]) {
|
||||
fn lint_same_then_else(cx: &LateContext<'_, '_>, blocks: &[&Block]) {
|
||||
let eq: &dyn Fn(&&Block, &&Block) -> bool = &|&lhs, &rhs| -> bool { SpanlessEq::new(cx).eq_block(lhs, rhs) };
|
||||
|
||||
if let Some((i, j)) = search_same_sequenced(blocks, eq) {
|
||||
|
@ -149,7 +150,7 @@ fn lint_same_then_else(cx: &LateContext, blocks: &[&Block]) {
|
|||
}
|
||||
|
||||
/// Implementation of `IFS_SAME_COND`.
|
||||
fn lint_same_cond(cx: &LateContext, conds: &[&Expr]) {
|
||||
fn lint_same_cond(cx: &LateContext<'_, '_>, conds: &[&Expr]) {
|
||||
let hash: &dyn Fn(&&Expr) -> u64 = &|expr| -> u64 {
|
||||
let mut h = SpanlessHash::new(cx, cx.tables);
|
||||
h.hash_expr(expr);
|
||||
|
@ -171,7 +172,7 @@ fn lint_same_cond(cx: &LateContext, conds: &[&Expr]) {
|
|||
}
|
||||
|
||||
/// Implementation of `MATCH_SAME_ARMS`.
|
||||
fn lint_match_arms(cx: &LateContext, expr: &Expr) {
|
||||
fn lint_match_arms(cx: &LateContext<'_, '_>, expr: &Expr) {
|
||||
if let ExprKind::Match(_, ref arms, MatchSource::Normal) = expr.node {
|
||||
let hash = |&(_, arm): &(usize, &Arm)| -> u64 {
|
||||
let mut h = SpanlessHash::new(cx, cx.tables);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use rustc::cfg::CFG;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use rustc::hir::*;
|
||||
use rustc::ty;
|
||||
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
|
||||
|
@ -186,7 +187,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CCHelper<'a, 'tcx> {
|
|||
|
||||
#[cfg(feature = "debugging")]
|
||||
#[allow(too_many_arguments)]
|
||||
fn report_cc_bug(_: &LateContext, cc: u64, narms: u64, div: u64, shorts: u64, returns: u64, span: Span, _: NodeId) {
|
||||
fn report_cc_bug(_: &LateContext<'_, '_>, cc: u64, narms: u64, div: u64, shorts: u64, returns: u64, span: Span, _: NodeId) {
|
||||
span_bug!(
|
||||
span,
|
||||
"Clippy encountered a bug calculating cyclomatic complexity: cc = {}, arms = {}, \
|
||||
|
@ -200,7 +201,7 @@ fn report_cc_bug(_: &LateContext, cc: u64, narms: u64, div: u64, shorts: u64, re
|
|||
}
|
||||
#[cfg(not(feature = "debugging"))]
|
||||
#[allow(too_many_arguments)]
|
||||
fn report_cc_bug(cx: &LateContext, cc: u64, narms: u64, div: u64, shorts: u64, returns: u64, span: Span, id: NodeId) {
|
||||
fn report_cc_bug(cx: &LateContext<'_, '_>, cc: u64, narms: u64, div: u64, shorts: u64, returns: u64, span: Span, id: NodeId) {
|
||||
if !is_allowed(cx, CYCLOMATIC_COMPLEXITY, id) {
|
||||
cx.sess().span_note_without_error(
|
||||
span,
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use rustc::hir::*;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use rustc::ty::TypeVariants;
|
||||
|
||||
use crate::utils::{any_parent_is_automatically_derived, match_def_path, opt_def_id, paths, span_lint_and_sugg};
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use rustc::ty::{self, Ty};
|
||||
use rustc::hir::*;
|
||||
use syntax::codemap::Span;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use itertools::Itertools;
|
||||
use pulldown_cmark;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use syntax::ast;
|
||||
use syntax::codemap::{BytePos, Span};
|
||||
use syntax_pos::Pos;
|
||||
|
@ -51,11 +52,11 @@ impl LintPass for Doc {
|
|||
}
|
||||
|
||||
impl EarlyLintPass for Doc {
|
||||
fn check_crate(&mut self, cx: &EarlyContext, krate: &ast::Crate) {
|
||||
fn check_crate(&mut self, cx: &EarlyContext<'_>, krate: &ast::Crate) {
|
||||
check_attrs(cx, &self.valid_idents, &krate.attrs);
|
||||
}
|
||||
|
||||
fn check_item(&mut self, cx: &EarlyContext, item: &ast::Item) {
|
||||
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &ast::Item) {
|
||||
check_attrs(cx, &self.valid_idents, &item.attrs);
|
||||
}
|
||||
}
|
||||
|
@ -138,7 +139,7 @@ pub fn strip_doc_comment_decoration(comment: &str, span: Span) -> (String, Vec<(
|
|||
panic!("not a doc-comment: {}", comment);
|
||||
}
|
||||
|
||||
pub fn check_attrs<'a>(cx: &EarlyContext, valid_idents: &[String], attrs: &'a [ast::Attribute]) {
|
||||
pub fn check_attrs<'a>(cx: &EarlyContext<'_>, valid_idents: &[String], attrs: &'a [ast::Attribute]) {
|
||||
let mut doc = String::new();
|
||||
let mut spans = vec![];
|
||||
|
||||
|
@ -185,7 +186,7 @@ pub fn check_attrs<'a>(cx: &EarlyContext, valid_idents: &[String], attrs: &'a [a
|
|||
}
|
||||
|
||||
fn check_doc<'a, Events: Iterator<Item = (usize, pulldown_cmark::Event<'a>)>>(
|
||||
cx: &EarlyContext,
|
||||
cx: &EarlyContext<'_>,
|
||||
valid_idents: &[String],
|
||||
docs: Events,
|
||||
spans: &[(usize, Span)],
|
||||
|
@ -231,7 +232,7 @@ fn check_doc<'a, Events: Iterator<Item = (usize, pulldown_cmark::Event<'a>)>>(
|
|||
}
|
||||
}
|
||||
|
||||
fn check_text(cx: &EarlyContext, valid_idents: &[String], text: &str, span: Span) {
|
||||
fn check_text(cx: &EarlyContext<'_>, valid_idents: &[String], text: &str, span: Span) {
|
||||
for word in text.split_whitespace() {
|
||||
// Trim punctuation as in `some comment (see foo::bar).`
|
||||
// ^^
|
||||
|
@ -254,7 +255,7 @@ fn check_text(cx: &EarlyContext, valid_idents: &[String], text: &str, span: Span
|
|||
}
|
||||
}
|
||||
|
||||
fn check_word(cx: &EarlyContext, word: &str, span: Span) {
|
||||
fn check_word(cx: &EarlyContext<'_>, word: &str, span: Span) {
|
||||
/// Checks if a string is camel-case, ie. contains at least two uppercase
|
||||
/// letter (`Clippy` is
|
||||
/// ok) and one lower-case letter (`NASA` is ok). Plural are also excluded
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use rustc::hir::*;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use syntax::codemap::Span;
|
||||
|
||||
use crate::utils::{snippet, span_lint_and_sugg, SpanlessEq};
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use syntax::ast::*;
|
||||
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass};
|
||||
use rustc::{declare_lint, lint_array};
|
||||
|
||||
/// **What it does:** Checks for unnecessary double parentheses.
|
||||
///
|
||||
|
@ -30,7 +31,7 @@ impl LintPass for DoubleParens {
|
|||
}
|
||||
|
||||
impl EarlyLintPass for DoubleParens {
|
||||
fn check_expr(&mut self, cx: &EarlyContext, expr: &Expr) {
|
||||
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
|
||||
match expr.node {
|
||||
ExprKind::Paren(ref in_paren) => match in_paren.node {
|
||||
ExprKind::Paren(_) | ExprKind::Tup(_) => {
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use rustc::ty;
|
||||
use rustc::hir::*;
|
||||
use crate::utils::{is_copy, match_def_path, opt_def_id, paths, span_note_and_lint};
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use rustc::hir::*;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use syntax::codemap::Spanned;
|
||||
|
||||
use crate::consts::{constant, Constant};
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
//! lint on if expressions with an else if, but without a final else branch
|
||||
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use syntax::ast::*;
|
||||
|
||||
use crate::utils::{in_external_macro, span_lint_and_sugg};
|
||||
use crate::utils::span_lint_and_sugg;
|
||||
|
||||
/// **What it does:** Checks for usage of if expressions with an `else if` branch,
|
||||
/// but without a final `else` branch.
|
||||
|
@ -48,8 +49,8 @@ impl LintPass for ElseIfWithoutElse {
|
|||
}
|
||||
|
||||
impl EarlyLintPass for ElseIfWithoutElse {
|
||||
fn check_expr(&mut self, cx: &EarlyContext, mut item: &Expr) {
|
||||
if in_external_macro(cx, item.span) {
|
||||
fn check_expr(&mut self, cx: &EarlyContext<'_>, mut item: &Expr) {
|
||||
if in_external_macro(cx.sess(), item.span) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
//! lint when there is an enum with no variants
|
||||
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use rustc::hir::*;
|
||||
use crate::utils::span_lint_and_then;
|
||||
|
||||
|
@ -32,7 +33,7 @@ impl LintPass for EmptyEnum {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EmptyEnum {
|
||||
fn check_item(&mut self, cx: &LateContext, item: &Item) {
|
||||
fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item) {
|
||||
let did = cx.tcx.hir.local_def_id(item.id);
|
||||
if let ItemKind::Enum(..) = item.node {
|
||||
let ty = cx.tcx.type_of(did);
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use rustc::hir::*;
|
||||
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use syntax::codemap::Span;
|
||||
use crate::utils::SpanlessEq;
|
||||
use crate::utils::{get_item_name, match_type, paths, snippet, span_lint_and_then, walk_ptrs_ty};
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
//! don't fit into an `i32`
|
||||
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use rustc::hir::*;
|
||||
use rustc::ty;
|
||||
use rustc::ty::subst::Substs;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
use rustc::hir::*;
|
||||
use rustc::hir::def::Def;
|
||||
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use syntax::ast::NodeId;
|
||||
use syntax::codemap::Span;
|
||||
use crate::utils::span_lint;
|
||||
|
@ -43,7 +44,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EnumGlobUse {
|
|||
}
|
||||
|
||||
impl EnumGlobUse {
|
||||
fn lint_item(&self, cx: &LateContext, item: &Item) {
|
||||
fn lint_item(&self, cx: &LateContext<'_, '_>, item: &Item) {
|
||||
if item.vis.node.is_pub() {
|
||||
return; // re-exports are fine
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
//! lint on enum variants that are prefixed or suffixed by the same characters
|
||||
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use syntax::ast::*;
|
||||
use syntax::codemap::Span;
|
||||
use syntax::symbol::LocalInternedString;
|
||||
|
@ -148,7 +149,7 @@ fn partial_rmatch(post: &str, name: &str) -> usize {
|
|||
// FIXME: #600
|
||||
#[allow(while_let_on_iterator)]
|
||||
fn check_variant(
|
||||
cx: &EarlyContext,
|
||||
cx: &EarlyContext<'_>,
|
||||
threshold: u64,
|
||||
def: &EnumDef,
|
||||
item_name: &str,
|
||||
|
@ -239,12 +240,12 @@ fn to_camel_case(item_name: &str) -> String {
|
|||
}
|
||||
|
||||
impl EarlyLintPass for EnumVariantNames {
|
||||
fn check_item_post(&mut self, _cx: &EarlyContext, _item: &Item) {
|
||||
fn check_item_post(&mut self, _cx: &EarlyContext<'_>, _item: &Item) {
|
||||
let last = self.modules.pop();
|
||||
assert!(last.is_some());
|
||||
}
|
||||
|
||||
fn check_item(&mut self, cx: &EarlyContext, item: &Item) {
|
||||
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
|
||||
let item_name = item.ident.as_str();
|
||||
let item_name_chars = item_name.chars().count();
|
||||
let item_camel = to_camel_case(&item_name);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use rustc::hir::*;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use crate::utils::{in_macro, implements_trait, is_copy, multispan_sugg, snippet, span_lint, span_lint_and_then, SpanlessEq};
|
||||
|
||||
/// **What it does:** Checks for equal operands to comparison, logical and
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use crate::consts::{constant_simple, Constant};
|
||||
use rustc::hir::*;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use syntax::codemap::Span;
|
||||
use crate::utils::{in_macro, span_lint};
|
||||
|
||||
|
@ -49,7 +50,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ErasingOp {
|
|||
}
|
||||
}
|
||||
|
||||
fn check(cx: &LateContext, e: &Expr, span: Span) {
|
||||
fn check(cx: &LateContext<'_, '_>, e: &Expr, span: Span) {
|
||||
if let Some(Constant::Int(v)) = constant_simple(cx, cx.tables, e) {
|
||||
if v == 0 {
|
||||
span_lint(
|
||||
|
|
|
@ -2,6 +2,7 @@ use rustc::hir::*;
|
|||
use rustc::hir::intravisit as visit;
|
||||
use rustc::hir::map::Node::{NodeExpr, NodeStmt};
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use rustc::middle::expr_use_visitor::*;
|
||||
use rustc::middle::mem_categorization::{cmt_, Categorization};
|
||||
use rustc::ty::{self, Ty};
|
||||
|
@ -38,7 +39,7 @@ declare_clippy_lint! {
|
|||
"using `Box<T>` where unnecessary"
|
||||
}
|
||||
|
||||
fn is_non_trait_box(ty: Ty) -> bool {
|
||||
fn is_non_trait_box(ty: Ty<'_>) -> bool {
|
||||
ty.is_box() && !ty.boxed_ty().is_trait()
|
||||
}
|
||||
|
||||
|
@ -136,7 +137,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
fn borrow(&mut self, _: NodeId, _: Span, cmt: &cmt_<'tcx>, _: ty::Region, _: ty::BorrowKind, loan_cause: LoanCause) {
|
||||
fn borrow(&mut self, _: NodeId, _: Span, cmt: &cmt_<'tcx>, _: ty::Region<'_>, _: ty::BorrowKind, loan_cause: LoanCause) {
|
||||
if let Categorization::Local(lid) = cmt.cat {
|
||||
match loan_cause {
|
||||
// x.foo()
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use rustc::ty;
|
||||
use rustc::hir::*;
|
||||
use crate::utils::{is_adjusted, iter_input_pats, snippet_opt, span_lint_and_then};
|
||||
|
@ -45,7 +46,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EtaPass {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_closure(cx: &LateContext, expr: &Expr) {
|
||||
fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr) {
|
||||
if let ExprKind::Closure(_, ref decl, eid, _, _) = expr.node {
|
||||
let body = cx.tcx.hir.body(eid);
|
||||
let ex = &body.value;
|
||||
|
|
|
@ -2,6 +2,8 @@ use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
|
|||
use rustc::hir::*;
|
||||
use rustc::ty;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use syntax::ast;
|
||||
use crate::utils::{get_parent_expr, span_lint, span_note_and_lint};
|
||||
|
||||
|
@ -173,7 +175,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> {
|
|||
/// logical operators are considered to have a defined evaluation order.
|
||||
///
|
||||
/// When such a read is found, the lint is triggered.
|
||||
fn check_for_unsequenced_reads(vis: &mut ReadVisitor) {
|
||||
fn check_for_unsequenced_reads(vis: &mut ReadVisitor<'_, '_>) {
|
||||
let map = &vis.cx.tcx.hir;
|
||||
let mut cur_id = vis.write_expr.id;
|
||||
loop {
|
||||
|
@ -346,7 +348,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
/// Returns true if `expr` is the LHS of an assignment, like `expr = ...`.
|
||||
fn is_in_assignment_position(cx: &LateContext, expr: &Expr) -> bool {
|
||||
fn is_in_assignment_position(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
|
||||
if let Some(parent) = get_parent_expr(cx, expr) {
|
||||
if let ExprKind::Assign(ref lhs, _) = parent.node {
|
||||
return lhs.id == expr.id;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use rustc::hir;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use rustc::ty::TypeVariants;
|
||||
use std::f32;
|
||||
use std::f64;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use rustc::hir::*;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use crate::utils::{is_expn_of, match_def_path, resolve_node, span_lint};
|
||||
use crate::utils::opt_def_id;
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use rustc::hir;
|
||||
use rustc::ty;
|
||||
use syntax_pos::Span;
|
||||
|
@ -126,7 +128,7 @@ fn lint_impl_body<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, impl_span: Span, impl_it
|
|||
}
|
||||
}
|
||||
|
||||
fn match_type(tcx: ty::TyCtxt, ty: ty::Ty, path: &[&str]) -> bool {
|
||||
fn match_type(tcx: ty::TyCtxt<'_, '_, '_>, ty: ty::Ty<'_>, path: &[&str]) -> bool {
|
||||
match ty.sty {
|
||||
ty::TyAdt(adt, _) => match_def_path(tcx, adt.did, path),
|
||||
_ => false,
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use rustc::hir::*;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use rustc::ty;
|
||||
use syntax::ast::LitKind;
|
||||
use syntax_pos::Span;
|
||||
|
@ -103,7 +105,7 @@ fn check_single_piece(expr: &Expr) -> bool {
|
|||
/// ```
|
||||
/// and that type of `__arg0` is `&str` or `String`
|
||||
/// then returns the span of first element of the matched tuple
|
||||
fn get_single_string_arg(cx: &LateContext, expr: &Expr) -> Option<Span> {
|
||||
fn get_single_string_arg(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<Span> {
|
||||
if_chain! {
|
||||
if let ExprKind::AddrOf(_, ref expr) = expr.node;
|
||||
if let ExprKind::Match(ref match_expr, ref arms, _) = expr.node;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use syntax::ast;
|
||||
use crate::utils::{differing_macro_contexts, in_macro, snippet_opt, span_note_and_lint};
|
||||
use syntax::ptr::P;
|
||||
|
@ -82,7 +83,7 @@ impl LintPass for Formatting {
|
|||
}
|
||||
|
||||
impl EarlyLintPass for Formatting {
|
||||
fn check_block(&mut self, cx: &EarlyContext, block: &ast::Block) {
|
||||
fn check_block(&mut self, cx: &EarlyContext<'_>, block: &ast::Block) {
|
||||
for w in block.stmts.windows(2) {
|
||||
match (&w[0].node, &w[1].node) {
|
||||
(&ast::StmtKind::Expr(ref first), &ast::StmtKind::Expr(ref second)) |
|
||||
|
@ -94,7 +95,7 @@ impl EarlyLintPass for Formatting {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_expr(&mut self, cx: &EarlyContext, expr: &ast::Expr) {
|
||||
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) {
|
||||
check_assign(cx, expr);
|
||||
check_else_if(cx, expr);
|
||||
check_array(cx, expr);
|
||||
|
@ -102,7 +103,7 @@ impl EarlyLintPass for Formatting {
|
|||
}
|
||||
|
||||
/// Implementation of the `SUSPICIOUS_ASSIGNMENT_FORMATTING` lint.
|
||||
fn check_assign(cx: &EarlyContext, expr: &ast::Expr) {
|
||||
fn check_assign(cx: &EarlyContext<'_>, expr: &ast::Expr) {
|
||||
if let ast::ExprKind::Assign(ref lhs, ref rhs) = expr.node {
|
||||
if !differing_macro_contexts(lhs.span, rhs.span) && !in_macro(lhs.span) {
|
||||
let eq_span = lhs.span.between(rhs.span);
|
||||
|
@ -131,7 +132,7 @@ fn check_assign(cx: &EarlyContext, expr: &ast::Expr) {
|
|||
}
|
||||
|
||||
/// Implementation of the `SUSPICIOUS_ELSE_FORMATTING` lint for weird `else if`.
|
||||
fn check_else_if(cx: &EarlyContext, expr: &ast::Expr) {
|
||||
fn check_else_if(cx: &EarlyContext<'_>, expr: &ast::Expr) {
|
||||
if let Some((then, &Some(ref else_))) = unsugar_if(expr) {
|
||||
if unsugar_if(else_).is_some() && !differing_macro_contexts(then.span, else_.span) && !in_macro(then.span) {
|
||||
// this will be a span from the closing ‘}’ of the “then” block (excluding) to
|
||||
|
@ -163,7 +164,7 @@ fn check_else_if(cx: &EarlyContext, expr: &ast::Expr) {
|
|||
}
|
||||
|
||||
/// Implementation of the `POSSIBLE_MISSING_COMMA` lint for array
|
||||
fn check_array(cx: &EarlyContext, expr: &ast::Expr) {
|
||||
fn check_array(cx: &EarlyContext<'_>, expr: &ast::Expr) {
|
||||
if let ast::ExprKind::Array(ref array) = expr.node {
|
||||
for element in array {
|
||||
if let ast::ExprKind::Binary(ref op, ref lhs, _) = element.node {
|
||||
|
@ -189,7 +190,7 @@ fn check_array(cx: &EarlyContext, expr: &ast::Expr) {
|
|||
}
|
||||
|
||||
/// Implementation of the `SUSPICIOUS_ELSE_FORMATTING` lint for consecutive ifs.
|
||||
fn check_consecutive_ifs(cx: &EarlyContext, first: &ast::Expr, second: &ast::Expr) {
|
||||
fn check_consecutive_ifs(cx: &EarlyContext<'_>, first: &ast::Expr, second: &ast::Expr) {
|
||||
if !differing_macro_contexts(first.span, second.span) && !in_macro(first.span) && unsugar_if(first).is_some()
|
||||
&& unsugar_if(second).is_some()
|
||||
{
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use matches::matches;
|
||||
use rustc::hir::intravisit;
|
||||
use rustc::hir;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use rustc::ty;
|
||||
use rustc::hir::def::Def;
|
||||
use std::collections::HashSet;
|
||||
|
@ -126,7 +128,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> Functions {
|
||||
fn check_arg_number(self, cx: &LateContext, decl: &hir::FnDecl, span: Span) {
|
||||
fn check_arg_number(self, cx: &LateContext<'_, '_>, decl: &hir::FnDecl, span: Span) {
|
||||
let args = decl.inputs.len() as u64;
|
||||
if args > self.threshold {
|
||||
span_lint(
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use rustc::hir::*;
|
||||
use syntax::ast::NodeId;
|
||||
use crate::utils::{in_macro, match_def_path, match_trait_method, same_tys, snippet, span_lint_and_then};
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use crate::consts::{constant_simple, Constant};
|
||||
use rustc::hir::*;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use syntax::codemap::Span;
|
||||
use crate::utils::{in_macro, snippet, span_lint, unsext, clip};
|
||||
use rustc::ty;
|
||||
|
@ -59,7 +60,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityOp {
|
|||
}
|
||||
|
||||
#[allow(cast_possible_wrap)]
|
||||
fn check(cx: &LateContext, e: &Expr, m: i8, span: Span, arg: Span) {
|
||||
fn check(cx: &LateContext<'_, '_>, e: &Expr, m: i8, span: Span, arg: Span) {
|
||||
if let Some(Constant::Int(v)) = constant_simple(cx, cx.tables, e) {
|
||||
let check = match cx.tables.expr_ty(e).sty {
|
||||
ty::TyInt(ity) => unsext(cx.tcx, -1i128, ity),
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use rustc::hir::*;
|
||||
use crate::utils::{match_qpath, paths, snippet, span_lint_and_then};
|
||||
|
||||
|
|
|
@ -2,9 +2,10 @@
|
|||
//! on the condition
|
||||
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use syntax::ast::*;
|
||||
|
||||
use crate::utils::{in_external_macro, span_help_and_lint};
|
||||
use crate::utils::span_help_and_lint;
|
||||
|
||||
/// **What it does:** Checks for usage of `!` or `!=` in an if condition with an
|
||||
/// else branch.
|
||||
|
@ -46,8 +47,8 @@ impl LintPass for IfNotElse {
|
|||
}
|
||||
|
||||
impl EarlyLintPass for IfNotElse {
|
||||
fn check_expr(&mut self, cx: &EarlyContext, item: &Expr) {
|
||||
if in_external_macro(cx, item.span) {
|
||||
fn check_expr(&mut self, cx: &EarlyContext<'_>, item: &Expr) {
|
||||
if in_external_macro(cx.sess(), item.span) {
|
||||
return;
|
||||
}
|
||||
if let ExprKind::If(ref cond, _, Some(ref els)) = item.node {
|
||||
|
|
|
@ -6,6 +6,7 @@ use crate::utils::higher;
|
|||
use crate::utils::higher::Range;
|
||||
use rustc::hir::*;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use rustc::ty;
|
||||
use syntax::ast::RangeLimits;
|
||||
|
||||
|
@ -154,7 +155,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {
|
|||
/// the range.
|
||||
fn to_const_range<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
range: Range,
|
||||
range: Range<'_>,
|
||||
array_size: u128,
|
||||
) -> Option<(u128, u128)> {
|
||||
let s = range
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use super::utils::{get_arg_name, match_var, remove_blocks, snippet, span_lint_and_sugg};
|
||||
use rustc::hir::*;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
|
||||
/// **What it does:** Checks for matches being used to destructure a single-variant enum
|
||||
/// or tuple struct where a `let` will suffice.
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use rustc::hir::*;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use crate::utils::{get_trait_def_id, higher, implements_trait, match_qpath, paths, span_lint};
|
||||
|
||||
/// **What it does:** Checks for iteration that is guaranteed to be infinite.
|
||||
|
@ -139,7 +140,7 @@ static HEURISTICS: &[(&str, usize, Heuristic, Finiteness)] = &[
|
|||
("scan", 3, First, MaybeInfinite),
|
||||
];
|
||||
|
||||
fn is_infinite(cx: &LateContext, expr: &Expr) -> Finiteness {
|
||||
fn is_infinite(cx: &LateContext<'_, '_>, expr: &Expr) -> Finiteness {
|
||||
match expr.node {
|
||||
ExprKind::MethodCall(ref method, _, ref args) => {
|
||||
for &(name, len, heuristic, cap) in HEURISTICS.iter() {
|
||||
|
@ -203,7 +204,7 @@ static COMPLETING_METHODS: &[(&str, usize)] = &[
|
|||
("product", 1),
|
||||
];
|
||||
|
||||
fn complete_infinite_iter(cx: &LateContext, expr: &Expr) -> Finiteness {
|
||||
fn complete_infinite_iter(cx: &LateContext<'_, '_>, expr: &Expr) -> Finiteness {
|
||||
match expr.node {
|
||||
ExprKind::MethodCall(ref method, _, ref args) => {
|
||||
for &(name, len) in COMPLETING_METHODS.iter() {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use rustc::hir::*;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use std::collections::HashMap;
|
||||
use std::default::Default;
|
||||
use syntax_pos::Span;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
//! checks for `#[inline]` on trait methods without bodies
|
||||
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use rustc::hir::*;
|
||||
use syntax::ast::{Attribute, Name};
|
||||
use crate::utils::span_lint_and_then;
|
||||
|
@ -43,7 +44,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_attrs(cx: &LateContext, name: Name, attrs: &[Attribute]) {
|
||||
fn check_attrs(cx: &LateContext<'_, '_>, name: Name, attrs: &[Attribute]) {
|
||||
for attr in attrs {
|
||||
if attr.name() != "inline" {
|
||||
continue;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
//! lint on blocks unnecessarily using >= with a + 1 or - 1
|
||||
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use syntax::ast::*;
|
||||
|
||||
use crate::utils::{snippet_opt, span_lint_and_then};
|
||||
|
@ -60,7 +61,7 @@ impl IntPlusOne {
|
|||
false
|
||||
}
|
||||
|
||||
fn check_binop(&self, cx: &EarlyContext, binop: BinOpKind, lhs: &Expr, rhs: &Expr) -> Option<String> {
|
||||
fn check_binop(&self, cx: &EarlyContext<'_>, binop: BinOpKind, lhs: &Expr, rhs: &Expr) -> Option<String> {
|
||||
match (binop, &lhs.node, &rhs.node) {
|
||||
// case where `x - 1 >= ...` or `-1 + x >= ...`
|
||||
(BinOpKind::Ge, &ExprKind::Binary(ref lhskind, ref lhslhs, ref lhsrhs), _) => {
|
||||
|
@ -126,7 +127,7 @@ impl IntPlusOne {
|
|||
|
||||
fn generate_recommendation(
|
||||
&self,
|
||||
cx: &EarlyContext,
|
||||
cx: &EarlyContext<'_>,
|
||||
binop: BinOpKind,
|
||||
node: &Expr,
|
||||
other_side: &Expr,
|
||||
|
@ -149,7 +150,7 @@ impl IntPlusOne {
|
|||
None
|
||||
}
|
||||
|
||||
fn emit_warning(&self, cx: &EarlyContext, block: &Expr, recommendation: String) {
|
||||
fn emit_warning(&self, cx: &EarlyContext<'_>, block: &Expr, recommendation: String) {
|
||||
span_lint_and_then(cx, INT_PLUS_ONE, block.span, "Unnecessary `>= y + 1` or `x - 1 >=`", |db| {
|
||||
db.span_suggestion(block.span, "change `>= y + 1` to `> y` as shown", recommendation);
|
||||
});
|
||||
|
@ -157,7 +158,7 @@ impl IntPlusOne {
|
|||
}
|
||||
|
||||
impl EarlyLintPass for IntPlusOne {
|
||||
fn check_expr(&mut self, cx: &EarlyContext, item: &Expr) {
|
||||
fn check_expr(&mut self, cx: &EarlyContext<'_>, item: &Expr) {
|
||||
if let ExprKind::Binary(ref kind, ref lhs, ref rhs) = item.node {
|
||||
if let Some(ref rec) = self.check_binop(cx, kind.node, lhs, rhs) {
|
||||
self.emit_warning(cx, item, rec.clone());
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use rustc::ty;
|
||||
use rustc::hir::*;
|
||||
use crate::utils::{match_def_path, opt_def_id, paths, span_help_and_lint};
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
//! lint when items are used after statements
|
||||
|
||||
use matches::matches;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use syntax::ast::*;
|
||||
use crate::utils::{in_macro, span_lint};
|
||||
|
||||
|
@ -41,7 +43,7 @@ impl LintPass for ItemsAfterStatements {
|
|||
}
|
||||
|
||||
impl EarlyLintPass for ItemsAfterStatements {
|
||||
fn check_block(&mut self, cx: &EarlyContext, item: &Block) {
|
||||
fn check_block(&mut self, cx: &EarlyContext<'_>, item: &Block) {
|
||||
if in_macro(item.span) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
//! lint when there is a large size difference between variants on an enum
|
||||
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use rustc::hir::*;
|
||||
use crate::utils::{snippet_opt, span_lint_and_then};
|
||||
use rustc::ty::layout::LayoutOf;
|
||||
|
@ -47,7 +48,7 @@ impl LintPass for LargeEnumVariant {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeEnumVariant {
|
||||
fn check_item(&mut self, cx: &LateContext, item: &Item) {
|
||||
fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item) {
|
||||
let did = cx.tcx.hir.local_def_id(item.id);
|
||||
if let ItemKind::Enum(ref def, _) = item.node {
|
||||
let ty = cx.tcx.type_of(did);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use rustc::hir::def_id::DefId;
|
||||
use rustc::hir::*;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use rustc::ty;
|
||||
use std::collections::HashSet;
|
||||
use syntax::ast::{Lit, LitKind, Name};
|
||||
|
@ -105,8 +106,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LenZero {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_trait_items(cx: &LateContext, visited_trait: &Item, trait_items: &[TraitItemRef]) {
|
||||
fn is_named_self(cx: &LateContext, item: &TraitItemRef, name: &str) -> bool {
|
||||
fn check_trait_items(cx: &LateContext<'_, '_>, visited_trait: &Item, trait_items: &[TraitItemRef]) {
|
||||
fn is_named_self(cx: &LateContext<'_, '_>, item: &TraitItemRef, name: &str) -> bool {
|
||||
item.ident.name == name && if let AssociatedItemKind::Method { has_self } = item.kind {
|
||||
has_self && {
|
||||
let did = cx.tcx.hir.local_def_id(item.id.node_id);
|
||||
|
@ -118,7 +119,7 @@ fn check_trait_items(cx: &LateContext, visited_trait: &Item, trait_items: &[Trai
|
|||
}
|
||||
|
||||
// fill the set with current and super traits
|
||||
fn fill_trait_set(traitt: DefId, set: &mut HashSet<DefId>, cx: &LateContext) {
|
||||
fn fill_trait_set(traitt: DefId, set: &mut HashSet<DefId>, cx: &LateContext<'_, '_>) {
|
||||
if set.insert(traitt) {
|
||||
for supertrait in ::rustc::traits::supertrait_def_ids(cx.tcx, traitt) {
|
||||
fill_trait_set(supertrait, set, cx);
|
||||
|
@ -153,8 +154,8 @@ fn check_trait_items(cx: &LateContext, visited_trait: &Item, trait_items: &[Trai
|
|||
}
|
||||
}
|
||||
|
||||
fn check_impl_items(cx: &LateContext, item: &Item, impl_items: &[ImplItemRef]) {
|
||||
fn is_named_self(cx: &LateContext, item: &ImplItemRef, name: &str) -> bool {
|
||||
fn check_impl_items(cx: &LateContext<'_, '_>, item: &Item, impl_items: &[ImplItemRef]) {
|
||||
fn is_named_self(cx: &LateContext<'_, '_>, item: &ImplItemRef, name: &str) -> bool {
|
||||
item.ident.name == name && if let AssociatedItemKind::Method { has_self } = item.kind {
|
||||
has_self && {
|
||||
let did = cx.tcx.hir.local_def_id(item.id.node_id);
|
||||
|
@ -193,7 +194,7 @@ fn check_impl_items(cx: &LateContext, item: &Item, impl_items: &[ImplItemRef]) {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_cmp(cx: &LateContext, span: Span, method: &Expr, lit: &Expr, op: &str, compare_to: u32) {
|
||||
fn check_cmp(cx: &LateContext<'_, '_>, span: Span, method: &Expr, lit: &Expr, op: &str, compare_to: u32) {
|
||||
if let (&ExprKind::MethodCall(ref method_path, _, ref args), &ExprKind::Lit(ref lit)) = (&method.node, &lit.node) {
|
||||
// check if we are in an is_empty() method
|
||||
if let Some(name) = get_item_name(cx, method) {
|
||||
|
@ -206,7 +207,7 @@ fn check_cmp(cx: &LateContext, span: Span, method: &Expr, lit: &Expr, op: &str,
|
|||
}
|
||||
}
|
||||
|
||||
fn check_len(cx: &LateContext, span: Span, method_name: Name, args: &[Expr], lit: &Lit, op: &str, compare_to: u32) {
|
||||
fn check_len(cx: &LateContext<'_, '_>, span: Span, method_name: Name, args: &[Expr], lit: &Lit, op: &str, compare_to: u32) {
|
||||
if let Spanned {
|
||||
node: LitKind::Int(lit, _),
|
||||
..
|
||||
|
@ -231,9 +232,9 @@ fn check_len(cx: &LateContext, span: Span, method_name: Name, args: &[Expr], lit
|
|||
}
|
||||
|
||||
/// Check if this type has an `is_empty` method.
|
||||
fn has_is_empty(cx: &LateContext, expr: &Expr) -> bool {
|
||||
fn has_is_empty(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
|
||||
/// Get an `AssociatedItem` and return true if it matches `is_empty(self)`.
|
||||
fn is_is_empty(cx: &LateContext, item: &ty::AssociatedItem) -> bool {
|
||||
fn is_is_empty(cx: &LateContext<'_, '_>, item: &ty::AssociatedItem) -> bool {
|
||||
if let ty::AssociatedKind::Method = item.kind {
|
||||
if item.ident.name == "is_empty" {
|
||||
let sig = cx.tcx.fn_sig(item.def_id);
|
||||
|
@ -248,7 +249,7 @@ fn has_is_empty(cx: &LateContext, expr: &Expr) -> bool {
|
|||
}
|
||||
|
||||
/// Check the inherent impl's items for an `is_empty(self)` method.
|
||||
fn has_is_empty_impl(cx: &LateContext, id: DefId) -> bool {
|
||||
fn has_is_empty_impl(cx: &LateContext<'_, '_>, id: DefId) -> bool {
|
||||
cx.tcx.inherent_impls(id).iter().any(|imp| {
|
||||
cx.tcx
|
||||
.associated_items(*imp)
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use rustc::hir;
|
||||
use rustc::hir::BindingAnnotation;
|
||||
use rustc::hir::def::Def;
|
||||
|
|
|
@ -14,54 +14,41 @@
|
|||
#![feature(rust_2018_preview)]
|
||||
#![warn(rust_2018_idioms)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate rustc;
|
||||
|
||||
use toml;
|
||||
use rustc_plugin;
|
||||
use rustc;
|
||||
|
||||
#[macro_use]
|
||||
extern crate matches as matches_macro;
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
||||
#[macro_use]
|
||||
extern crate if_chain;
|
||||
|
||||
macro_rules! declare_clippy_lint {
|
||||
{ pub $name:tt, style, $description:tt } => {
|
||||
declare_lint! { pub $name, Warn, $description }
|
||||
declare_lint! { pub $name, Warn, $description, report_in_external_macro: true }
|
||||
};
|
||||
{ pub $name:tt, correctness, $description:tt } => {
|
||||
declare_lint! { pub $name, Deny, $description }
|
||||
declare_lint! { pub $name, Deny, $description, report_in_external_macro: true }
|
||||
};
|
||||
{ pub $name:tt, complexity, $description:tt } => {
|
||||
declare_lint! { pub $name, Warn, $description }
|
||||
declare_lint! { pub $name, Warn, $description, report_in_external_macro: true }
|
||||
};
|
||||
{ pub $name:tt, perf, $description:tt } => {
|
||||
declare_lint! { pub $name, Warn, $description }
|
||||
declare_lint! { pub $name, Warn, $description, report_in_external_macro: true }
|
||||
};
|
||||
{ pub $name:tt, pedantic, $description:tt } => {
|
||||
declare_lint! { pub $name, Allow, $description }
|
||||
declare_lint! { pub $name, Allow, $description, report_in_external_macro: true }
|
||||
};
|
||||
{ pub $name:tt, restriction, $description:tt } => {
|
||||
declare_lint! { pub $name, Allow, $description }
|
||||
declare_lint! { pub $name, Allow, $description, report_in_external_macro: true }
|
||||
};
|
||||
{ pub $name:tt, cargo, $description:tt } => {
|
||||
declare_lint! { pub $name, Allow, $description }
|
||||
declare_lint! { pub $name, Allow, $description, report_in_external_macro: true }
|
||||
};
|
||||
{ pub $name:tt, nursery, $description:tt } => {
|
||||
declare_lint! { pub $name, Allow, $description }
|
||||
declare_lint! { pub $name, Allow, $description, report_in_external_macro: true }
|
||||
};
|
||||
{ pub $name:tt, internal, $description:tt } => {
|
||||
declare_lint! { pub $name, Allow, $description }
|
||||
declare_lint! { pub $name, Allow, $description, report_in_external_macro: true }
|
||||
};
|
||||
{ pub $name:tt, internal_warn, $description:tt } => {
|
||||
declare_lint! { pub $name, Warn, $description }
|
||||
declare_lint! { pub $name, Warn, $description, report_in_external_macro: true }
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -189,8 +176,12 @@ mod reexport {
|
|||
crate use syntax::ast::{Name, NodeId};
|
||||
}
|
||||
|
||||
pub fn register_pre_expansion_lints(session: &rustc::session::Session, store: &mut rustc::lint::LintStore) {
|
||||
store.register_pre_expansion_pass(Some(session), box write::Pass);
|
||||
}
|
||||
|
||||
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||
pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
|
||||
pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>) {
|
||||
let conf = match utils::conf::file_from_args(reg.args()) {
|
||||
Ok(file_name) => {
|
||||
// if the user specified a file, it must exist, otherwise default to `clippy.toml` but
|
||||
|
@ -334,7 +325,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
|
|||
reg.register_late_lint_pass(box strings::StringLitAsBytes);
|
||||
reg.register_late_lint_pass(box derive::Derive);
|
||||
reg.register_late_lint_pass(box types::CharLitAsU8);
|
||||
reg.register_late_lint_pass(box write::Pass);
|
||||
reg.register_late_lint_pass(box vec::Pass);
|
||||
reg.register_early_lint_pass(box non_expressive_names::NonExpressiveNames {
|
||||
single_char_binding_names_threshold: conf.single_char_binding_names_threshold,
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
use crate::reexport::*;
|
||||
use matches::matches;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use rustc::hir::def::Def;
|
||||
use rustc::hir::*;
|
||||
use rustc::hir::intravisit::*;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use syntax::codemap::Span;
|
||||
use crate::utils::{in_external_macro, last_path_segment, span_lint};
|
||||
use crate::utils::{last_path_segment, span_lint};
|
||||
use syntax::symbol::keywords;
|
||||
|
||||
/// **What it does:** Checks for lifetime annotations which can be removed by
|
||||
|
@ -96,7 +98,7 @@ fn check_fn_inner<'a, 'tcx>(
|
|||
generics: &'tcx Generics,
|
||||
span: Span,
|
||||
) {
|
||||
if in_external_macro(cx, span) || has_where_lifetimes(cx, &generics.where_clause) {
|
||||
if in_external_macro(cx.sess(), span) || has_where_lifetimes(cx, &generics.where_clause) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,9 +2,11 @@
|
|||
//! floating-point literal expressions.
|
||||
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use syntax::ast::*;
|
||||
use syntax_pos;
|
||||
use crate::utils::{in_external_macro, snippet_opt, span_lint_and_sugg};
|
||||
use crate::utils::{snippet_opt, span_lint_and_sugg};
|
||||
|
||||
/// **What it does:** Warns if a long integral or floating-point constant does
|
||||
/// not contain underscores.
|
||||
|
@ -227,7 +229,7 @@ enum WarningType {
|
|||
}
|
||||
|
||||
impl WarningType {
|
||||
crate fn display(&self, grouping_hint: &str, cx: &EarlyContext, span: syntax_pos::Span) {
|
||||
crate fn display(&self, grouping_hint: &str, cx: &EarlyContext<'_>, span: syntax_pos::Span) {
|
||||
match self {
|
||||
WarningType::UnreadableLiteral => span_lint_and_sugg(
|
||||
cx,
|
||||
|
@ -279,8 +281,8 @@ impl LintPass for LiteralDigitGrouping {
|
|||
}
|
||||
|
||||
impl EarlyLintPass for LiteralDigitGrouping {
|
||||
fn check_expr(&mut self, cx: &EarlyContext, expr: &Expr) {
|
||||
if in_external_macro(cx, expr.span) {
|
||||
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
|
||||
if in_external_macro(cx.sess(), expr.span) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -291,7 +293,7 @@ impl EarlyLintPass for LiteralDigitGrouping {
|
|||
}
|
||||
|
||||
impl LiteralDigitGrouping {
|
||||
fn check_lit(self, cx: &EarlyContext, lit: &Lit) {
|
||||
fn check_lit(self, cx: &EarlyContext<'_>, lit: &Lit) {
|
||||
match lit.node {
|
||||
LitKind::Int(..) => {
|
||||
// Lint integral literals.
|
||||
|
@ -419,8 +421,8 @@ impl LintPass for LiteralRepresentation {
|
|||
}
|
||||
|
||||
impl EarlyLintPass for LiteralRepresentation {
|
||||
fn check_expr(&mut self, cx: &EarlyContext, expr: &Expr) {
|
||||
if in_external_macro(cx, expr.span) {
|
||||
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
|
||||
if in_external_macro(cx.sess(), expr.span) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -436,7 +438,7 @@ impl LiteralRepresentation {
|
|||
threshold,
|
||||
}
|
||||
}
|
||||
fn check_lit(self, cx: &EarlyContext, lit: &Lit) {
|
||||
fn check_lit(self, cx: &EarlyContext<'_>, lit: &Lit) {
|
||||
// Lint integral literals.
|
||||
if_chain! {
|
||||
if let LitKind::Int(..) = lit.node;
|
||||
|
|
|
@ -6,6 +6,8 @@ use rustc::hir::def_id;
|
|||
use rustc::hir::intravisit::{walk_block, walk_decl, walk_expr, walk_pat, walk_stmt, NestedVisitorMap, Visitor};
|
||||
use rustc::hir::map::Node::{NodeBlock, NodeExpr, NodeStmt};
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use rustc::middle::region;
|
||||
// use rustc::middle::region::CodeExtent;
|
||||
use rustc::middle::expr_use_visitor::*;
|
||||
|
@ -21,7 +23,7 @@ use crate::utils::{sugg, sext};
|
|||
use crate::utils::usage::mutated_variables;
|
||||
use crate::consts::{constant, Constant};
|
||||
|
||||
use crate::utils::{get_enclosing_block, get_parent_expr, higher, in_external_macro, is_integer_literal, is_refutable,
|
||||
use crate::utils::{get_enclosing_block, get_parent_expr, higher, is_integer_literal, is_refutable,
|
||||
last_path_segment, match_trait_method, match_type, match_var, multispan_sugg, snippet, snippet_opt,
|
||||
span_help_and_lint, span_lint, span_lint_and_sugg, span_lint_and_then, SpanlessEq};
|
||||
use crate::utils::paths;
|
||||
|
@ -448,7 +450,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
|||
&& arms[1].pats.len() == 1 && arms[1].guard.is_none()
|
||||
&& is_simple_break_expr(&arms[1].body)
|
||||
{
|
||||
if in_external_macro(cx, expr.span) {
|
||||
if in_external_macro(cx.sess(), expr.span) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -741,7 +743,7 @@ struct FixedOffsetVar {
|
|||
offset: Offset,
|
||||
}
|
||||
|
||||
fn is_slice_like<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty) -> bool {
|
||||
fn is_slice_like<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'_>) -> bool {
|
||||
let is_slice = match ty.sty {
|
||||
ty::TyRef(_, subty, _) => is_slice_like(cx, subty),
|
||||
ty::TySlice(..) | ty::TyArray(..) => true,
|
||||
|
@ -1183,7 +1185,7 @@ fn check_for_loop_reverse_range<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arg: &'tcx
|
|||
}
|
||||
}
|
||||
|
||||
fn lint_iter_method(cx: &LateContext, args: &[Expr], arg: &Expr, method_name: &str) {
|
||||
fn lint_iter_method(cx: &LateContext<'_, '_>, args: &[Expr], arg: &Expr, method_name: &str) {
|
||||
let object = snippet(cx, args[0].span, "_");
|
||||
let muta = if method_name == "iter_mut" {
|
||||
"mut "
|
||||
|
@ -1201,7 +1203,7 @@ fn lint_iter_method(cx: &LateContext, args: &[Expr], arg: &Expr, method_name: &s
|
|||
)
|
||||
}
|
||||
|
||||
fn check_for_loop_arg(cx: &LateContext, pat: &Pat, arg: &Expr, expr: &Expr) {
|
||||
fn check_for_loop_arg(cx: &LateContext<'_, '_>, pat: &Pat, arg: &Expr, expr: &Expr) {
|
||||
let mut next_loop_linted = false; // whether or not ITER_NEXT_LOOP lint was used
|
||||
if let ExprKind::MethodCall(ref method, _, ref args) = arg.node {
|
||||
// just the receiver, no arguments
|
||||
|
@ -1256,7 +1258,7 @@ fn check_for_loop_arg(cx: &LateContext, pat: &Pat, arg: &Expr, expr: &Expr) {
|
|||
}
|
||||
|
||||
/// Check for `for` loops over `Option`s and `Results`
|
||||
fn check_arg_type(cx: &LateContext, pat: &Pat, arg: &Expr) {
|
||||
fn check_arg_type(cx: &LateContext<'_, '_>, pat: &Pat, arg: &Expr) {
|
||||
let ty = cx.tables.expr_ty(arg);
|
||||
if match_type(cx, ty, &paths::OPTION) {
|
||||
span_help_and_lint(
|
||||
|
@ -1418,7 +1420,7 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate {
|
|||
|
||||
fn consume_pat(&mut self, _: &Pat, _: &cmt_<'tcx>, _: ConsumeMode) {}
|
||||
|
||||
fn borrow(&mut self, _: NodeId, sp: Span, cmt: &cmt_<'tcx>, _: ty::Region, bk: ty::BorrowKind, _: LoanCause) {
|
||||
fn borrow(&mut self, _: NodeId, sp: Span, cmt: &cmt_<'tcx>, _: ty::Region<'_>, bk: ty::BorrowKind, _: LoanCause) {
|
||||
if let ty::BorrowKind::MutBorrow = bk {
|
||||
if let Categorization::Local(id) = cmt.cat {
|
||||
if Some(id) == self.node_id_low {
|
||||
|
@ -1451,7 +1453,7 @@ impl<'tcx> MutatePairDelegate {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_for_mut_range_bound(cx: &LateContext, arg: &Expr, body: &Expr) {
|
||||
fn check_for_mut_range_bound(cx: &LateContext<'_, '_>, arg: &Expr, body: &Expr) {
|
||||
if let Some(higher::Range {
|
||||
start: Some(start),
|
||||
end: Some(end),
|
||||
|
@ -1470,7 +1472,7 @@ fn check_for_mut_range_bound(cx: &LateContext, arg: &Expr, body: &Expr) {
|
|||
}
|
||||
}
|
||||
|
||||
fn mut_warn_with_span(cx: &LateContext, span: Option<Span>) {
|
||||
fn mut_warn_with_span(cx: &LateContext<'_, '_>, span: Option<Span>) {
|
||||
if let Some(sp) = span {
|
||||
span_lint(
|
||||
cx,
|
||||
|
@ -1481,7 +1483,7 @@ fn mut_warn_with_span(cx: &LateContext, span: Option<Span>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_for_mutability(cx: &LateContext, bound: &Expr) -> Option<NodeId> {
|
||||
fn check_for_mutability(cx: &LateContext<'_, '_>, bound: &Expr) -> Option<NodeId> {
|
||||
if_chain! {
|
||||
if let ExprKind::Path(ref qpath) = bound.node;
|
||||
if let QPath::Resolved(None, _) = *qpath;
|
||||
|
@ -1503,7 +1505,7 @@ fn check_for_mutability(cx: &LateContext, bound: &Expr) -> Option<NodeId> {
|
|||
None
|
||||
}
|
||||
|
||||
fn check_for_mutation(cx: &LateContext, body: &Expr, bound_ids: &[Option<NodeId>]) -> (Option<Span>, Option<Span>) {
|
||||
fn check_for_mutation(cx: &LateContext<'_, '_>, body: &Expr, bound_ids: &[Option<NodeId>]) -> (Option<Span>, Option<Span>) {
|
||||
let mut delegate = MutatePairDelegate {
|
||||
node_id_low: bound_ids[0],
|
||||
node_id_high: bound_ids[1],
|
||||
|
@ -1780,7 +1782,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarUsedAfterLoopVisitor<'a, 'tcx> {
|
|||
/// Return true if the type of expr is one that provides `IntoIterator` impls
|
||||
/// for `&T` and `&mut T`, such as `Vec`.
|
||||
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||
fn is_ref_iterable_type(cx: &LateContext, e: &Expr) -> bool {
|
||||
fn is_ref_iterable_type(cx: &LateContext<'_, '_>, e: &Expr) -> bool {
|
||||
// no walk_ptrs_ty: calling iter() on a reference can make sense because it
|
||||
// will allow further borrows afterwards
|
||||
let ty = cx.tables.expr_ty(e);
|
||||
|
@ -1795,7 +1797,7 @@ fn is_ref_iterable_type(cx: &LateContext, e: &Expr) -> bool {
|
|||
match_type(cx, ty, &paths::BTREESET)
|
||||
}
|
||||
|
||||
fn is_iterable_array(ty: Ty, cx: &LateContext) -> bool {
|
||||
fn is_iterable_array(ty: Ty<'_>, cx: &LateContext<'_, '_>) -> bool {
|
||||
// IntoIterator is currently only implemented for array sizes <= 32 in rustc
|
||||
match ty.sty {
|
||||
ty::TyArray(_, n) => (0..=32).contains(&n.assert_usize(cx.tcx).expect("array length")),
|
||||
|
@ -2004,7 +2006,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn var_def_id(cx: &LateContext, expr: &Expr) -> Option<NodeId> {
|
||||
fn var_def_id(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<NodeId> {
|
||||
if let ExprKind::Path(ref qpath) = expr.node {
|
||||
let path_res = cx.tables.qpath_def(qpath, expr.hir_id);
|
||||
if let Def::Local(node_id) = path_res {
|
||||
|
@ -2028,7 +2030,7 @@ fn is_conditional(expr: &Expr) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_nested(cx: &LateContext, match_expr: &Expr, iter_expr: &Expr) -> bool {
|
||||
fn is_nested(cx: &LateContext<'_, '_>, match_expr: &Expr, iter_expr: &Expr) -> bool {
|
||||
if_chain! {
|
||||
if let Some(loop_block) = get_enclosing_block(cx, match_expr.id);
|
||||
if let Some(map::Node::NodeExpr(loop_expr)) = cx.tcx.hir.find(cx.tcx.hir.get_parent_node(loop_block.id));
|
||||
|
@ -2039,7 +2041,7 @@ fn is_nested(cx: &LateContext, match_expr: &Expr, iter_expr: &Expr) -> bool {
|
|||
false
|
||||
}
|
||||
|
||||
fn is_loop_nested(cx: &LateContext, loop_expr: &Expr, iter_expr: &Expr) -> bool {
|
||||
fn is_loop_nested(cx: &LateContext<'_, '_>, loop_expr: &Expr, iter_expr: &Expr) -> bool {
|
||||
let mut id = loop_expr.id;
|
||||
let iter_name = if let Some(name) = path_name(iter_expr) {
|
||||
name
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use rustc::hir::*;
|
||||
use rustc::ty;
|
||||
use syntax::ast;
|
||||
|
@ -98,7 +100,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
|||
}
|
||||
}
|
||||
|
||||
fn expr_eq_name(cx: &LateContext, expr: &Expr, id: ast::Ident) -> bool {
|
||||
fn expr_eq_name(cx: &LateContext<'_, '_>, expr: &Expr, id: ast::Ident) -> bool {
|
||||
match expr.node {
|
||||
ExprKind::Path(QPath::Resolved(None, ref path)) => {
|
||||
let arg_segment = [
|
||||
|
@ -114,7 +116,7 @@ fn expr_eq_name(cx: &LateContext, expr: &Expr, id: ast::Ident) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_type_name(cx: &LateContext, expr: &Expr, arg: &Expr) -> Option<&'static str> {
|
||||
fn get_type_name(cx: &LateContext<'_, '_>, expr: &Expr, arg: &Expr) -> Option<&'static str> {
|
||||
if match_trait_method(cx, expr, &paths::ITERATOR) {
|
||||
Some("iterator")
|
||||
} else if match_type(cx, walk_ptrs_ty(cx.tables.expr_ty(arg)), &paths::OPTION) {
|
||||
|
@ -124,7 +126,7 @@ fn get_type_name(cx: &LateContext, expr: &Expr, arg: &Expr) -> Option<&'static s
|
|||
}
|
||||
}
|
||||
|
||||
fn only_derefs(cx: &LateContext, expr: &Expr, id: ast::Ident) -> bool {
|
||||
fn only_derefs(cx: &LateContext<'_, '_>, expr: &Expr, id: ast::Ident) -> bool {
|
||||
match expr.node {
|
||||
ExprKind::Unary(UnDeref, ref subexpr) if !is_adjusted(cx, subexpr) => only_derefs(cx, subexpr, id),
|
||||
_ => expr_eq_name(cx, expr, id),
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use rustc::hir;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use rustc::ty;
|
||||
use rustc_errors::Applicability;
|
||||
use syntax::codemap::Span;
|
||||
|
@ -82,7 +84,7 @@ impl LintPass for Pass {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_unit_type(ty: ty::Ty) -> bool {
|
||||
fn is_unit_type(ty: ty::Ty<'_>) -> bool {
|
||||
match ty.sty {
|
||||
ty::TyTuple(slice) => slice.is_empty(),
|
||||
ty::TyNever => true,
|
||||
|
@ -90,7 +92,7 @@ fn is_unit_type(ty: ty::Ty) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_unit_function(cx: &LateContext, expr: &hir::Expr) -> bool {
|
||||
fn is_unit_function(cx: &LateContext<'_, '_>, expr: &hir::Expr) -> bool {
|
||||
let ty = cx.tables.expr_ty(expr);
|
||||
|
||||
if let ty::TyFnDef(id, _) = ty.sty {
|
||||
|
@ -101,7 +103,7 @@ fn is_unit_function(cx: &LateContext, expr: &hir::Expr) -> bool {
|
|||
false
|
||||
}
|
||||
|
||||
fn is_unit_expression(cx: &LateContext, expr: &hir::Expr) -> bool {
|
||||
fn is_unit_expression(cx: &LateContext<'_, '_>, expr: &hir::Expr) -> bool {
|
||||
is_unit_type(cx.tables.expr_ty(expr))
|
||||
}
|
||||
|
||||
|
@ -109,7 +111,7 @@ fn is_unit_expression(cx: &LateContext, expr: &hir::Expr) -> bool {
|
|||
/// semicolons, which causes problems when generating a suggestion. Given an
|
||||
/// expression that evaluates to '()' or '!', recursively remove useless braces
|
||||
/// and semi-colons until is suitable for including in the suggestion template
|
||||
fn reduce_unit_expression<'a>(cx: &LateContext, expr: &'a hir::Expr) -> Option<Span> {
|
||||
fn reduce_unit_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a hir::Expr) -> Option<Span> {
|
||||
if !is_unit_expression(cx, expr) {
|
||||
return None;
|
||||
}
|
||||
|
@ -173,7 +175,7 @@ fn unit_closure<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'a hir::Expr) -> Op
|
|||
/// `y` => `_y`
|
||||
///
|
||||
/// Anything else will return `_`.
|
||||
fn let_binding_name(cx: &LateContext, var_arg: &hir::Expr) -> String {
|
||||
fn let_binding_name(cx: &LateContext<'_, '_>, var_arg: &hir::Expr) -> String {
|
||||
match &var_arg.node {
|
||||
hir::ExprKind::Field(_, _) => snippet(cx, var_arg.span, "_").replace(".", "_"),
|
||||
hir::ExprKind::Path(_) => format!("_{}", snippet(cx, var_arg.span, "")),
|
||||
|
@ -189,7 +191,7 @@ fn suggestion_msg(function_type: &str, map_type: &str) -> String {
|
|||
)
|
||||
}
|
||||
|
||||
fn lint_map_unit_fn(cx: &LateContext, stmt: &hir::Stmt, expr: &hir::Expr, map_args: &[hir::Expr]) {
|
||||
fn lint_map_unit_fn(cx: &LateContext<'_, '_>, stmt: &hir::Stmt, expr: &hir::Expr, map_args: &[hir::Expr]) {
|
||||
let var_arg = &map_args[0];
|
||||
let fn_arg = &map_args[1];
|
||||
|
||||
|
@ -242,7 +244,7 @@ fn lint_map_unit_fn(cx: &LateContext, stmt: &hir::Stmt, expr: &hir::Expr, map_ar
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
||||
fn check_stmt(&mut self, cx: &LateContext, stmt: &hir::Stmt) {
|
||||
fn check_stmt(&mut self, cx: &LateContext<'_, '_>, stmt: &hir::Stmt) {
|
||||
if in_macro(stmt.span) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
use rustc::hir::*;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use rustc::ty::{self, Ty};
|
||||
use std::cmp::Ordering;
|
||||
use std::collections::Bound;
|
||||
use syntax::ast::LitKind;
|
||||
use syntax::codemap::Span;
|
||||
use crate::utils::paths;
|
||||
use crate::utils::{expr_block, in_external_macro, is_allowed, is_expn_of, match_qpath, match_type, multispan_sugg,
|
||||
use crate::utils::{expr_block, is_allowed, is_expn_of, match_qpath, match_type, multispan_sugg,
|
||||
remove_blocks, snippet, span_lint_and_sugg, span_lint_and_then, span_note_and_lint, walk_ptrs_ty};
|
||||
use crate::utils::sugg::Sugg;
|
||||
use crate::consts::{constant, Constant};
|
||||
|
@ -181,7 +183,7 @@ impl LintPass for MatchPass {
|
|||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MatchPass {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
if in_external_macro(cx, expr.span) {
|
||||
if in_external_macro(cx.sess(), expr.span) {
|
||||
return;
|
||||
}
|
||||
if let ExprKind::Match(ref ex, ref arms, MatchSource::Normal) = expr.node {
|
||||
|
@ -198,7 +200,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MatchPass {
|
|||
}
|
||||
|
||||
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||
fn check_single_match(cx: &LateContext, ex: &Expr, arms: &[Arm], expr: &Expr) {
|
||||
fn check_single_match(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &Expr) {
|
||||
if arms.len() == 2 &&
|
||||
arms[0].pats.len() == 1 && arms[0].guard.is_none() &&
|
||||
arms[1].pats.len() == 1 && arms[1].guard.is_none() {
|
||||
|
@ -220,13 +222,13 @@ fn check_single_match(cx: &LateContext, ex: &Expr, arms: &[Arm], expr: &Expr) {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_single_match_single_pattern(cx: &LateContext, ex: &Expr, arms: &[Arm], expr: &Expr, els: Option<&Expr>) {
|
||||
fn check_single_match_single_pattern(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &Expr, els: Option<&Expr>) {
|
||||
if is_wild(&arms[1].pats[0]) {
|
||||
report_single_match_single_pattern(cx, ex, arms, expr, els);
|
||||
}
|
||||
}
|
||||
|
||||
fn report_single_match_single_pattern(cx: &LateContext, ex: &Expr, arms: &[Arm], expr: &Expr, els: Option<&Expr>) {
|
||||
fn report_single_match_single_pattern(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &Expr, els: Option<&Expr>) {
|
||||
let lint = if els.is_some() {
|
||||
SINGLE_MATCH_ELSE
|
||||
} else {
|
||||
|
@ -250,7 +252,7 @@ fn report_single_match_single_pattern(cx: &LateContext, ex: &Expr, arms: &[Arm],
|
|||
);
|
||||
}
|
||||
|
||||
fn check_single_match_opt_like(cx: &LateContext, ex: &Expr, arms: &[Arm], expr: &Expr, ty: Ty, els: Option<&Expr>) {
|
||||
fn check_single_match_opt_like(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &Expr, ty: Ty<'_>, els: Option<&Expr>) {
|
||||
// list of candidate Enums we know will never get any more members
|
||||
let candidates = &[
|
||||
(&paths::COW, "Borrowed"),
|
||||
|
@ -282,7 +284,7 @@ fn check_single_match_opt_like(cx: &LateContext, ex: &Expr, arms: &[Arm], expr:
|
|||
}
|
||||
}
|
||||
|
||||
fn check_match_bool(cx: &LateContext, ex: &Expr, arms: &[Arm], expr: &Expr) {
|
||||
fn check_match_bool(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &Expr) {
|
||||
// type of expression == bool
|
||||
if cx.tables.expr_ty(ex).sty == ty::TyBool {
|
||||
span_lint_and_then(
|
||||
|
@ -363,7 +365,7 @@ fn is_wild(pat: &impl std::ops::Deref<Target = Pat>) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_wild_err_arm(cx: &LateContext, ex: &Expr, arms: &[Arm]) {
|
||||
fn check_wild_err_arm(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm]) {
|
||||
let ex_ty = walk_ptrs_ty(cx.tables.expr_ty(ex));
|
||||
if match_type(cx, ex_ty, &paths::RESULT) {
|
||||
for arm in arms {
|
||||
|
@ -403,7 +405,7 @@ fn is_panic_block(block: &Block) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_match_ref_pats(cx: &LateContext, ex: &Expr, arms: &[Arm], expr: &Expr) {
|
||||
fn check_match_ref_pats(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &Expr) {
|
||||
if has_only_ref_pats(arms) {
|
||||
let mut suggs = Vec::new();
|
||||
let (title, msg) = if let ExprKind::AddrOf(Mutability::MutImmutable, ref inner) = ex.node {
|
||||
|
@ -434,7 +436,7 @@ fn check_match_ref_pats(cx: &LateContext, ex: &Expr, arms: &[Arm], expr: &Expr)
|
|||
}
|
||||
}
|
||||
|
||||
fn check_match_as_ref(cx: &LateContext, ex: &Expr, arms: &[Arm], expr: &Expr) {
|
||||
fn check_match_as_ref(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &Expr) {
|
||||
if arms.len() == 2 &&
|
||||
arms[0].pats.len() == 1 && arms[0].guard.is_none() &&
|
||||
arms[1].pats.len() == 1 && arms[1].guard.is_none() {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use rustc::hir::{Expr, ExprKind};
|
||||
use crate::utils::{match_def_path, opt_def_id, paths, span_lint};
|
||||
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
use matches::matches;
|
||||
use rustc::hir;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use rustc::ty::{self, Ty};
|
||||
use rustc::hir::def::Def;
|
||||
use std::borrow::Cow;
|
||||
|
@ -7,7 +10,7 @@ use std::fmt;
|
|||
use std::iter;
|
||||
use syntax::ast;
|
||||
use syntax::codemap::{Span, BytePos};
|
||||
use crate::utils::{get_arg_name, get_trait_def_id, implements_trait, in_external_macro, in_macro, is_copy, is_expn_of, is_self,
|
||||
use crate::utils::{get_arg_name, get_trait_def_id, implements_trait, in_macro, is_copy, is_expn_of, is_self,
|
||||
is_self_ty, iter_input_pats, last_path_segment, match_def_path, match_path, match_qpath, match_trait_method,
|
||||
match_type, method_chain_args, match_var, return_ty, remove_blocks, same_tys, single_segment_path, snippet,
|
||||
span_lint, span_lint_and_sugg, span_lint_and_then, span_note_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth, SpanlessEq};
|
||||
|
@ -803,7 +806,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
|||
}
|
||||
|
||||
fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, implitem: &'tcx hir::ImplItem) {
|
||||
if in_external_macro(cx, implitem.span) {
|
||||
if in_external_macro(cx.sess(), implitem.span) {
|
||||
return;
|
||||
}
|
||||
let name = implitem.ident.name;
|
||||
|
@ -873,10 +876,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
|||
}
|
||||
|
||||
/// Checks for the `OR_FUN_CALL` lint.
|
||||
fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, method_span: Span, name: &str, args: &[hir::Expr]) {
|
||||
fn lint_or_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span: Span, name: &str, args: &[hir::Expr]) {
|
||||
/// Check for `unwrap_or(T::new())` or `unwrap_or(T::default())`.
|
||||
fn check_unwrap_or_default(
|
||||
cx: &LateContext,
|
||||
cx: &LateContext<'_, '_>,
|
||||
name: &str,
|
||||
fun: &hir::Expr,
|
||||
self_expr: &hir::Expr,
|
||||
|
@ -921,7 +924,7 @@ fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, method_span: Span, name:
|
|||
/// Check for `*or(foo())`.
|
||||
#[allow(too_many_arguments)]
|
||||
fn check_general_case(
|
||||
cx: &LateContext,
|
||||
cx: &LateContext<'_, '_>,
|
||||
name: &str,
|
||||
method_span: Span,
|
||||
fun_span: Span,
|
||||
|
@ -964,7 +967,7 @@ fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, method_span: Span, name:
|
|||
return;
|
||||
}
|
||||
|
||||
let sugg: Cow<_> = match (fn_has_arguments, !or_has_args) {
|
||||
let sugg: Cow<'_, _> = match (fn_has_arguments, !or_has_args) {
|
||||
(true, _) => format!("|_| {}", snippet(cx, arg.span, "..")).into(),
|
||||
(false, false) => format!("|| {}", snippet(cx, arg.span, "..")).into(),
|
||||
(false, true) => snippet(cx, fun_span, ".."),
|
||||
|
@ -997,7 +1000,7 @@ fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, method_span: Span, name:
|
|||
}
|
||||
|
||||
/// Checks for the `EXPECT_FUN_CALL` lint.
|
||||
fn lint_expect_fun_call(cx: &LateContext, expr: &hir::Expr, method_span: Span, name: &str, args: &[hir::Expr]) {
|
||||
fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span: Span, name: &str, args: &[hir::Expr]) {
|
||||
fn extract_format_args(arg: &hir::Expr) -> Option<&hir::HirVec<hir::Expr>> {
|
||||
if let hir::ExprKind::AddrOf(_, ref addr_of) = arg.node {
|
||||
if let hir::ExprKind::Call(ref inner_fun, ref inner_args) = addr_of.node {
|
||||
|
@ -1012,7 +1015,7 @@ fn lint_expect_fun_call(cx: &LateContext, expr: &hir::Expr, method_span: Span, n
|
|||
None
|
||||
}
|
||||
|
||||
fn generate_format_arg_snippet(cx: &LateContext, a: &hir::Expr) -> String {
|
||||
fn generate_format_arg_snippet(cx: &LateContext<'_, '_>, a: &hir::Expr) -> String {
|
||||
if let hir::ExprKind::AddrOf(_, ref format_arg) = a.node {
|
||||
if let hir::ExprKind::Match(ref format_arg_expr, _, _) = format_arg.node {
|
||||
if let hir::ExprKind::Tup(ref format_arg_expr_tup) = format_arg_expr.node {
|
||||
|
@ -1025,7 +1028,7 @@ fn lint_expect_fun_call(cx: &LateContext, expr: &hir::Expr, method_span: Span, n
|
|||
}
|
||||
|
||||
fn check_general_case(
|
||||
cx: &LateContext,
|
||||
cx: &LateContext<'_, '_>,
|
||||
name: &str,
|
||||
method_span: Span,
|
||||
self_expr: &hir::Expr,
|
||||
|
@ -1076,7 +1079,7 @@ fn lint_expect_fun_call(cx: &LateContext, expr: &hir::Expr, method_span: Span, n
|
|||
return;
|
||||
}
|
||||
|
||||
let sugg: Cow<_> = snippet(cx, arg.span, "..");
|
||||
let sugg: Cow<'_, _> = snippet(cx, arg.span, "..");
|
||||
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
|
@ -1097,7 +1100,7 @@ fn lint_expect_fun_call(cx: &LateContext, expr: &hir::Expr, method_span: Span, n
|
|||
}
|
||||
|
||||
/// Checks for the `CLONE_ON_COPY` lint.
|
||||
fn lint_clone_on_copy(cx: &LateContext, expr: &hir::Expr, arg: &hir::Expr, arg_ty: Ty) {
|
||||
fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::Expr, arg_ty: Ty<'_>) {
|
||||
let ty = cx.tables.expr_ty(expr);
|
||||
if let ty::TyRef(_, inner, _) = arg_ty.sty {
|
||||
if let ty::TyRef(_, innermost, _) = inner.sty {
|
||||
|
@ -1165,7 +1168,7 @@ fn lint_clone_on_copy(cx: &LateContext, expr: &hir::Expr, arg: &hir::Expr, arg_t
|
|||
}
|
||||
}
|
||||
|
||||
fn lint_clone_on_ref_ptr(cx: &LateContext, expr: &hir::Expr, arg: &hir::Expr) {
|
||||
fn lint_clone_on_ref_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::Expr) {
|
||||
let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(arg));
|
||||
|
||||
if let ty::TyAdt(_, subst) = obj_ty.sty {
|
||||
|
@ -1191,7 +1194,7 @@ fn lint_clone_on_ref_ptr(cx: &LateContext, expr: &hir::Expr, arg: &hir::Expr) {
|
|||
}
|
||||
|
||||
|
||||
fn lint_string_extend(cx: &LateContext, expr: &hir::Expr, args: &[hir::Expr]) {
|
||||
fn lint_string_extend(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &[hir::Expr]) {
|
||||
let arg = &args[1];
|
||||
if let Some(arglists) = method_chain_args(arg, &["chars"]) {
|
||||
let target = &arglists[0][0];
|
||||
|
@ -1220,14 +1223,14 @@ fn lint_string_extend(cx: &LateContext, expr: &hir::Expr, args: &[hir::Expr]) {
|
|||
}
|
||||
}
|
||||
|
||||
fn lint_extend(cx: &LateContext, expr: &hir::Expr, args: &[hir::Expr]) {
|
||||
fn lint_extend(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &[hir::Expr]) {
|
||||
let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&args[0]));
|
||||
if match_type(cx, obj_ty, &paths::STRING) {
|
||||
lint_string_extend(cx, expr, args);
|
||||
}
|
||||
}
|
||||
|
||||
fn lint_cstring_as_ptr(cx: &LateContext, expr: &hir::Expr, new: &hir::Expr, unwrap: &hir::Expr) {
|
||||
fn lint_cstring_as_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr, new: &hir::Expr, unwrap: &hir::Expr) {
|
||||
if_chain! {
|
||||
if let hir::ExprKind::Call(ref fun, ref args) = new.node;
|
||||
if args.len() == 1;
|
||||
|
@ -1248,7 +1251,7 @@ fn lint_cstring_as_ptr(cx: &LateContext, expr: &hir::Expr, new: &hir::Expr, unwr
|
|||
}
|
||||
}
|
||||
|
||||
fn lint_iter_cloned_collect(cx: &LateContext, expr: &hir::Expr, iter_args: &[hir::Expr]) {
|
||||
fn lint_iter_cloned_collect(cx: &LateContext<'_, '_>, expr: &hir::Expr, iter_args: &[hir::Expr]) {
|
||||
if match_type(cx, cx.tables.expr_ty(expr), &paths::VEC)
|
||||
&& derefs_to_slice(cx, &iter_args[0], cx.tables.expr_ty(&iter_args[0])).is_some()
|
||||
{
|
||||
|
@ -1262,7 +1265,7 @@ fn lint_iter_cloned_collect(cx: &LateContext, expr: &hir::Expr, iter_args: &[hir
|
|||
}
|
||||
}
|
||||
|
||||
fn lint_unnecessary_fold(cx: &LateContext, expr: &hir::Expr, fold_args: &[hir::Expr]) {
|
||||
fn lint_unnecessary_fold(cx: &LateContext<'_, '_>, expr: &hir::Expr, fold_args: &[hir::Expr]) {
|
||||
// Check that this is a call to Iterator::fold rather than just some function called fold
|
||||
if !match_trait_method(cx, expr, &paths::ITERATOR) {
|
||||
return;
|
||||
|
@ -1272,7 +1275,7 @@ fn lint_unnecessary_fold(cx: &LateContext, expr: &hir::Expr, fold_args: &[hir::E
|
|||
"Expected fold_args to have three entries - the receiver, the initial value and the closure");
|
||||
|
||||
fn check_fold_with_op(
|
||||
cx: &LateContext,
|
||||
cx: &LateContext<'_, '_>,
|
||||
fold_args: &[hir::Expr],
|
||||
op: hir::BinOpKind,
|
||||
replacement_method_name: &str,
|
||||
|
@ -1350,7 +1353,7 @@ fn lint_unnecessary_fold(cx: &LateContext, expr: &hir::Expr, fold_args: &[hir::E
|
|||
};
|
||||
}
|
||||
|
||||
fn lint_iter_nth(cx: &LateContext, expr: &hir::Expr, iter_args: &[hir::Expr], is_mut: bool) {
|
||||
fn lint_iter_nth(cx: &LateContext<'_, '_>, expr: &hir::Expr, iter_args: &[hir::Expr], is_mut: bool) {
|
||||
let mut_str = if is_mut { "_mut" } else { "" };
|
||||
let caller_type = if derefs_to_slice(cx, &iter_args[0], cx.tables.expr_ty(&iter_args[0])).is_some() {
|
||||
"slice"
|
||||
|
@ -1374,7 +1377,7 @@ fn lint_iter_nth(cx: &LateContext, expr: &hir::Expr, iter_args: &[hir::Expr], is
|
|||
);
|
||||
}
|
||||
|
||||
fn lint_get_unwrap(cx: &LateContext, expr: &hir::Expr, get_args: &[hir::Expr], is_mut: bool) {
|
||||
fn lint_get_unwrap(cx: &LateContext<'_, '_>, expr: &hir::Expr, get_args: &[hir::Expr], is_mut: bool) {
|
||||
// Note: we don't want to lint `get_mut().unwrap` for HashMap or BTreeMap,
|
||||
// because they do not implement `IndexMut`
|
||||
let expr_ty = cx.tables.expr_ty(&get_args[0]);
|
||||
|
@ -1413,7 +1416,7 @@ fn lint_get_unwrap(cx: &LateContext, expr: &hir::Expr, get_args: &[hir::Expr], i
|
|||
);
|
||||
}
|
||||
|
||||
fn lint_iter_skip_next(cx: &LateContext, expr: &hir::Expr) {
|
||||
fn lint_iter_skip_next(cx: &LateContext<'_, '_>, expr: &hir::Expr) {
|
||||
// lint if caller of skip is an Iterator
|
||||
if match_trait_method(cx, expr, &paths::ITERATOR) {
|
||||
span_lint(
|
||||
|
@ -1425,8 +1428,8 @@ fn lint_iter_skip_next(cx: &LateContext, expr: &hir::Expr) {
|
|||
}
|
||||
}
|
||||
|
||||
fn derefs_to_slice(cx: &LateContext, expr: &hir::Expr, ty: Ty) -> Option<sugg::Sugg<'static>> {
|
||||
fn may_slice(cx: &LateContext, ty: Ty) -> bool {
|
||||
fn derefs_to_slice(cx: &LateContext<'_, '_>, expr: &hir::Expr, ty: Ty<'_>) -> Option<sugg::Sugg<'static>> {
|
||||
fn may_slice(cx: &LateContext<'_, '_>, ty: Ty<'_>) -> bool {
|
||||
match ty.sty {
|
||||
ty::TySlice(_) => true,
|
||||
ty::TyAdt(def, _) if def.is_box() => may_slice(cx, ty.boxed_ty()),
|
||||
|
@ -1458,7 +1461,7 @@ fn derefs_to_slice(cx: &LateContext, expr: &hir::Expr, ty: Ty) -> Option<sugg::S
|
|||
}
|
||||
|
||||
/// lint use of `unwrap()` for `Option`s and `Result`s
|
||||
fn lint_unwrap(cx: &LateContext, expr: &hir::Expr, unwrap_args: &[hir::Expr]) {
|
||||
fn lint_unwrap(cx: &LateContext<'_, '_>, expr: &hir::Expr, unwrap_args: &[hir::Expr]) {
|
||||
let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&unwrap_args[0]));
|
||||
|
||||
let mess = if match_type(cx, obj_ty, &paths::OPTION) {
|
||||
|
@ -1486,7 +1489,7 @@ fn lint_unwrap(cx: &LateContext, expr: &hir::Expr, unwrap_args: &[hir::Expr]) {
|
|||
}
|
||||
|
||||
/// lint use of `ok().expect()` for `Result`s
|
||||
fn lint_ok_expect(cx: &LateContext, expr: &hir::Expr, ok_args: &[hir::Expr]) {
|
||||
fn lint_ok_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr, ok_args: &[hir::Expr]) {
|
||||
// lint if the caller of `ok()` is a `Result`
|
||||
if match_type(cx, cx.tables.expr_ty(&ok_args[0]), &paths::RESULT) {
|
||||
let result_type = cx.tables.expr_ty(&ok_args[0]);
|
||||
|
@ -1504,7 +1507,7 @@ fn lint_ok_expect(cx: &LateContext, expr: &hir::Expr, ok_args: &[hir::Expr]) {
|
|||
}
|
||||
|
||||
/// lint use of `map().unwrap_or()` for `Option`s
|
||||
fn lint_map_unwrap_or(cx: &LateContext, expr: &hir::Expr, map_args: &[hir::Expr], unwrap_args: &[hir::Expr]) {
|
||||
fn lint_map_unwrap_or(cx: &LateContext<'_, '_>, expr: &hir::Expr, map_args: &[hir::Expr], unwrap_args: &[hir::Expr]) {
|
||||
// lint if the caller of `map()` is an `Option`
|
||||
if match_type(cx, cx.tables.expr_ty(&map_args[0]), &paths::OPTION) {
|
||||
// get snippets for args to map() and unwrap_or()
|
||||
|
@ -1762,7 +1765,7 @@ struct BinaryExprInfo<'a> {
|
|||
}
|
||||
|
||||
/// Checks for the `CHARS_NEXT_CMP` and `CHARS_LAST_CMP` lints.
|
||||
fn lint_binary_expr_with_method_call<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, info: &mut BinaryExprInfo) {
|
||||
fn lint_binary_expr_with_method_call(cx: &LateContext<'_, '_>, info: &mut BinaryExprInfo<'_>) {
|
||||
macro_rules! lint_with_both_lhs_and_rhs {
|
||||
($func:ident, $cx:expr, $info:ident) => {
|
||||
if !$func($cx, $info) {
|
||||
|
@ -1781,9 +1784,9 @@ fn lint_binary_expr_with_method_call<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, i
|
|||
}
|
||||
|
||||
/// Wrapper fn for `CHARS_NEXT_CMP` and `CHARS_NEXT_CMP` lints.
|
||||
fn lint_chars_cmp<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
info: &BinaryExprInfo,
|
||||
fn lint_chars_cmp(
|
||||
cx: &LateContext<'_, '_>,
|
||||
info: &BinaryExprInfo<'_>,
|
||||
chain_methods: &[&str],
|
||||
lint: &'static Lint,
|
||||
suggest: &str,
|
||||
|
@ -1821,12 +1824,12 @@ fn lint_chars_cmp<'a, 'tcx>(
|
|||
}
|
||||
|
||||
/// Checks for the `CHARS_NEXT_CMP` lint.
|
||||
fn lint_chars_next_cmp<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, info: &BinaryExprInfo) -> bool {
|
||||
fn lint_chars_next_cmp<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, info: &BinaryExprInfo<'_>) -> bool {
|
||||
lint_chars_cmp(cx, info, &["chars", "next"], CHARS_NEXT_CMP, "starts_with")
|
||||
}
|
||||
|
||||
/// Checks for the `CHARS_LAST_CMP` lint.
|
||||
fn lint_chars_last_cmp<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, info: &BinaryExprInfo) -> bool {
|
||||
fn lint_chars_last_cmp<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, info: &BinaryExprInfo<'_>) -> bool {
|
||||
if lint_chars_cmp(cx, info, &["chars", "last"], CHARS_NEXT_CMP, "ends_with") {
|
||||
true
|
||||
} else {
|
||||
|
@ -1837,7 +1840,7 @@ fn lint_chars_last_cmp<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, info: &BinaryExprIn
|
|||
/// Wrapper fn for `CHARS_NEXT_CMP` and `CHARS_LAST_CMP` lints with `unwrap()`.
|
||||
fn lint_chars_cmp_with_unwrap<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
info: &BinaryExprInfo,
|
||||
info: &BinaryExprInfo<'_>,
|
||||
chain_methods: &[&str],
|
||||
lint: &'static Lint,
|
||||
suggest: &str,
|
||||
|
@ -1868,12 +1871,12 @@ fn lint_chars_cmp_with_unwrap<'a, 'tcx>(
|
|||
}
|
||||
|
||||
/// Checks for the `CHARS_NEXT_CMP` lint with `unwrap()`.
|
||||
fn lint_chars_next_cmp_with_unwrap<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, info: &BinaryExprInfo) -> bool {
|
||||
fn lint_chars_next_cmp_with_unwrap<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, info: &BinaryExprInfo<'_>) -> bool {
|
||||
lint_chars_cmp_with_unwrap(cx, info, &["chars", "next", "unwrap"], CHARS_NEXT_CMP, "starts_with")
|
||||
}
|
||||
|
||||
/// Checks for the `CHARS_LAST_CMP` lint with `unwrap()`.
|
||||
fn lint_chars_last_cmp_with_unwrap<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, info: &BinaryExprInfo) -> bool {
|
||||
fn lint_chars_last_cmp_with_unwrap<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, info: &BinaryExprInfo<'_>) -> bool {
|
||||
if lint_chars_cmp_with_unwrap(cx, info, &["chars", "last", "unwrap"], CHARS_LAST_CMP, "ends_with") {
|
||||
true
|
||||
} else {
|
||||
|
@ -1904,7 +1907,7 @@ fn lint_single_char_pattern<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hi
|
|||
}
|
||||
|
||||
/// Checks for the `USELESS_ASREF` lint.
|
||||
fn lint_asref(cx: &LateContext, expr: &hir::Expr, call_name: &str, as_ref_args: &[hir::Expr]) {
|
||||
fn lint_asref(cx: &LateContext<'_, '_>, expr: &hir::Expr, call_name: &str, as_ref_args: &[hir::Expr]) {
|
||||
// when we get here, we've already checked that the call name is "as_ref" or "as_mut"
|
||||
// check if the call is to the actual `AsRef` or `AsMut` trait
|
||||
if match_trait_method(cx, expr, &paths::ASREF_TRAIT) || match_trait_method(cx, expr, &paths::ASMUT_TRAIT) {
|
||||
|
@ -1928,7 +1931,7 @@ fn lint_asref(cx: &LateContext, expr: &hir::Expr, call_name: &str, as_ref_args:
|
|||
}
|
||||
|
||||
/// Given a `Result<T, E>` type, return its error type (`E`).
|
||||
fn get_error_type<'a>(cx: &LateContext, ty: Ty<'a>) -> Option<Ty<'a>> {
|
||||
fn get_error_type<'a>(cx: &LateContext<'_, '_>, ty: Ty<'a>) -> Option<Ty<'a>> {
|
||||
if let ty::TyAdt(_, substs) = ty.sty {
|
||||
if match_type(cx, ty, &paths::RESULT) {
|
||||
substs.types().nth(1)
|
||||
|
@ -2030,7 +2033,7 @@ enum SelfKind {
|
|||
impl SelfKind {
|
||||
fn matches(
|
||||
self,
|
||||
cx: &LateContext,
|
||||
cx: &LateContext<'_, '_>,
|
||||
ty: &hir::Ty,
|
||||
arg: &hir::Arg,
|
||||
self_ty: &hir::Ty,
|
||||
|
@ -2157,7 +2160,7 @@ impl Convention {
|
|||
}
|
||||
|
||||
impl fmt::Display for Convention {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
match *self {
|
||||
Convention::Eq(this) => this.fmt(f),
|
||||
Convention::StartsWith(this) => this.fmt(f).and_then(|_| '*'.fmt(f)),
|
||||
|
@ -2174,7 +2177,7 @@ enum OutType {
|
|||
}
|
||||
|
||||
impl OutType {
|
||||
fn matches(self, cx: &LateContext, ty: &hir::FunctionRetTy) -> bool {
|
||||
fn matches(self, cx: &LateContext<'_, '_>, ty: &hir::FunctionRetTy) -> bool {
|
||||
let is_unit = |ty: &hir::Ty| SpanlessEq::new(cx).eq_ty_kind(&ty.node, &hir::TyKind::Tup(vec![].into()));
|
||||
match (self, ty) {
|
||||
(OutType::Unit, &hir::DefaultReturn(_)) => true,
|
||||
|
|
|
@ -2,6 +2,7 @@ use crate::consts::{constant_simple, Constant};
|
|||
use crate::utils::{match_def_path, opt_def_id, paths, span_lint};
|
||||
use rustc::hir::*;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use std::cmp::Ordering;
|
||||
|
||||
/// **What it does:** Checks for expressions where `std::cmp::min` and `max` are
|
||||
|
@ -65,7 +66,7 @@ enum MinMax {
|
|||
Max,
|
||||
}
|
||||
|
||||
fn min_max<'a>(cx: &LateContext, expr: &'a Expr) -> Option<(MinMax, Constant, &'a Expr)> {
|
||||
fn min_max<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr) -> Option<(MinMax, Constant, &'a Expr)> {
|
||||
if let ExprKind::Call(ref path, ref args) = expr.node {
|
||||
if let ExprKind::Path(ref qpath) = path.node {
|
||||
opt_def_id(cx.tables.qpath_def(qpath, path.hir_id)).and_then(|def_id| {
|
||||
|
@ -85,7 +86,7 @@ fn min_max<'a>(cx: &LateContext, expr: &'a Expr) -> Option<(MinMax, Constant, &'
|
|||
}
|
||||
}
|
||||
|
||||
fn fetch_const<'a>(cx: &LateContext, args: &'a [Expr], m: MinMax) -> Option<(MinMax, Constant, &'a Expr)> {
|
||||
fn fetch_const<'a>(cx: &LateContext<'_, '_>, args: &'a [Expr], m: MinMax) -> Option<(MinMax, Constant, &'a Expr)> {
|
||||
if args.len() != 2 {
|
||||
return None;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
use crate::reexport::*;
|
||||
use matches::matches;
|
||||
use rustc::hir::*;
|
||||
use rustc::hir::intravisit::FnKind;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use rustc::ty;
|
||||
use syntax::codemap::{ExpnFormat, Span};
|
||||
use crate::utils::{get_item_name, get_parent_expr, implements_trait, in_constant, in_macro, is_integer_literal,
|
||||
|
@ -430,7 +433,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_nan(cx: &LateContext, path: &Path, expr: &Expr) {
|
||||
fn check_nan(cx: &LateContext<'_, '_>, path: &Path, expr: &Expr) {
|
||||
if !in_constant(cx, expr.id) {
|
||||
if let Some(seg) = path.segments.last() {
|
||||
if seg.ident.name == "NAN" {
|
||||
|
@ -461,11 +464,11 @@ fn is_allowed<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_float(cx: &LateContext, expr: &Expr) -> bool {
|
||||
fn is_float(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
|
||||
matches!(walk_ptrs_ty(cx.tables.expr_ty(expr)).sty, ty::TyFloat(_))
|
||||
}
|
||||
|
||||
fn check_to_owned(cx: &LateContext, expr: &Expr, other: &Expr) {
|
||||
fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr, other: &Expr) {
|
||||
let (arg_ty, snip) = match expr.node {
|
||||
ExprKind::MethodCall(.., ref args) if args.len() == 1 => {
|
||||
if match_trait_method(cx, expr, &paths::TO_STRING) || match_trait_method(cx, expr, &paths::TO_OWNED) {
|
||||
|
@ -539,7 +542,7 @@ fn check_to_owned(cx: &LateContext, expr: &Expr, other: &Expr) {
|
|||
/// Heuristic to see if an expression is used. Should be compatible with
|
||||
/// `unused_variables`'s idea
|
||||
/// of what it means for an expression to be "used".
|
||||
fn is_used(cx: &LateContext, expr: &Expr) -> bool {
|
||||
fn is_used(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
|
||||
if let Some(parent) = get_parent_expr(cx, expr) {
|
||||
match parent.node {
|
||||
ExprKind::Assign(_, ref rhs) | ExprKind::AssignOp(_, _, ref rhs) => SpanlessEq::new(cx).eq_expr(rhs, expr),
|
||||
|
@ -562,14 +565,14 @@ fn in_attributes_expansion(expr: &Expr) -> bool {
|
|||
}
|
||||
|
||||
/// Test whether `def` is a variable defined outside a macro.
|
||||
fn non_macro_local(cx: &LateContext, def: &def::Def) -> bool {
|
||||
fn non_macro_local(cx: &LateContext<'_, '_>, def: &def::Def) -> bool {
|
||||
match *def {
|
||||
def::Def::Local(id) | def::Def::Upvar(id, _, _) => !in_macro(cx.tcx.hir.span(id)),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn check_cast(cx: &LateContext, span: Span, e: &Expr, ty: &Ty) {
|
||||
fn check_cast(cx: &LateContext<'_, '_>, span: Span, e: &Expr, ty: &Ty) {
|
||||
if_chain! {
|
||||
if let TyKind::Ptr(MutTy { mutbl, .. }) = ty.node;
|
||||
if let ExprKind::Lit(ref lit) = e.node;
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use std::collections::HashMap;
|
||||
use std::char;
|
||||
use syntax::ast::*;
|
||||
use syntax::codemap::Span;
|
||||
use syntax::visit::FnKind;
|
||||
use crate::utils::{constants, in_external_macro, snippet, snippet_opt, span_help_and_lint, span_lint, span_lint_and_then};
|
||||
use crate::utils::{constants, snippet, snippet_opt, span_help_and_lint, span_lint, span_lint_and_then};
|
||||
|
||||
/// **What it does:** Checks for structure field patterns bound to wildcards.
|
||||
///
|
||||
|
@ -187,7 +189,7 @@ impl LintPass for MiscEarly {
|
|||
}
|
||||
|
||||
impl EarlyLintPass for MiscEarly {
|
||||
fn check_generics(&mut self, cx: &EarlyContext, gen: &Generics) {
|
||||
fn check_generics(&mut self, cx: &EarlyContext<'_>, gen: &Generics) {
|
||||
for param in &gen.params {
|
||||
if let GenericParamKind::Type { .. } = param.kind {
|
||||
let name = param.ident.as_str();
|
||||
|
@ -203,7 +205,7 @@ impl EarlyLintPass for MiscEarly {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_pat(&mut self, cx: &EarlyContext, pat: &Pat) {
|
||||
fn check_pat(&mut self, cx: &EarlyContext<'_>, pat: &Pat) {
|
||||
if let PatKind::Struct(ref npat, ref pfields, _) = pat.node {
|
||||
let mut wilds = 0;
|
||||
let type_name = npat.segments
|
||||
|
@ -264,7 +266,7 @@ impl EarlyLintPass for MiscEarly {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_fn(&mut self, cx: &EarlyContext, _: FnKind, decl: &FnDecl, _: Span, _: NodeId) {
|
||||
fn check_fn(&mut self, cx: &EarlyContext<'_>, _: FnKind<'_>, decl: &FnDecl, _: Span, _: NodeId) {
|
||||
let mut registered_names: HashMap<String, Span> = HashMap::new();
|
||||
|
||||
for arg in &decl.inputs {
|
||||
|
@ -291,8 +293,8 @@ impl EarlyLintPass for MiscEarly {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_expr(&mut self, cx: &EarlyContext, expr: &Expr) {
|
||||
if in_external_macro(cx, expr.span) {
|
||||
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
|
||||
if in_external_macro(cx.sess(), expr.span) {
|
||||
return;
|
||||
}
|
||||
match expr.node {
|
||||
|
@ -323,7 +325,7 @@ impl EarlyLintPass for MiscEarly {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_block(&mut self, cx: &EarlyContext, block: &Block) {
|
||||
fn check_block(&mut self, cx: &EarlyContext<'_>, block: &Block) {
|
||||
for w in block.stmts.windows(2) {
|
||||
if_chain! {
|
||||
if let StmtKind::Local(ref local) = w[0].node;
|
||||
|
@ -350,7 +352,7 @@ impl EarlyLintPass for MiscEarly {
|
|||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
use rustc::hir;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use rustc::ty;
|
||||
use syntax::ast;
|
||||
use syntax::attr;
|
||||
|
@ -66,7 +67,7 @@ impl MissingDoc {
|
|||
.expect("empty doc_hidden_stack")
|
||||
}
|
||||
|
||||
fn check_missing_docs_attrs(&self, cx: &LateContext, attrs: &[ast::Attribute], sp: Span, desc: &'static str) {
|
||||
fn check_missing_docs_attrs(&self, cx: &LateContext<'_, '_>, attrs: &[ast::Attribute], sp: Span, desc: &'static str) {
|
||||
// If we're building a test harness, then warning about
|
||||
// documentation is probably not really relevant right now.
|
||||
if cx.sess().opts.test {
|
||||
|
@ -177,6 +178,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
|
|||
hir::ImplItemKind::Const(..) => "an associated constant",
|
||||
hir::ImplItemKind::Method(..) => "a method",
|
||||
hir::ImplItemKind::Type(_) => "an associated type",
|
||||
hir::ImplItemKind::Existential(_) => "an existential type",
|
||||
};
|
||||
self.check_missing_docs_attrs(cx, &impl_item.attrs, impl_item.span, desc);
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
use rustc::hir;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use syntax::ast;
|
||||
use syntax::codemap::Span;
|
||||
|
||||
|
@ -67,7 +68,7 @@ declare_clippy_lint! {
|
|||
|
||||
pub struct MissingInline;
|
||||
|
||||
fn check_missing_inline_attrs(cx: &LateContext,
|
||||
fn check_missing_inline_attrs(cx: &LateContext<'_, '_>,
|
||||
attrs: &[ast::Attribute], sp: Span, desc: &'static str) {
|
||||
let has_inline = attrs
|
||||
.iter()
|
||||
|
@ -165,7 +166,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingInline {
|
|||
let desc = match impl_item.node {
|
||||
hir::ImplItemKind::Method(..) => "a method",
|
||||
hir::ImplItemKind::Const(..) |
|
||||
hir::ImplItemKind::Type(_) => return,
|
||||
hir::ImplItemKind::Type(_) |
|
||||
hir::ImplItemKind::Existential(_) => return,
|
||||
};
|
||||
|
||||
let def_id = cx.tcx.hir.local_def_id(impl_item.id);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
//! lint on multiple versions of a crate being used
|
||||
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use syntax::ast::*;
|
||||
|
||||
use cargo_metadata;
|
||||
|
@ -38,7 +39,7 @@ impl LintPass for Pass {
|
|||
}
|
||||
|
||||
impl EarlyLintPass for Pass {
|
||||
fn check_crate(&mut self, cx: &EarlyContext, krate: &Crate) {
|
||||
fn check_crate(&mut self, cx: &EarlyContext<'_>, krate: &Crate) {
|
||||
let metadata = match cargo_metadata::metadata_deps(None, true) {
|
||||
Ok(metadata) => metadata,
|
||||
Err(_) => {
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
use rustc::hir;
|
||||
use rustc::hir::intravisit;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use rustc::ty;
|
||||
use crate::utils::{higher, in_external_macro, span_lint};
|
||||
use crate::utils::{higher, span_lint};
|
||||
|
||||
/// **What it does:** Checks for instances of `mut mut` references.
|
||||
///
|
||||
|
@ -49,7 +50,7 @@ pub struct MutVisitor<'a, 'tcx: 'a> {
|
|||
|
||||
impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
|
||||
if in_external_macro(self.cx, expr.span) {
|
||||
if in_external_macro(self.cx.sess(), expr.span) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use rustc::ty::{self, Ty};
|
||||
use rustc::ty::subst::Subst;
|
||||
use rustc::hir::*;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
//! This lint is **warn** by default
|
||||
|
||||
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use rustc::ty::{self, Ty};
|
||||
use rustc::hir::Expr;
|
||||
use syntax::ast;
|
||||
|
@ -79,7 +80,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutexAtomic {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_atomic_name(ty: Ty) -> Option<(&'static str)> {
|
||||
fn get_atomic_name(ty: Ty<'_>) -> Option<(&'static str)> {
|
||||
match ty.sty {
|
||||
ty::TyBool => Some("AtomicBool"),
|
||||
ty::TyUint(_) => Some("AtomicUsize"),
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
//! This lint is **warn** by default
|
||||
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use rustc::hir::*;
|
||||
use syntax::ast::LitKind;
|
||||
use syntax::codemap::Spanned;
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
//! This lint is **warn** by default
|
||||
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use rustc::hir::{BindingAnnotation, Expr, ExprKind, MutImmutable, Pat, PatKind};
|
||||
use rustc::ty;
|
||||
use rustc::ty::adjustment::{Adjust, Adjustment};
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
//! This lint is **warn** by default
|
||||
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use rustc::hir::{BindingAnnotation, MutImmutable, Pat, PatKind};
|
||||
use crate::utils::{in_macro, snippet, span_lint_and_then};
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
//!
|
||||
//! This lint is **warn** by default.
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use syntax::ast;
|
||||
use syntax::codemap::{original_sp, DUMMY_SP};
|
||||
use std::borrow::Cow;
|
||||
|
@ -109,7 +110,7 @@ impl LintPass for NeedlessContinue {
|
|||
}
|
||||
|
||||
impl EarlyLintPass for NeedlessContinue {
|
||||
fn check_expr(&mut self, ctx: &EarlyContext, expr: &ast::Expr) {
|
||||
fn check_expr(&mut self, ctx: &EarlyContext<'_>, expr: &ast::Expr) {
|
||||
if !in_macro(expr.span) {
|
||||
check_and_warn(ctx, expr);
|
||||
}
|
||||
|
@ -264,7 +265,7 @@ const DROP_ELSE_BLOCK_MSG: &str = "Consider dropping the else clause, and moving
|
|||
block, like so:\n";
|
||||
|
||||
|
||||
fn emit_warning<'a>(ctx: &EarlyContext, data: &'a LintData, header: &str, typ: LintType) {
|
||||
fn emit_warning<'a>(ctx: &EarlyContext<'_>, data: &'a LintData<'_>, header: &str, typ: LintType) {
|
||||
// snip is the whole *help* message that appears after the warning.
|
||||
// message is the warning message.
|
||||
// expr is the expression which the lint warning message refers to.
|
||||
|
@ -283,7 +284,7 @@ fn emit_warning<'a>(ctx: &EarlyContext, data: &'a LintData, header: &str, typ: L
|
|||
span_help_and_lint(ctx, NEEDLESS_CONTINUE, expr.span, message, &snip);
|
||||
}
|
||||
|
||||
fn suggestion_snippet_for_continue_inside_if<'a>(ctx: &EarlyContext, data: &'a LintData, header: &str) -> String {
|
||||
fn suggestion_snippet_for_continue_inside_if<'a>(ctx: &EarlyContext<'_>, data: &'a LintData<'_>, header: &str) -> String {
|
||||
let cond_code = snippet(ctx, data.if_cond.span, "..");
|
||||
|
||||
let if_code = format!("if {} {{\n continue;\n}}\n", cond_code);
|
||||
|
@ -300,7 +301,7 @@ fn suggestion_snippet_for_continue_inside_if<'a>(ctx: &EarlyContext, data: &'a L
|
|||
ret
|
||||
}
|
||||
|
||||
fn suggestion_snippet_for_continue_inside_else<'a>(ctx: &EarlyContext, data: &'a LintData, header: &str) -> String {
|
||||
fn suggestion_snippet_for_continue_inside_else<'a>(ctx: &EarlyContext<'_>, data: &'a LintData<'_>, header: &str) -> String {
|
||||
let cond_code = snippet(ctx, data.if_cond.span, "..");
|
||||
let mut if_code = format!("if {} {{\n", cond_code);
|
||||
|
||||
|
@ -331,7 +332,7 @@ fn suggestion_snippet_for_continue_inside_else<'a>(ctx: &EarlyContext, data: &'a
|
|||
ret
|
||||
}
|
||||
|
||||
fn check_and_warn<'a>(ctx: &EarlyContext, expr: &'a ast::Expr) {
|
||||
fn check_and_warn<'a>(ctx: &EarlyContext<'_>, expr: &'a ast::Expr) {
|
||||
with_loop_block(expr, |loop_block| {
|
||||
for (i, stmt) in loop_block.stmts.iter().enumerate() {
|
||||
with_if_expr(stmt, |if_expr, cond, then_block, else_expr| {
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
use matches::matches;
|
||||
use rustc::hir::*;
|
||||
use rustc::hir::map::*;
|
||||
use rustc::hir::intravisit::FnKind;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use rustc::ty::{self, RegionKind, TypeFoldable};
|
||||
use rustc::traits;
|
||||
use rustc::middle::expr_use_visitor as euv;
|
||||
|
@ -201,7 +204,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessPassByValue {
|
|||
}
|
||||
|
||||
// Dereference suggestion
|
||||
let sugg = |db: &mut DiagnosticBuilder| {
|
||||
let sugg = |db: &mut DiagnosticBuilder<'_>| {
|
||||
if let ty::TypeVariants::TyAdt(def, ..) = ty.sty {
|
||||
if let Some(span) = cx.tcx.hir.span_if_local(def.did) {
|
||||
if cx.param_env.can_type_implement_copy(cx.tcx, ty).is_ok() {
|
||||
|
@ -393,7 +396,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn borrow(&mut self, _: NodeId, _: Span, _: &mc::cmt_<'tcx>, _: ty::Region, _: ty::BorrowKind, _: euv::LoanCause) {}
|
||||
fn borrow(&mut self, _: NodeId, _: Span, _: &mc::cmt_<'tcx>, _: ty::Region<'_>, _: ty::BorrowKind, _: euv::LoanCause) {}
|
||||
|
||||
fn mutate(&mut self, _: NodeId, _: Span, _: &mc::cmt_<'tcx>, _: euv::MutateMode) {}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use rustc::ty;
|
||||
use rustc::hir::{Expr, ExprKind};
|
||||
use crate::utils::span_lint;
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
use rustc::hir::*;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
|
||||
use crate::utils::{self, paths, span_lint, in_external_macro};
|
||||
use crate::utils::{self, paths, span_lint};
|
||||
|
||||
/// **What it does:**
|
||||
/// Checks for the usage of negated comparision operators on types which only implement
|
||||
|
@ -53,7 +55,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NoNegCompOpForPartialOrd {
|
|||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
if_chain! {
|
||||
|
||||
if !in_external_macro(cx, expr.span);
|
||||
if !in_external_macro(cx.sess(), expr.span);
|
||||
if let ExprKind::Unary(UnOp::UnNot, ref inner) = expr.node;
|
||||
if let ExprKind::Binary(ref op, ref left, _) = inner.node;
|
||||
if let BinOpKind::Le | BinOpKind::Ge | BinOpKind::Lt | BinOpKind::Gt = op.node;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use rustc::hir::*;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use syntax::codemap::{Span, Spanned};
|
||||
|
||||
use crate::consts::{self, Constant};
|
||||
|
@ -44,7 +46,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NegMultiply {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_mul(cx: &LateContext, span: Span, lit: &Expr, exp: &Expr) {
|
||||
fn check_mul(cx: &LateContext<'_, '_>, span: Span, lit: &Expr, exp: &Expr) {
|
||||
if_chain! {
|
||||
if let ExprKind::Lit(ref l) = lit.node;
|
||||
if let Constant::Int(val) = consts::lit_to_constant(&l.node, cx.tables.expr_ty(lit));
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
use rustc::hir::def_id::DefId;
|
||||
use rustc::hir;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use rustc::ty::{self, Ty};
|
||||
use syntax::codemap::Span;
|
||||
use crate::utils::paths;
|
||||
use crate::utils::{get_trait_def_id, implements_trait, in_external_macro, return_ty, same_tys, span_lint_and_then};
|
||||
use crate::utils::{get_trait_def_id, implements_trait, return_ty, same_tys, span_lint_and_then};
|
||||
use crate::utils::sugg::DiagnosticBuilderExt;
|
||||
|
||||
/// **What it does:** Checks for types with a `fn new() -> Self` method and no
|
||||
|
@ -93,7 +95,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
|
|||
for assoc_item in items {
|
||||
if let hir::AssociatedItemKind::Method { has_self: false } = assoc_item.kind {
|
||||
let impl_item = cx.tcx.hir.impl_item(assoc_item.id);
|
||||
if in_external_macro(cx, impl_item.span) {
|
||||
if in_external_macro(cx.sess(), impl_item.span) {
|
||||
return;
|
||||
}
|
||||
if let hir::ImplItemKind::Method(ref sig, _) = impl_item.node {
|
||||
|
@ -155,7 +157,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
|
|||
}
|
||||
}
|
||||
|
||||
fn create_new_without_default_suggest_msg(ty: Ty) -> String {
|
||||
fn create_new_without_default_suggest_msg(ty: Ty<'_>) -> String {
|
||||
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||
format!(
|
||||
"impl Default for {} {{
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use rustc::hir::def::Def;
|
||||
use rustc::hir::{BinOpKind, BlockCheckMode, Expr, ExprKind, Stmt, StmtKind, UnsafeSource};
|
||||
use crate::utils::{has_drop, in_macro, snippet_opt, span_lint, span_lint_and_sugg};
|
||||
|
@ -40,7 +41,7 @@ declare_clippy_lint! {
|
|||
"outer expressions with no effect"
|
||||
}
|
||||
|
||||
fn has_no_effect(cx: &LateContext, expr: &Expr) -> bool {
|
||||
fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
|
||||
if in_macro(expr.span) {
|
||||
return false;
|
||||
}
|
||||
|
@ -127,7 +128,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
|||
}
|
||||
|
||||
|
||||
fn reduce_expression<'a>(cx: &LateContext, expr: &'a Expr) -> Option<Vec<&'a Expr>> {
|
||||
fn reduce_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr) -> Option<Vec<&'a Expr>> {
|
||||
if in_macro(expr.span) {
|
||||
return None;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
//! This lint is **deny** by default.
|
||||
|
||||
use rustc::lint::{LateContext, LateLintPass, Lint, LintArray, LintPass};
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use rustc::hir::*;
|
||||
use rustc::hir::def::Def;
|
||||
use rustc::ty::{self, TypeFlags};
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use syntax::codemap::Span;
|
||||
use syntax::symbol::LocalInternedString;
|
||||
use syntax::ast::*;
|
||||
|
@ -311,13 +312,13 @@ impl<'a, 'tcx> Visitor<'tcx> for SimilarNamesLocalVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl EarlyLintPass for NonExpressiveNames {
|
||||
fn check_item(&mut self, cx: &EarlyContext, item: &Item) {
|
||||
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
|
||||
if let ItemKind::Fn(ref decl, _, _, ref blk) = item.node {
|
||||
do_check(self, cx, &item.attrs, decl, blk);
|
||||
}
|
||||
}
|
||||
|
||||
fn check_impl_item(&mut self, cx: &EarlyContext, item: &ImplItem) {
|
||||
fn check_impl_item(&mut self, cx: &EarlyContext<'_>, item: &ImplItem) {
|
||||
if let ImplItemKind::Method(ref sig, ref blk) = item.node {
|
||||
do_check(self, cx, &item.attrs, &sig.decl, blk);
|
||||
}
|
||||
|
@ -325,7 +326,7 @@ impl EarlyLintPass for NonExpressiveNames {
|
|||
|
||||
}
|
||||
|
||||
fn do_check(lint: &mut NonExpressiveNames, cx: &EarlyContext, attrs: &[Attribute], decl: &FnDecl, blk: &Block) {
|
||||
fn do_check(lint: &mut NonExpressiveNames, cx: &EarlyContext<'_>, attrs: &[Attribute], decl: &FnDecl, blk: &Block) {
|
||||
if !attr::contains_name(attrs, "test") {
|
||||
let mut visitor = SimilarNamesLocalVisitor {
|
||||
names: Vec::new(),
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use rustc::hir::*;
|
||||
use crate::utils::{match_type, method_chain_args, paths, snippet, span_help_and_lint};
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use rustc::hir::{Expr, ExprKind};
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use syntax::ast::LitKind;
|
||||
use syntax::codemap::{Span, Spanned};
|
||||
use crate::utils::{match_type, paths, span_lint, walk_ptrs_ty};
|
||||
|
@ -60,7 +61,7 @@ enum OpenOption {
|
|||
Append,
|
||||
}
|
||||
|
||||
fn get_open_options(cx: &LateContext, argument: &Expr, options: &mut Vec<(OpenOption, Argument)>) {
|
||||
fn get_open_options(cx: &LateContext<'_, '_>, argument: &Expr, options: &mut Vec<(OpenOption, Argument)>) {
|
||||
if let ExprKind::MethodCall(ref path, _, ref arguments) = argument.node {
|
||||
let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&arguments[0]));
|
||||
|
||||
|
@ -111,7 +112,7 @@ fn get_open_options(cx: &LateContext, argument: &Expr, options: &mut Vec<(OpenOp
|
|||
}
|
||||
}
|
||||
|
||||
fn check_open_options(cx: &LateContext, options: &[(OpenOption, Argument)], span: Span) {
|
||||
fn check_open_options(cx: &LateContext<'_, '_>, options: &[(OpenOption, Argument)], span: Span) {
|
||||
let (mut create, mut append, mut truncate, mut read, mut write) = (false, false, false, false, false);
|
||||
let (mut create_arg, mut append_arg, mut truncate_arg, mut read_arg, mut write_arg) =
|
||||
(false, false, false, false, false);
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use rustc::hir::*;
|
||||
use crate::utils::{span_lint, SpanlessEq};
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use rustc::hir::*;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use syntax::ast::LitKind;
|
||||
use syntax::ptr::P;
|
||||
use syntax::ext::quote::rt::Span;
|
||||
|
@ -84,7 +86,7 @@ fn get_outer_span(expr: &Expr) -> Span {
|
|||
}
|
||||
}
|
||||
|
||||
fn match_panic(params: &P<[Expr]>, expr: &Expr, cx: &LateContext) {
|
||||
fn match_panic(params: &P<[Expr]>, expr: &Expr, cx: &LateContext<'_, '_>) {
|
||||
if_chain! {
|
||||
if let ExprKind::Lit(ref lit) = params[0].node;
|
||||
if is_direct_expn_of(expr.span, "panic").is_some();
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use rustc::hir::*;
|
||||
use crate::utils::{is_automatically_derived, span_lint};
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use syntax::ast::*;
|
||||
use syntax::codemap::Spanned;
|
||||
use crate::utils::{in_macro, snippet, span_lint_and_sugg};
|
||||
|
@ -36,7 +37,7 @@ impl LintPass for Precedence {
|
|||
}
|
||||
|
||||
impl EarlyLintPass for Precedence {
|
||||
fn check_expr(&mut self, cx: &EarlyContext, expr: &Expr) {
|
||||
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
|
||||
if in_macro(expr.span) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ use rustc::hir::*;
|
|||
use rustc::hir::map::NodeItem;
|
||||
use rustc::hir::QPath;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use rustc::ty;
|
||||
use syntax::ast::NodeId;
|
||||
use syntax::codemap::Span;
|
||||
|
@ -144,7 +146,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PointerPass {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_fn(cx: &LateContext, decl: &FnDecl, fn_id: NodeId, opt_body_id: Option<BodyId>) {
|
||||
fn check_fn(cx: &LateContext<'_, '_>, decl: &FnDecl, fn_id: NodeId, opt_body_id: Option<BodyId>) {
|
||||
let fn_def_id = cx.tcx.hir.local_def_id(fn_id);
|
||||
let sig = cx.tcx.fn_sig(fn_def_id);
|
||||
let fn_ty = sig.skip_binder();
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use rustc::hir::*;
|
||||
use rustc::hir::def::Def;
|
||||
use crate::utils::sugg::Sugg;
|
||||
|
@ -50,7 +52,7 @@ impl QuestionMarkPass {
|
|||
/// ```
|
||||
///
|
||||
/// If it matches, it will suggest to use the question mark operator instead
|
||||
fn check_is_none_and_early_return_none(cx: &LateContext, expr: &Expr) {
|
||||
fn check_is_none_and_early_return_none(cx: &LateContext<'_, '_>, expr: &Expr) {
|
||||
if_chain! {
|
||||
if let ExprKind::If(ref if_expr, ref body, _) = expr.node;
|
||||
if let ExprKind::MethodCall(ref segment, _, ref args) = if_expr.node;
|
||||
|
@ -79,13 +81,13 @@ impl QuestionMarkPass {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_option(cx: &LateContext, expression: &Expr) -> bool {
|
||||
fn is_option(cx: &LateContext<'_, '_>, expression: &Expr) -> bool {
|
||||
let expr_ty = cx.tables.expr_ty(expression);
|
||||
|
||||
match_type(cx, expr_ty, &OPTION)
|
||||
}
|
||||
|
||||
fn expression_returns_none(cx: &LateContext, expression: &Expr) -> bool {
|
||||
fn expression_returns_none(cx: &LateContext<'_, '_>, expression: &Expr) -> bool {
|
||||
match expression.node {
|
||||
ExprKind::Block(ref block, _) => {
|
||||
if let Some(return_expression) = Self::return_expression(block) {
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use rustc::hir::*;
|
||||
use syntax::ast::RangeLimits;
|
||||
use syntax::codemap::Spanned;
|
||||
|
@ -174,7 +176,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
|
|||
}
|
||||
}
|
||||
|
||||
fn has_step_by(cx: &LateContext, expr: &Expr) -> bool {
|
||||
fn has_step_by(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
|
||||
// No need for walk_ptrs_ty here because step_by moves self, so it
|
||||
// can't be called on a borrowed range.
|
||||
let ty = cx.tables.expr_ty_adjusted(expr);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use rustc::hir::*;
|
||||
use crate::utils::{in_macro, is_range_expression, match_var, span_lint_and_sugg};
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use syntax::ast::{Expr, ExprKind, UnOp};
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use crate::utils::{snippet, span_lint_and_sugg};
|
||||
|
||||
/// **What it does:** Checks for usage of `*&` and `*&mut` in expressions.
|
||||
|
@ -37,7 +39,7 @@ fn without_parens(mut e: &Expr) -> &Expr {
|
|||
}
|
||||
|
||||
impl EarlyLintPass for Pass {
|
||||
fn check_expr(&mut self, cx: &EarlyContext, e: &Expr) {
|
||||
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr) {
|
||||
if_chain! {
|
||||
if let ExprKind::Unary(UnOp::Deref, ref deref_target) = e.node;
|
||||
if let ExprKind::AddrOf(_, ref addrof_target) = without_parens(deref_target).node;
|
||||
|
@ -82,7 +84,7 @@ impl LintPass for DerefPass {
|
|||
}
|
||||
|
||||
impl EarlyLintPass for DerefPass {
|
||||
fn check_expr(&mut self, cx: &EarlyContext, e: &Expr) {
|
||||
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr) {
|
||||
if_chain! {
|
||||
if let ExprKind::Field(ref object, ref field_name) = e.node;
|
||||
if let ExprKind::Paren(ref parened) = object.node;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use regex_syntax;
|
||||
use rustc::hir::*;
|
||||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use std::collections::HashSet;
|
||||
use syntax::ast::{LitKind, NodeId, StrStyle};
|
||||
use syntax::codemap::{BytePos, Span};
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use rustc::hir;
|
||||
use rustc::hir::def::Def;
|
||||
use crate::utils::{match_def_path, span_lint_and_sugg};
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use if_chain::if_chain;
|
||||
use syntax::ast;
|
||||
use syntax::codemap::Span;
|
||||
use syntax::visit::FnKind;
|
||||
|
||||
use crate::utils::{in_external_macro, in_macro, match_path_ast, snippet_opt, span_lint_and_then, span_note_and_lint};
|
||||
use crate::utils::{in_macro, match_path_ast, snippet_opt, span_lint_and_then, span_note_and_lint};
|
||||
|
||||
/// **What it does:** Checks for return statements at the end of a block.
|
||||
///
|
||||
|
@ -47,7 +49,7 @@ pub struct ReturnPass;
|
|||
|
||||
impl ReturnPass {
|
||||
// Check the final stmt or expr in a block for unnecessary return.
|
||||
fn check_block_return(&mut self, cx: &EarlyContext, block: &ast::Block) {
|
||||
fn check_block_return(&mut self, cx: &EarlyContext<'_>, block: &ast::Block) {
|
||||
if let Some(stmt) = block.stmts.last() {
|
||||
match stmt.node {
|
||||
ast::StmtKind::Expr(ref expr) | ast::StmtKind::Semi(ref expr) => {
|
||||
|
@ -59,7 +61,7 @@ impl ReturnPass {
|
|||
}
|
||||
|
||||
// Check a the final expression in a block if it's a return.
|
||||
fn check_final_expr(&mut self, cx: &EarlyContext, expr: &ast::Expr, span: Option<Span>) {
|
||||
fn check_final_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr, span: Option<Span>) {
|
||||
match expr.node {
|
||||
// simple return is always "bad"
|
||||
ast::ExprKind::Ret(Some(ref inner)) => {
|
||||
|
@ -87,8 +89,8 @@ impl ReturnPass {
|
|||
}
|
||||
}
|
||||
|
||||
fn emit_return_lint(&mut self, cx: &EarlyContext, ret_span: Span, inner_span: Span) {
|
||||
if in_external_macro(cx, inner_span) || in_macro(inner_span) {
|
||||
fn emit_return_lint(&mut self, cx: &EarlyContext<'_>, ret_span: Span, inner_span: Span) {
|
||||
if in_external_macro(cx.sess(), inner_span) || in_macro(inner_span) {
|
||||
return;
|
||||
}
|
||||
span_lint_and_then(cx, NEEDLESS_RETURN, ret_span, "unneeded return statement", |db| {
|
||||
|
@ -99,7 +101,7 @@ impl ReturnPass {
|
|||
}
|
||||
|
||||
// Check for "let x = EXPR; x"
|
||||
fn check_let_return(&mut self, cx: &EarlyContext, block: &ast::Block) {
|
||||
fn check_let_return(&mut self, cx: &EarlyContext<'_>, block: &ast::Block) {
|
||||
let mut it = block.stmts.iter();
|
||||
|
||||
// we need both a let-binding stmt and an expr
|
||||
|
@ -115,7 +117,7 @@ impl ReturnPass {
|
|||
if let ast::PatKind::Ident(_, ident, _) = local.pat.node;
|
||||
if let ast::ExprKind::Path(_, ref path) = retexpr.node;
|
||||
if match_path_ast(path, &[&ident.as_str()]);
|
||||
if !in_external_macro(cx, initexpr.span);
|
||||
if !in_external_macro(cx.sess(), initexpr.span);
|
||||
then {
|
||||
span_note_and_lint(cx,
|
||||
LET_AND_RETURN,
|
||||
|
@ -136,14 +138,14 @@ impl LintPass for ReturnPass {
|
|||
}
|
||||
|
||||
impl EarlyLintPass for ReturnPass {
|
||||
fn check_fn(&mut self, cx: &EarlyContext, kind: FnKind, _: &ast::FnDecl, _: Span, _: ast::NodeId) {
|
||||
fn check_fn(&mut self, cx: &EarlyContext<'_>, kind: FnKind<'_>, _: &ast::FnDecl, _: Span, _: ast::NodeId) {
|
||||
match kind {
|
||||
FnKind::ItemFn(.., block) | FnKind::Method(.., block) => self.check_block_return(cx, block),
|
||||
FnKind::Closure(body) => self.check_final_expr(cx, body, Some(body.span)),
|
||||
}
|
||||
}
|
||||
|
||||
fn check_block(&mut self, cx: &EarlyContext, block: &ast::Block) {
|
||||
fn check_block(&mut self, cx: &EarlyContext<'_>, block: &ast::Block) {
|
||||
self.check_let_return(cx, block);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use rustc::lint::*;
|
||||
use rustc::{declare_lint, lint_array};
|
||||
use rustc::hir::*;
|
||||
use crate::utils::{get_trait_def_id, paths, span_lint};
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue