mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 13:13:34 +00:00
Auto merge of #4962 - JohnTitor:rustup-1227, r=matthiaskrgr
Rustup to rust-lang/rust#66936 changelog: none
This commit is contained in:
commit
0fcb5304e2
109 changed files with 735 additions and 655 deletions
|
@ -60,14 +60,14 @@ const KNOWN_CONSTS: [(f64, &str, usize); 16] = [
|
|||
declare_lint_pass!(ApproxConstant => [APPROX_CONSTANT]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ApproxConstant {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
|
||||
if let ExprKind::Lit(lit) = &e.kind {
|
||||
check_lit(cx, &lit.node, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn check_lit(cx: &LateContext<'_, '_>, lit: &LitKind, e: &Expr) {
|
||||
fn check_lit(cx: &LateContext<'_, '_>, lit: &LitKind, e: &Expr<'_>) {
|
||||
match *lit {
|
||||
LitKind::Float(s, LitFloatType::Suffixed(fty)) => match fty {
|
||||
FloatTy::F32 => check_known_consts(cx, e, s, "f32"),
|
||||
|
@ -78,7 +78,7 @@ fn check_lit(cx: &LateContext<'_, '_>, lit: &LitKind, 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 {
|
||||
|
|
|
@ -54,7 +54,7 @@ pub struct Arithmetic {
|
|||
impl_lint_pass!(Arithmetic => [INTEGER_ARITHMETIC, FLOAT_ARITHMETIC]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) {
|
||||
if self.expr_span.is_some() {
|
||||
return;
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_expr_post(&mut self, _: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
|
||||
fn check_expr_post(&mut self, _: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) {
|
||||
if Some(expr.span) == self.expr_span {
|
||||
self.expr_span = None;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(AssertionsOnConstants => [ASSERTIONS_ON_CONSTANTS]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
|
||||
let lint_true = || {
|
||||
span_help_and_lint(
|
||||
cx,
|
||||
|
@ -110,7 +110,7 @@ enum AssertKind {
|
|||
/// ```
|
||||
///
|
||||
/// where `message` is any expression and `c` is a constant bool.
|
||||
fn match_assert_with_message<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Option<AssertKind> {
|
||||
fn match_assert_with_message<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> Option<AssertKind> {
|
||||
if_chain! {
|
||||
if let ExprKind::Match(ref expr, ref arms, _) = expr.kind;
|
||||
// matches { let _t = expr; _t }
|
||||
|
@ -124,7 +124,7 @@ fn match_assert_with_message<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx E
|
|||
if let LitKind::Bool(true) = lit.node;
|
||||
// arm 1 block
|
||||
if let ExprKind::Block(ref block, _) = arms[0].body.kind;
|
||||
if block.stmts.len() == 0;
|
||||
if block.stmts.is_empty();
|
||||
if let Some(block_expr) = &block.expr;
|
||||
if let ExprKind::Block(ref inner_block, _) = block_expr.kind;
|
||||
if let Some(begin_panic_call) = &inner_block.expr;
|
||||
|
|
|
@ -59,7 +59,7 @@ declare_lint_pass!(AssignOps => [ASSIGN_OP_PATTERN, MISREFACTORED_ASSIGN_OP]);
|
|||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
|
||||
#[allow(clippy::too_many_lines)]
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) {
|
||||
match &expr.kind {
|
||||
hir::ExprKind::AssignOp(op, lhs, rhs) => {
|
||||
if let hir::ExprKind::Binary(binop, l, r) = &rhs.kind {
|
||||
|
@ -79,7 +79,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
|
|||
hir::ExprKind::Assign(assignee, e, _) => {
|
||||
if let hir::ExprKind::Binary(op, l, r) = &e.kind {
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
let lint = |assignee: &hir::Expr, rhs: &hir::Expr| {
|
||||
let lint = |assignee: &hir::Expr<'_>, rhs: &hir::Expr<'_>| {
|
||||
let ty = cx.tables.expr_ty(assignee);
|
||||
let rty = cx.tables.expr_ty(rhs);
|
||||
macro_rules! ops {
|
||||
|
@ -190,11 +190,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
|
|||
|
||||
fn lint_misrefactored_assign_op(
|
||||
cx: &LateContext<'_, '_>,
|
||||
expr: &hir::Expr,
|
||||
expr: &hir::Expr<'_>,
|
||||
op: hir::BinOp,
|
||||
rhs: &hir::Expr,
|
||||
assignee: &hir::Expr,
|
||||
rhs_other: &hir::Expr,
|
||||
rhs: &hir::Expr<'_>,
|
||||
assignee: &hir::Expr<'_>,
|
||||
rhs_other: &hir::Expr<'_>,
|
||||
) {
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
|
@ -240,13 +240,13 @@ fn is_commutative(op: hir::BinOpKind) -> bool {
|
|||
}
|
||||
|
||||
struct ExprVisitor<'a, 'tcx> {
|
||||
assignee: &'a hir::Expr,
|
||||
assignee: &'a hir::Expr<'a>,
|
||||
counter: u8,
|
||||
cx: &'a LateContext<'a, 'tcx>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for ExprVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) {
|
||||
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(self.assignee, expr) {
|
||||
self.counter += 1;
|
||||
}
|
||||
|
|
|
@ -380,7 +380,7 @@ fn is_relevant_trait(cx: &LateContext<'_, '_>, item: &TraitItem<'_>) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_relevant_block(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, block: &Block) -> bool {
|
||||
fn is_relevant_block(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, block: &Block<'_>) -> bool {
|
||||
if let Some(stmt) = block.stmts.first() {
|
||||
match &stmt.kind {
|
||||
StmtKind::Local(_) => true,
|
||||
|
@ -392,7 +392,7 @@ fn is_relevant_block(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, bl
|
|||
}
|
||||
}
|
||||
|
||||
fn is_relevant_expr(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, expr: &Expr) -> bool {
|
||||
fn is_relevant_expr(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, expr: &Expr<'_>) -> bool {
|
||||
match &expr.kind {
|
||||
ExprKind::Block(block, _) => is_relevant_block(cx, tables, block),
|
||||
ExprKind::Ret(Some(e)) => is_relevant_expr(cx, tables, e),
|
||||
|
|
|
@ -112,7 +112,7 @@ impl BitMask {
|
|||
impl_lint_pass!(BitMask => [BAD_BIT_MASK, INEFFECTIVE_BIT_MASK, VERBOSE_BIT_MASK]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
|
||||
if let ExprKind::Binary(cmp, left, right) = &e.kind {
|
||||
if cmp.node.is_comparison() {
|
||||
if let Some(cmp_opt) = fetch_int_literal(cx, right) {
|
||||
|
@ -165,7 +165,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(op, left, right) = &bit_op.kind {
|
||||
if op.node != BinOpKind::BitAnd && op.node != BinOpKind::BitOr {
|
||||
return;
|
||||
|
@ -319,7 +319,7 @@ fn check_ineffective_gt(cx: &LateContext<'_, '_>, span: Span, m: u128, c: u128,
|
|||
}
|
||||
}
|
||||
|
||||
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,
|
||||
|
|
|
@ -37,7 +37,7 @@ impl BlacklistedName {
|
|||
impl_lint_pass!(BlacklistedName => [BLACKLISTED_NAME]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlacklistedName {
|
||||
fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {
|
||||
fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat<'_>) {
|
||||
if let PatKind::Binding(.., ident, _) = pat.kind {
|
||||
if self.blacklist.contains(&ident.name.to_string()) {
|
||||
span_lint(
|
||||
|
|
|
@ -46,12 +46,12 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(BlockInIfCondition => [BLOCK_IN_IF_CONDITION_EXPR, BLOCK_IN_IF_CONDITION_STMT]);
|
||||
|
||||
struct ExVisitor<'a, 'tcx> {
|
||||
found_block: Option<&'tcx Expr>,
|
||||
found_block: Option<&'tcx Expr<'tcx>>,
|
||||
cx: &'a LateContext<'a, 'tcx>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr) {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) {
|
||||
if let ExprKind::Closure(_, _, eid, _, _) = expr.kind {
|
||||
let body = self.cx.tcx.hir().body(eid);
|
||||
let ex = &body.value;
|
||||
|
@ -72,7 +72,7 @@ const COMPLEX_BLOCK_MESSAGE: &str = "in an 'if' condition, avoid complex blocks
|
|||
instead, move the block or closure higher and bind it with a 'let'";
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlockInIfCondition {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if in_external_macro(cx.sess(), expr.span) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -75,12 +75,12 @@ struct NonminimalBoolVisitor<'a, 'tcx> {
|
|||
|
||||
use quine_mc_cluskey::Bool;
|
||||
struct Hir2Qmm<'a, 'tcx, 'v> {
|
||||
terminals: Vec<&'v Expr>,
|
||||
terminals: Vec<&'v Expr<'v>>,
|
||||
cx: &'a LateContext<'a, 'tcx>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
|
||||
fn extract(&mut self, op: BinOpKind, a: &[&'v Expr], mut v: Vec<Bool>) -> Result<Vec<Bool>, String> {
|
||||
fn extract(&mut self, op: BinOpKind, a: &[&'v Expr<'_>], mut v: Vec<Bool>) -> Result<Vec<Bool>, String> {
|
||||
for a in a {
|
||||
if let ExprKind::Binary(binop, lhs, rhs) = &a.kind {
|
||||
if binop.node == op {
|
||||
|
@ -93,7 +93,7 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
|
|||
Ok(v)
|
||||
}
|
||||
|
||||
fn run(&mut self, e: &'v Expr) -> Result<Bool, String> {
|
||||
fn run(&mut self, e: &'v Expr<'_>) -> Result<Bool, String> {
|
||||
fn negate(bin_op_kind: BinOpKind) -> Option<BinOpKind> {
|
||||
match bin_op_kind {
|
||||
BinOpKind::Eq => Some(BinOpKind::Ne),
|
||||
|
@ -154,7 +154,7 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
|
|||
}
|
||||
|
||||
struct SuggestContext<'a, 'tcx, 'v> {
|
||||
terminals: &'v [&'v Expr],
|
||||
terminals: &'v [&'v Expr<'v>],
|
||||
cx: &'a LateContext<'a, 'tcx>,
|
||||
output: String,
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
|
|||
}
|
||||
}
|
||||
|
||||
fn simplify_not(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<String> {
|
||||
fn simplify_not(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option<String> {
|
||||
match &expr.kind {
|
||||
ExprKind::Binary(binop, lhs, rhs) => {
|
||||
if !implements_ord(cx, lhs) {
|
||||
|
@ -266,7 +266,7 @@ fn simplify_not(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<String> {
|
|||
}
|
||||
}
|
||||
|
||||
fn suggest(cx: &LateContext<'_, '_>, suggestion: &Bool, terminals: &[&Expr]) -> String {
|
||||
fn suggest(cx: &LateContext<'_, '_>, suggestion: &Bool, terminals: &[&Expr<'_>]) -> String {
|
||||
let mut suggest_context = SuggestContext {
|
||||
terminals,
|
||||
cx,
|
||||
|
@ -332,7 +332,7 @@ fn terminal_stats(b: &Bool) -> Stats {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
|
||||
fn bool_expr(&self, e: &'tcx Expr) {
|
||||
fn bool_expr(&self, e: &'tcx Expr<'_>) {
|
||||
let mut h2q = Hir2Qmm {
|
||||
terminals: Vec::new(),
|
||||
cx: self.cx,
|
||||
|
@ -437,7 +437,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, e: &'tcx Expr) {
|
||||
fn visit_expr(&mut self, e: &'tcx Expr<'_>) {
|
||||
if in_macro(e.span) {
|
||||
return;
|
||||
}
|
||||
|
@ -460,7 +460,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn implements_ord<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, expr: &Expr) -> bool {
|
||||
fn implements_ord<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, expr: &Expr<'_>) -> bool {
|
||||
let ty = cx.tables.expr_ty(expr);
|
||||
get_trait_def_id(cx, &paths::ORD).map_or(false, |id| implements_trait(cx, ty, id, &[]))
|
||||
}
|
||||
|
@ -470,7 +470,7 @@ struct NotSimplificationVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr) {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
|
||||
if let ExprKind::Unary(UnNot, inner) = &expr.kind {
|
||||
if let Some(suggestion) = simplify_not(self.cx, inner) {
|
||||
span_lint_and_sugg(
|
||||
|
|
|
@ -36,7 +36,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(ByteCount => [NAIVE_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.kind;
|
||||
if count.ident.name == sym!(count);
|
||||
|
@ -96,11 +96,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_arg(name: Name, arg: Name, needle: &Expr) -> bool {
|
||||
fn check_arg(name: Name, arg: Name, needle: &Expr<'_>) -> bool {
|
||||
name == arg && !contains_name(name, needle)
|
||||
}
|
||||
|
||||
fn get_path_name(expr: &Expr) -> Option<Name> {
|
||||
fn get_path_name(expr: &Expr<'_>) -> Option<Name> {
|
||||
match expr.kind {
|
||||
ExprKind::Box(ref e) | ExprKind::AddrOf(BorrowKind::Ref, _, ref e) | ExprKind::Unary(UnOp::UnDeref, ref e) => {
|
||||
get_path_name(e)
|
||||
|
|
|
@ -42,7 +42,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(CheckedConversions => [CHECKED_CONVERSIONS]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CheckedConversions {
|
||||
fn check_expr(&mut self, cx: &LateContext<'_, '_>, item: &Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'_, '_>, item: &Expr<'_>) {
|
||||
let result = if_chain! {
|
||||
if !in_external_macro(cx.sess(), item.span);
|
||||
if let ExprKind::Binary(op, ref left, ref right) = &item.kind;
|
||||
|
@ -84,12 +84,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CheckedConversions {
|
|||
|
||||
/// Searches for a single check from unsigned to _ is done
|
||||
/// todo: check for case signed -> larger unsigned == only x >= 0
|
||||
fn single_check(expr: &Expr) -> Option<Conversion<'_>> {
|
||||
fn single_check<'tcx>(expr: &'tcx Expr<'tcx>) -> Option<Conversion<'tcx>> {
|
||||
check_upper_bound(expr).filter(|cv| cv.cvt == ConversionType::FromUnsigned)
|
||||
}
|
||||
|
||||
/// Searches for a combination of upper & lower bound checks
|
||||
fn double_check<'a>(cx: &LateContext<'_, '_>, left: &'a Expr, right: &'a Expr) -> Option<Conversion<'a>> {
|
||||
fn double_check<'a>(cx: &LateContext<'_, '_>, left: &'a Expr<'_>, right: &'a Expr<'_>) -> Option<Conversion<'a>> {
|
||||
let upper_lower = |l, r| {
|
||||
let upper = check_upper_bound(l);
|
||||
let lower = check_lower_bound(r);
|
||||
|
@ -104,7 +104,7 @@ fn double_check<'a>(cx: &LateContext<'_, '_>, left: &'a Expr, right: &'a Expr) -
|
|||
#[derive(Clone, Debug)]
|
||||
struct Conversion<'a> {
|
||||
cvt: ConversionType,
|
||||
expr_to_cast: &'a Expr,
|
||||
expr_to_cast: &'a Expr<'a>,
|
||||
to_type: Option<&'a str>,
|
||||
}
|
||||
|
||||
|
@ -141,7 +141,7 @@ impl<'a> Conversion<'a> {
|
|||
}
|
||||
|
||||
/// Try to construct a new conversion if the conversion type is valid
|
||||
fn try_new(expr_to_cast: &'a Expr, from_type: &str, to_type: &'a str) -> Option<Conversion<'a>> {
|
||||
fn try_new(expr_to_cast: &'a Expr<'_>, from_type: &str, to_type: &'a str) -> Option<Conversion<'a>> {
|
||||
ConversionType::try_new(from_type, to_type).map(|cvt| Conversion {
|
||||
cvt,
|
||||
expr_to_cast,
|
||||
|
@ -150,7 +150,7 @@ impl<'a> Conversion<'a> {
|
|||
}
|
||||
|
||||
/// Construct a new conversion without type constraint
|
||||
fn new_any(expr_to_cast: &'a Expr) -> Conversion<'a> {
|
||||
fn new_any(expr_to_cast: &'a Expr<'_>) -> Conversion<'a> {
|
||||
Conversion {
|
||||
cvt: ConversionType::SignedToUnsigned,
|
||||
expr_to_cast,
|
||||
|
@ -180,7 +180,7 @@ impl ConversionType {
|
|||
}
|
||||
|
||||
/// Check for `expr <= (to_type::max_value() as from_type)`
|
||||
fn check_upper_bound(expr: &Expr) -> Option<Conversion<'_>> {
|
||||
fn check_upper_bound<'tcx>(expr: &'tcx Expr<'tcx>) -> Option<Conversion<'tcx>> {
|
||||
if_chain! {
|
||||
if let ExprKind::Binary(ref op, ref left, ref right) = &expr.kind;
|
||||
if let Some((candidate, check)) = normalize_le_ge(op, left, right);
|
||||
|
@ -195,8 +195,8 @@ fn check_upper_bound(expr: &Expr) -> Option<Conversion<'_>> {
|
|||
}
|
||||
|
||||
/// Check for `expr >= 0|(to_type::min_value() as from_type)`
|
||||
fn check_lower_bound(expr: &Expr) -> Option<Conversion<'_>> {
|
||||
fn check_function<'a>(candidate: &'a Expr, check: &'a Expr) -> Option<Conversion<'a>> {
|
||||
fn check_lower_bound<'tcx>(expr: &'tcx Expr<'tcx>) -> Option<Conversion<'tcx>> {
|
||||
fn check_function<'a>(candidate: &'a Expr<'a>, check: &'a Expr<'a>) -> Option<Conversion<'a>> {
|
||||
(check_lower_bound_zero(candidate, check)).or_else(|| (check_lower_bound_min(candidate, check)))
|
||||
}
|
||||
|
||||
|
@ -209,7 +209,7 @@ fn check_lower_bound(expr: &Expr) -> Option<Conversion<'_>> {
|
|||
}
|
||||
|
||||
/// Check for `expr >= 0`
|
||||
fn check_lower_bound_zero<'a>(candidate: &'a Expr, check: &'a Expr) -> Option<Conversion<'a>> {
|
||||
fn check_lower_bound_zero<'a>(candidate: &'a Expr<'_>, check: &'a Expr<'_>) -> Option<Conversion<'a>> {
|
||||
if_chain! {
|
||||
if let ExprKind::Lit(ref lit) = &check.kind;
|
||||
if let LitKind::Int(0, _) = &lit.node;
|
||||
|
@ -223,7 +223,7 @@ fn check_lower_bound_zero<'a>(candidate: &'a Expr, check: &'a Expr) -> Option<Co
|
|||
}
|
||||
|
||||
/// Check for `expr >= (to_type::min_value() as from_type)`
|
||||
fn check_lower_bound_min<'a>(candidate: &'a Expr, check: &'a Expr) -> Option<Conversion<'a>> {
|
||||
fn check_lower_bound_min<'a>(candidate: &'a Expr<'_>, check: &'a Expr<'_>) -> Option<Conversion<'a>> {
|
||||
if let Some((from, to)) = get_types_from_cast(check, MIN_VALUE, SINTS) {
|
||||
Conversion::try_new(candidate, from, to)
|
||||
} else {
|
||||
|
@ -232,9 +232,9 @@ fn check_lower_bound_min<'a>(candidate: &'a Expr, check: &'a Expr) -> Option<Con
|
|||
}
|
||||
|
||||
/// Tries to extract the from- and to-type from a cast expression
|
||||
fn get_types_from_cast<'a>(expr: &'a Expr, func: &'a str, types: &'a [&str]) -> Option<(&'a str, &'a str)> {
|
||||
fn get_types_from_cast<'a>(expr: &'a Expr<'_>, func: &'a str, types: &'a [&str]) -> Option<(&'a str, &'a str)> {
|
||||
// `to_type::maxmin_value() as from_type`
|
||||
let call_from_cast: Option<(&Expr, &str)> = if_chain! {
|
||||
let call_from_cast: Option<(&Expr<'_>, &str)> = if_chain! {
|
||||
// to_type::maxmin_value(), from_type
|
||||
if let ExprKind::Cast(ref limit, ref from_type) = &expr.kind;
|
||||
if let TyKind::Path(ref from_type_path) = &from_type.kind;
|
||||
|
@ -248,7 +248,7 @@ fn get_types_from_cast<'a>(expr: &'a Expr, func: &'a str, types: &'a [&str]) ->
|
|||
};
|
||||
|
||||
// `from_type::from(to_type::maxmin_value())`
|
||||
let limit_from: Option<(&Expr, &str)> = call_from_cast.or_else(|| {
|
||||
let limit_from: Option<(&Expr<'_>, &str)> = call_from_cast.or_else(|| {
|
||||
if_chain! {
|
||||
// `from_type::from, to_type::maxmin_value()`
|
||||
if let ExprKind::Call(ref from_func, ref args) = &expr.kind;
|
||||
|
@ -327,7 +327,7 @@ fn transpose<T, U>(lhs: Option<T>, rhs: Option<U>) -> Option<(T, U)> {
|
|||
}
|
||||
|
||||
/// Will return the expressions as if they were expr1 <= expr2
|
||||
fn normalize_le_ge<'a>(op: &BinOp, left: &'a Expr, right: &'a Expr) -> Option<(&'a Expr, &'a Expr)> {
|
||||
fn normalize_le_ge<'a>(op: &BinOp, left: &'a Expr<'a>, right: &'a Expr<'a>) -> Option<(&'a Expr<'a>, &'a Expr<'a>)> {
|
||||
match op.node {
|
||||
BinOpKind::Le => Some((left, right)),
|
||||
BinOpKind::Ge => Some((right, left)),
|
||||
|
|
|
@ -141,7 +141,7 @@ struct CCHelper {
|
|||
}
|
||||
|
||||
impl<'tcx> Visitor<'tcx> for CCHelper {
|
||||
fn visit_expr(&mut self, e: &'tcx Expr) {
|
||||
fn visit_expr(&mut self, e: &'tcx Expr<'_>) {
|
||||
walk_expr(self, e);
|
||||
match e.kind {
|
||||
ExprKind::Match(_, ref arms, _) => {
|
||||
|
|
|
@ -54,7 +54,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(ComparisonChain => [COMPARISON_CHAIN]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ComparisonChain {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if expr.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -178,7 +178,7 @@ pub fn lit_to_constant(lit: &LitKind, ty: Option<Ty<'_>>) -> Constant {
|
|||
pub fn constant<'c, 'cc>(
|
||||
lcx: &LateContext<'c, 'cc>,
|
||||
tables: &'c ty::TypeckTables<'cc>,
|
||||
e: &Expr,
|
||||
e: &Expr<'_>,
|
||||
) -> Option<(Constant, bool)> {
|
||||
let mut cx = ConstEvalLateContext {
|
||||
lcx,
|
||||
|
@ -193,7 +193,7 @@ pub fn constant<'c, 'cc>(
|
|||
pub fn constant_simple<'c, 'cc>(
|
||||
lcx: &LateContext<'c, 'cc>,
|
||||
tables: &'c ty::TypeckTables<'cc>,
|
||||
e: &Expr,
|
||||
e: &Expr<'_>,
|
||||
) -> Option<Constant> {
|
||||
constant(lcx, tables, e).and_then(|(cst, res)| if res { None } else { Some(cst) })
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ pub struct ConstEvalLateContext<'a, 'tcx> {
|
|||
|
||||
impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
|
||||
/// Simple constant folding: Insert an expression, get a constant or none.
|
||||
pub fn expr(&mut self, e: &Expr) -> Option<Constant> {
|
||||
pub fn expr(&mut self, e: &Expr<'_>) -> Option<Constant> {
|
||||
if let Some((ref cond, ref then, otherwise)) = higher::if_block(&e) {
|
||||
return self.ifthenelse(cond, then, otherwise);
|
||||
}
|
||||
|
@ -315,7 +315,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
|
|||
|
||||
/// Create `Some(Vec![..])` of all constants, unless there is any
|
||||
/// non-constant part.
|
||||
fn multi(&mut self, vec: &[Expr]) -> Option<Vec<Constant>> {
|
||||
fn multi(&mut self, vec: &[Expr<'_>]) -> Option<Vec<Constant>> {
|
||||
vec.iter().map(|elem| self.expr(elem)).collect::<Option<_>>()
|
||||
}
|
||||
|
||||
|
@ -348,7 +348,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
|
|||
}
|
||||
|
||||
/// A block can only yield a constant if it only has one constant expression.
|
||||
fn block(&mut self, block: &Block) -> Option<Constant> {
|
||||
fn block(&mut self, block: &Block<'_>) -> Option<Constant> {
|
||||
if block.stmts.is_empty() {
|
||||
block.expr.as_ref().and_then(|b| self.expr(b))
|
||||
} else {
|
||||
|
@ -356,7 +356,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
|
|||
}
|
||||
}
|
||||
|
||||
fn ifthenelse(&mut self, cond: &Expr, then: &Expr, otherwise: Option<&Expr>) -> Option<Constant> {
|
||||
fn ifthenelse(&mut self, cond: &Expr<'_>, then: &Expr<'_>, otherwise: Option<&Expr<'_>>) -> Option<Constant> {
|
||||
if let Some(Constant::Bool(b)) = self.expr(cond) {
|
||||
if b {
|
||||
self.expr(&*then)
|
||||
|
@ -368,7 +368,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
|
|||
}
|
||||
}
|
||||
|
||||
fn binop(&mut self, op: BinOp, left: &Expr, right: &Expr) -> Option<Constant> {
|
||||
fn binop(&mut self, op: BinOp, left: &Expr<'_>, right: &Expr<'_>) -> Option<Constant> {
|
||||
let l = self.expr(left)?;
|
||||
let r = self.expr(right);
|
||||
match (l, r) {
|
||||
|
|
|
@ -153,7 +153,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(CopyAndPaste => [IFS_SAME_COND, SAME_FUNCTIONS_IN_IF_CONDITION, IF_SAME_THEN_ELSE, MATCH_SAME_ARMS]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyAndPaste {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if !expr.span.from_expansion() {
|
||||
// skip ifs directly in else, it will be checked in the parent if
|
||||
if let Some(expr) = get_parent_expr(cx, expr) {
|
||||
|
@ -174,8 +174,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyAndPaste {
|
|||
}
|
||||
|
||||
/// Implementation of `IF_SAME_THEN_ELSE`.
|
||||
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) };
|
||||
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) {
|
||||
span_note_and_lint(
|
||||
|
@ -190,14 +191,14 @@ fn lint_same_then_else(cx: &LateContext<'_, '_>, blocks: &[&Block]) {
|
|||
}
|
||||
|
||||
/// Implementation of `IFS_SAME_COND`.
|
||||
fn lint_same_cond(cx: &LateContext<'_, '_>, conds: &[&Expr]) {
|
||||
let hash: &dyn Fn(&&Expr) -> u64 = &|expr| -> u64 {
|
||||
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);
|
||||
h.finish()
|
||||
};
|
||||
|
||||
let eq: &dyn Fn(&&Expr, &&Expr) -> bool =
|
||||
let eq: &dyn Fn(&&Expr<'_>, &&Expr<'_>) -> bool =
|
||||
&|&lhs, &rhs| -> bool { SpanlessEq::new(cx).ignore_fn().eq_expr(lhs, rhs) };
|
||||
|
||||
for (i, j) in search_same(conds, hash, eq) {
|
||||
|
@ -213,14 +214,14 @@ fn lint_same_cond(cx: &LateContext<'_, '_>, conds: &[&Expr]) {
|
|||
}
|
||||
|
||||
/// Implementation of `SAME_FUNCTIONS_IN_IF_CONDITION`.
|
||||
fn lint_same_fns_in_if_cond(cx: &LateContext<'_, '_>, conds: &[&Expr]) {
|
||||
let hash: &dyn Fn(&&Expr) -> u64 = &|expr| -> u64 {
|
||||
fn lint_same_fns_in_if_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);
|
||||
h.finish()
|
||||
};
|
||||
|
||||
let eq: &dyn Fn(&&Expr, &&Expr) -> bool = &|&lhs, &rhs| -> bool {
|
||||
let eq: &dyn Fn(&&Expr<'_>, &&Expr<'_>) -> bool = &|&lhs, &rhs| -> bool {
|
||||
// Do not spawn warning if `IFS_SAME_COND` already produced it.
|
||||
if SpanlessEq::new(cx).ignore_fn().eq_expr(lhs, rhs) {
|
||||
return false;
|
||||
|
@ -241,7 +242,7 @@ fn lint_same_fns_in_if_cond(cx: &LateContext<'_, '_>, conds: &[&Expr]) {
|
|||
}
|
||||
|
||||
/// Implementation of `MATCH_SAME_ARMS`.
|
||||
fn lint_match_arms<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr) {
|
||||
fn lint_match_arms<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr<'_>) {
|
||||
fn same_bindings<'tcx>(
|
||||
cx: &LateContext<'_, 'tcx>,
|
||||
lhs: &FxHashMap<Symbol, Ty<'tcx>>,
|
||||
|
@ -254,13 +255,13 @@ fn lint_match_arms<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr) {
|
|||
}
|
||||
|
||||
if let ExprKind::Match(_, ref arms, MatchSource::Normal) = expr.kind {
|
||||
let hash = |&(_, arm): &(usize, &Arm)| -> u64 {
|
||||
let hash = |&(_, arm): &(usize, &Arm<'_>)| -> u64 {
|
||||
let mut h = SpanlessHash::new(cx, cx.tables);
|
||||
h.hash_expr(&arm.body);
|
||||
h.finish()
|
||||
};
|
||||
|
||||
let eq = |&(lindex, lhs): &(usize, &Arm), &(rindex, rhs): &(usize, &Arm)| -> bool {
|
||||
let eq = |&(lindex, lhs): &(usize, &Arm<'_>), &(rindex, rhs): &(usize, &Arm<'_>)| -> bool {
|
||||
let min_index = usize::min(lindex, rindex);
|
||||
let max_index = usize::max(lindex, rindex);
|
||||
|
||||
|
@ -272,7 +273,7 @@ fn lint_match_arms<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr) {
|
|||
same_bindings(cx, &bindings(cx, &lhs.pat), &bindings(cx, &rhs.pat))
|
||||
};
|
||||
|
||||
let indexed_arms: Vec<(usize, &Arm)> = arms.iter().enumerate().collect();
|
||||
let indexed_arms: Vec<(usize, &Arm<'_>)> = arms.iter().enumerate().collect();
|
||||
for (&(_, i), &(_, j)) in search_same(&indexed_arms, hash, eq) {
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
|
@ -313,11 +314,11 @@ fn lint_match_arms<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr) {
|
|||
}
|
||||
|
||||
/// Returns the list of bindings in a pattern.
|
||||
fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> FxHashMap<Symbol, Ty<'tcx>> {
|
||||
fn bindings_impl<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat, map: &mut FxHashMap<Symbol, Ty<'tcx>>) {
|
||||
fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat<'_>) -> FxHashMap<Symbol, Ty<'tcx>> {
|
||||
fn bindings_impl<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat<'_>, map: &mut FxHashMap<Symbol, Ty<'tcx>>) {
|
||||
match pat.kind {
|
||||
PatKind::Box(ref pat) | PatKind::Ref(ref pat, _) => bindings_impl(cx, pat, map),
|
||||
PatKind::TupleStruct(_, ref pats, _) => {
|
||||
PatKind::TupleStruct(_, pats, _) => {
|
||||
for pat in pats {
|
||||
bindings_impl(cx, pat, map);
|
||||
}
|
||||
|
@ -330,17 +331,17 @@ fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> FxHashMap<Symbol
|
|||
bindings_impl(cx, as_pat, map);
|
||||
}
|
||||
},
|
||||
PatKind::Or(ref fields) | PatKind::Tuple(ref fields, _) => {
|
||||
PatKind::Or(fields) | PatKind::Tuple(fields, _) => {
|
||||
for pat in fields {
|
||||
bindings_impl(cx, pat, map);
|
||||
}
|
||||
},
|
||||
PatKind::Struct(_, ref fields, _) => {
|
||||
PatKind::Struct(_, fields, _) => {
|
||||
for pat in fields {
|
||||
bindings_impl(cx, &pat.pat, map);
|
||||
}
|
||||
},
|
||||
PatKind::Slice(ref lhs, ref mid, ref rhs) => {
|
||||
PatKind::Slice(lhs, ref mid, rhs) => {
|
||||
for pat in lhs {
|
||||
bindings_impl(cx, pat, map);
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(DefaultTraitAccess => [DEFAULT_TRAIT_ACCESS]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if_chain! {
|
||||
if let ExprKind::Call(ref path, ..) = expr.kind;
|
||||
if !any_parent_is_automatically_derived(cx.tcx, expr.hir_id);
|
||||
|
|
|
@ -40,7 +40,7 @@ declare_lint_pass!(DoubleComparisons => [DOUBLE_COMPARISONS]);
|
|||
|
||||
impl<'a, 'tcx> DoubleComparisons {
|
||||
#[allow(clippy::similar_names)]
|
||||
fn check_binop(cx: &LateContext<'a, 'tcx>, op: BinOpKind, lhs: &'tcx Expr, rhs: &'tcx Expr, span: Span) {
|
||||
fn check_binop(cx: &LateContext<'a, 'tcx>, op: BinOpKind, lhs: &'tcx Expr<'_>, rhs: &'tcx Expr<'_>, span: Span) {
|
||||
let (lkind, llhs, lrhs, rkind, rlhs, rrhs) = match (&lhs.kind, &rhs.kind) {
|
||||
(ExprKind::Binary(lb, llhs, lrhs), ExprKind::Binary(rb, rlhs, rrhs)) => {
|
||||
(lb.node, llhs, lrhs, rb.node, rlhs, rrhs)
|
||||
|
@ -88,7 +88,7 @@ impl<'a, 'tcx> DoubleComparisons {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DoubleComparisons {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if let ExprKind::Binary(ref kind, ref lhs, ref rhs) = expr.kind {
|
||||
Self::check_binop(cx, kind.node, lhs, rhs, expr.span);
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ const FORGET_COPY_SUMMARY: &str = "calls to `std::mem::forget` with a value that
|
|||
declare_lint_pass!(DropForgetRef => [DROP_REF, FORGET_REF, DROP_COPY, FORGET_COPY]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DropForgetRef {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if_chain! {
|
||||
if let ExprKind::Call(ref path, ref args) = expr.kind;
|
||||
if let ExprKind::Path(ref qpath) = path.kind;
|
||||
|
|
|
@ -34,7 +34,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(DurationSubsec => [DURATION_SUBSEC]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DurationSubsec {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if_chain! {
|
||||
if let ExprKind::Binary(Spanned { node: BinOpKind::Div, .. }, ref left, ref right) = expr.kind;
|
||||
if let ExprKind::MethodCall(ref method_path, _ , ref args) = left.kind;
|
||||
|
|
|
@ -53,7 +53,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(HashMapPass => [MAP_ENTRY]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HashMapPass {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if let Some((ref check, ref then_block, ref else_block)) = higher::if_block(&expr) {
|
||||
if let ExprKind::Unary(UnOp::UnNot, ref check) = check.kind {
|
||||
if let Some((ty, map, key)) = check_cond(cx, check) {
|
||||
|
@ -100,8 +100,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HashMapPass {
|
|||
|
||||
fn check_cond<'a, 'tcx, 'b>(
|
||||
cx: &'a LateContext<'a, 'tcx>,
|
||||
check: &'b Expr,
|
||||
) -> Option<(&'static str, &'b Expr, &'b Expr)> {
|
||||
check: &'b Expr<'b>,
|
||||
) -> Option<(&'static str, &'b Expr<'b>, &'b Expr<'b>)> {
|
||||
if_chain! {
|
||||
if let ExprKind::MethodCall(ref path, _, ref params) = check.kind;
|
||||
if params.len() >= 2;
|
||||
|
@ -130,13 +130,13 @@ struct InsertVisitor<'a, 'tcx, 'b> {
|
|||
cx: &'a LateContext<'a, 'tcx>,
|
||||
span: Span,
|
||||
ty: &'static str,
|
||||
map: &'b Expr,
|
||||
key: &'b Expr,
|
||||
map: &'b Expr<'b>,
|
||||
key: &'b Expr<'b>,
|
||||
sole_expr: bool,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx, 'b> Visitor<'tcx> for InsertVisitor<'a, 'tcx, 'b> {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr) {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
|
||||
if_chain! {
|
||||
if let ExprKind::MethodCall(ref path, _, ref params) = expr.kind;
|
||||
if params.len() == 3;
|
||||
|
|
|
@ -49,7 +49,7 @@ declare_lint_pass!(EqOp => [EQ_OP, OP_REF]);
|
|||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
|
||||
#[allow(clippy::similar_names, clippy::too_many_lines)]
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
|
||||
if let ExprKind::Binary(op, ref left, ref right) = e.kind {
|
||||
if e.span.from_expansion() {
|
||||
return;
|
||||
|
|
|
@ -31,7 +31,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(ErasingOp => [ERASING_OP]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ErasingOp {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
|
||||
if e.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
@ -48,7 +48,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(0)) = constant_simple(cx, cx.tables, e) {
|
||||
span_lint(
|
||||
cx,
|
||||
|
|
|
@ -61,13 +61,13 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(EtaReduction => [REDUNDANT_CLOSURE, REDUNDANT_CLOSURE_FOR_METHOD_CALLS]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EtaReduction {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if in_external_macro(cx.sess(), expr.span) {
|
||||
return;
|
||||
}
|
||||
|
||||
match expr.kind {
|
||||
ExprKind::Call(_, ref args) | ExprKind::MethodCall(_, _, ref args) => {
|
||||
ExprKind::Call(_, args) | ExprKind::MethodCall(_, _, args) => {
|
||||
for arg in args {
|
||||
check_closure(cx, arg)
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EtaReduction {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr) {
|
||||
fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
|
||||
if let ExprKind::Closure(_, ref decl, eid, _, _) = expr.kind {
|
||||
let body = cx.tcx.hir().body(eid);
|
||||
let ex = &body.value;
|
||||
|
@ -99,7 +99,7 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr) {
|
|||
|
||||
if !type_is_unsafe_function(cx, fn_ty);
|
||||
|
||||
if compare_inputs(&mut iter_input_pats(decl, body), &mut args.into_iter());
|
||||
if compare_inputs(&mut iter_input_pats(decl, body), &mut args.iter());
|
||||
|
||||
then {
|
||||
span_lint_and_then(cx, REDUNDANT_CLOSURE, expr.span, "redundant closure found", |db| {
|
||||
|
@ -127,7 +127,7 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr) {
|
|||
let method_def_id = cx.tables.type_dependent_def_id(ex.hir_id).unwrap();
|
||||
if !type_is_unsafe_function(cx, cx.tcx.type_of(method_def_id));
|
||||
|
||||
if compare_inputs(&mut iter_input_pats(decl, body), &mut args.into_iter());
|
||||
if compare_inputs(&mut iter_input_pats(decl, body), &mut args.iter());
|
||||
|
||||
if let Some(name) = get_ufcs_type_name(cx, method_def_id, &args[0]);
|
||||
|
||||
|
@ -146,7 +146,7 @@ fn check_closure(cx: &LateContext<'_, '_>, expr: &Expr) {
|
|||
}
|
||||
|
||||
/// Tries to determine the type for universal function call to be used instead of the closure
|
||||
fn get_ufcs_type_name(cx: &LateContext<'_, '_>, method_def_id: def_id::DefId, self_arg: &Expr) -> Option<String> {
|
||||
fn get_ufcs_type_name(cx: &LateContext<'_, '_>, method_def_id: def_id::DefId, self_arg: &Expr<'_>) -> Option<String> {
|
||||
let expected_type_of_self = &cx.tcx.fn_sig(method_def_id).inputs_and_output().skip_binder()[0];
|
||||
let actual_type_of_self = &cx.tables.node_type(self_arg.hir_id);
|
||||
|
||||
|
@ -200,8 +200,8 @@ fn get_type_name(cx: &LateContext<'_, '_>, ty: Ty<'_>) -> String {
|
|||
}
|
||||
|
||||
fn compare_inputs(
|
||||
closure_inputs: &mut dyn Iterator<Item = &Param>,
|
||||
call_args: &mut dyn Iterator<Item = &Expr>,
|
||||
closure_inputs: &mut dyn Iterator<Item = &Param<'_>>,
|
||||
call_args: &mut dyn Iterator<Item = &Expr<'_>>,
|
||||
) -> bool {
|
||||
for (closure_input, function_arg) in closure_inputs.zip(call_args) {
|
||||
if let PatKind::Binding(_, _, ident, _) = closure_input.pat.kind {
|
||||
|
|
|
@ -59,7 +59,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(EvalOrderDependence => [EVAL_ORDER_DEPENDENCE, DIVERGING_SUB_EXPRESSION]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EvalOrderDependence {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
// Find a write to a local variable.
|
||||
match expr.kind {
|
||||
ExprKind::Assign(ref lhs, ..) | ExprKind::AssignOp(_, ref lhs, _) => {
|
||||
|
@ -82,7 +82,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EvalOrderDependence {
|
|||
_ => {},
|
||||
}
|
||||
}
|
||||
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) {
|
||||
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt<'_>) {
|
||||
match stmt.kind {
|
||||
StmtKind::Local(ref local) => {
|
||||
if let Local { init: Some(ref e), .. } = **local {
|
||||
|
@ -100,10 +100,10 @@ struct DivergenceVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> {
|
||||
fn maybe_walk_expr(&mut self, e: &'tcx Expr) {
|
||||
fn maybe_walk_expr(&mut self, e: &'tcx Expr<'_>) {
|
||||
match e.kind {
|
||||
ExprKind::Closure(..) => {},
|
||||
ExprKind::Match(ref e, ref arms, _) => {
|
||||
ExprKind::Match(ref e, arms, _) => {
|
||||
self.visit_expr(e);
|
||||
for arm in arms {
|
||||
if let Some(ref guard) = arm.guard {
|
||||
|
@ -118,13 +118,13 @@ impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> {
|
|||
_ => walk_expr(self, e),
|
||||
}
|
||||
}
|
||||
fn report_diverging_sub_expr(&mut self, e: &Expr) {
|
||||
fn report_diverging_sub_expr(&mut self, e: &Expr<'_>) {
|
||||
span_lint(self.cx, DIVERGING_SUB_EXPRESSION, e.span, "sub-expression diverges");
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, e: &'tcx Expr) {
|
||||
fn visit_expr(&mut self, e: &'tcx Expr<'_>) {
|
||||
match e.kind {
|
||||
ExprKind::Continue(_) | ExprKind::Break(_, _) | ExprKind::Ret(_) => self.report_diverging_sub_expr(e),
|
||||
ExprKind::Call(ref func, _) => {
|
||||
|
@ -153,7 +153,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> {
|
|||
}
|
||||
self.maybe_walk_expr(e);
|
||||
}
|
||||
fn visit_block(&mut self, _: &'tcx Block) {
|
||||
fn visit_block(&mut self, _: &'tcx Block<'_>) {
|
||||
// don't continue over blocks, LateLintPass already does that
|
||||
}
|
||||
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
|
||||
|
@ -214,7 +214,7 @@ enum StopEarly {
|
|||
Stop,
|
||||
}
|
||||
|
||||
fn check_expr<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, expr: &'tcx Expr) -> StopEarly {
|
||||
fn check_expr<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, expr: &'tcx Expr<'_>) -> StopEarly {
|
||||
if expr.hir_id == vis.last_expr.hir_id {
|
||||
return StopEarly::KeepGoing;
|
||||
}
|
||||
|
@ -261,7 +261,7 @@ fn check_expr<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, expr: &'tcx Expr) -> St
|
|||
StopEarly::KeepGoing
|
||||
}
|
||||
|
||||
fn check_stmt<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, stmt: &'tcx Stmt) -> StopEarly {
|
||||
fn check_stmt<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, stmt: &'tcx Stmt<'_>) -> StopEarly {
|
||||
match stmt.kind {
|
||||
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => check_expr(vis, expr),
|
||||
// If the declaration is of a local variable, check its initializer
|
||||
|
@ -281,14 +281,14 @@ struct ReadVisitor<'a, 'tcx> {
|
|||
var: HirId,
|
||||
/// The expressions where the write to the variable occurred (for reporting
|
||||
/// in the lint).
|
||||
write_expr: &'tcx Expr,
|
||||
write_expr: &'tcx Expr<'tcx>,
|
||||
/// The last (highest in the AST) expression we've checked, so we know not
|
||||
/// to recheck it.
|
||||
last_expr: &'tcx Expr,
|
||||
last_expr: &'tcx Expr<'tcx>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr) {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
|
||||
if expr.hir_id == self.last_expr.hir_id {
|
||||
return;
|
||||
}
|
||||
|
@ -343,7 +343,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.kind {
|
||||
return lhs.hir_id == expr.hir_id;
|
||||
|
|
|
@ -40,7 +40,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(ExcessivePrecision => [EXCESSIVE_PRECISION]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExcessivePrecision {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) {
|
||||
if_chain! {
|
||||
let ty = cx.tables.expr_ty(expr);
|
||||
if let ty::Float(fty) = ty.kind;
|
||||
|
|
|
@ -26,7 +26,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(Exit => [EXIT]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Exit {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
|
||||
if_chain! {
|
||||
if let ExprKind::Call(ref path_expr, ref _args) = e.kind;
|
||||
if let ExprKind::Path(ref path) = path_expr.kind;
|
||||
|
|
|
@ -30,18 +30,18 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(ExplicitWrite => [EXPLICIT_WRITE]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitWrite {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if_chain! {
|
||||
// match call to unwrap
|
||||
if let ExprKind::MethodCall(ref unwrap_fun, _, ref unwrap_args) = expr.kind;
|
||||
if unwrap_fun.ident.name == sym!(unwrap);
|
||||
// match call to write_fmt
|
||||
if unwrap_args.len() > 0;
|
||||
if let ExprKind::MethodCall(ref write_fun, _, ref write_args) =
|
||||
if !unwrap_args.is_empty();
|
||||
if let ExprKind::MethodCall(ref write_fun, _, write_args) =
|
||||
unwrap_args[0].kind;
|
||||
if write_fun.ident.name == sym!(write_fmt);
|
||||
// match calls to std::io::stdout() / std::io::stderr ()
|
||||
if write_args.len() > 0;
|
||||
if !write_args.is_empty();
|
||||
if let Some(dest_name) = if match_function_call(cx, &write_args[0], &paths::STDOUT).is_some() {
|
||||
Some("stdout")
|
||||
} else if match_function_call(cx, &write_args[0], &paths::STDERR).is_some() {
|
||||
|
@ -130,12 +130,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitWrite {
|
|||
}
|
||||
|
||||
// Extract the output string from the given `write_args`.
|
||||
fn write_output_string(write_args: &HirVec<Expr>) -> Option<String> {
|
||||
fn write_output_string(write_args: &[Expr<'_>]) -> Option<String> {
|
||||
if_chain! {
|
||||
// Obtain the string that should be printed
|
||||
if write_args.len() > 1;
|
||||
if let ExprKind::Call(_, ref output_args) = write_args[1].kind;
|
||||
if output_args.len() > 0;
|
||||
if !output_args.is_empty();
|
||||
if let ExprKind::AddrOf(BorrowKind::Ref, _, ref output_string_expr) = output_args[0].kind;
|
||||
if let ExprKind::Array(ref string_exprs) = output_string_expr.kind;
|
||||
// we only want to provide an automatic suggestion for simple (non-format) strings
|
||||
|
|
|
@ -57,7 +57,7 @@ fn lint_impl_body<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, impl_span: Span, impl_it
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr) {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
|
||||
// check for `begin_panic`
|
||||
if_chain! {
|
||||
if let ExprKind::Call(ref func_expr, _) = expr.kind;
|
||||
|
|
|
@ -38,7 +38,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(UselessFormat => [USELESS_FORMAT]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessFormat {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
let span = match is_expn_of(expr.span, "format") {
|
||||
Some(s) if !s.from_expansion() => s,
|
||||
_ => return,
|
||||
|
@ -72,7 +72,11 @@ fn span_useless_format<T: LintContext>(cx: &T, span: Span, help: &str, mut sugg:
|
|||
});
|
||||
}
|
||||
|
||||
fn on_argumentv1_new<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, arms: &'tcx [Arm]) -> Option<String> {
|
||||
fn on_argumentv1_new<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
expr: &'tcx Expr<'_>,
|
||||
arms: &'tcx [Arm<'_>],
|
||||
) -> Option<String> {
|
||||
if_chain! {
|
||||
if let ExprKind::AddrOf(BorrowKind::Ref, _, ref format_args) = expr.kind;
|
||||
if let ExprKind::Array(ref elems) = arms[0].body.kind;
|
||||
|
@ -111,7 +115,7 @@ fn on_argumentv1_new<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, arm
|
|||
None
|
||||
}
|
||||
|
||||
fn on_new_v1<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Option<String> {
|
||||
fn on_new_v1<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> Option<String> {
|
||||
if_chain! {
|
||||
if let Some(args) = match_function_call(cx, expr, &paths::FMT_ARGUMENTS_NEW_V1);
|
||||
if args.len() == 2;
|
||||
|
@ -138,7 +142,7 @@ fn on_new_v1<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Option<S
|
|||
None
|
||||
}
|
||||
|
||||
fn on_new_v1_fmt<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Option<String> {
|
||||
fn on_new_v1_fmt<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> Option<String> {
|
||||
if_chain! {
|
||||
if let Some(args) = match_function_call(cx, expr, &paths::FMT_ARGUMENTS_NEW_V1_FORMATTED);
|
||||
if args.len() == 3;
|
||||
|
@ -172,7 +176,7 @@ fn on_new_v1_fmt<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Opti
|
|||
/// ...,
|
||||
/// }]
|
||||
/// ```
|
||||
fn check_unformatted(expr: &Expr) -> bool {
|
||||
fn check_unformatted(expr: &Expr<'_>) -> bool {
|
||||
if_chain! {
|
||||
if let ExprKind::AddrOf(BorrowKind::Ref, _, ref expr) = expr.kind;
|
||||
if let ExprKind::Array(ref exprs) = expr.kind;
|
||||
|
|
|
@ -483,7 +483,7 @@ fn has_mutable_arg(cx: &LateContext<'_, '_>, body: &hir::Body<'_>) -> bool {
|
|||
body.params.iter().any(|param| is_mutable_pat(cx, ¶m.pat, &mut tys))
|
||||
}
|
||||
|
||||
fn is_mutable_pat(cx: &LateContext<'_, '_>, pat: &hir::Pat, tys: &mut FxHashSet<DefId>) -> bool {
|
||||
fn is_mutable_pat(cx: &LateContext<'_, '_>, pat: &hir::Pat<'_>, tys: &mut FxHashSet<DefId>) -> bool {
|
||||
if let hir::PatKind::Wild = pat.kind {
|
||||
return false; // ignore `_` patterns
|
||||
}
|
||||
|
@ -518,7 +518,7 @@ fn is_mutable_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>, span: Span,
|
|||
}
|
||||
}
|
||||
|
||||
fn raw_ptr_arg(arg: &hir::Param, ty: &hir::Ty) -> Option<hir::HirId> {
|
||||
fn raw_ptr_arg(arg: &hir::Param<'_>, ty: &hir::Ty) -> Option<hir::HirId> {
|
||||
if let (&hir::PatKind::Binding(_, id, _, _), &hir::TyKind::Ptr(_)) = (&arg.pat.kind, &ty.kind) {
|
||||
Some(id)
|
||||
} else {
|
||||
|
@ -533,9 +533,9 @@ struct DerefVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) {
|
||||
match expr.kind {
|
||||
hir::ExprKind::Call(ref f, ref args) => {
|
||||
hir::ExprKind::Call(ref f, args) => {
|
||||
let ty = self.tables.expr_ty(f);
|
||||
|
||||
if type_is_unsafe_function(self.cx, ty) {
|
||||
|
@ -544,7 +544,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
},
|
||||
hir::ExprKind::MethodCall(_, _, ref args) => {
|
||||
hir::ExprKind::MethodCall(_, _, args) => {
|
||||
let def_id = self.tables.type_dependent_def_id(expr.hir_id).unwrap();
|
||||
let base_type = self.cx.tcx.type_of(def_id);
|
||||
|
||||
|
@ -567,7 +567,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> DerefVisitor<'a, 'tcx> {
|
||||
fn check_arg(&self, ptr: &hir::Expr) {
|
||||
fn check_arg(&self, ptr: &hir::Expr<'_>) {
|
||||
if let hir::ExprKind::Path(ref qpath) = ptr.kind {
|
||||
if let Res::Local(id) = qpath_res(self.cx, qpath, ptr.hir_id) {
|
||||
if self.ptrs.contains(&id) {
|
||||
|
@ -589,14 +589,14 @@ struct StaticMutVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) {
|
||||
use hir::ExprKind::*;
|
||||
|
||||
if self.mutates_static {
|
||||
return;
|
||||
}
|
||||
match expr.kind {
|
||||
Call(_, ref args) | MethodCall(_, _, ref args) => {
|
||||
Call(_, args) | MethodCall(_, _, args) => {
|
||||
let mut tys = FxHashSet::default();
|
||||
for arg in args {
|
||||
let def_id = arg.hir_id.owner_def_id();
|
||||
|
@ -627,7 +627,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_mutated_static(cx: &LateContext<'_, '_>, e: &hir::Expr) -> bool {
|
||||
fn is_mutated_static(cx: &LateContext<'_, '_>, e: &hir::Expr<'_>) -> bool {
|
||||
use hir::ExprKind::*;
|
||||
|
||||
match e.kind {
|
||||
|
|
|
@ -46,7 +46,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(GetLastWithLen => [GET_LAST_WITH_LEN]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for GetLastWithLen {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if_chain! {
|
||||
// Is a method call
|
||||
if let ExprKind::MethodCall(ref path, _, ref args) = expr.kind;
|
||||
|
|
|
@ -32,7 +32,7 @@ pub struct IdentityConversion {
|
|||
impl_lint_pass!(IdentityConversion => [IDENTITY_CONVERSION]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
|
||||
if e.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_expr_post(&mut self, _: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
||||
fn check_expr_post(&mut self, _: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
|
||||
if Some(&e.hir_id) == self.try_desugar_arm.last() {
|
||||
self.try_desugar_arm.pop();
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(IdentityOp => [IDENTITY_OP]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityOp {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
|
||||
if e.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityOp {
|
|||
}
|
||||
|
||||
#[allow(clippy::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).kind {
|
||||
ty::Int(ity) => unsext(cx.tcx, -1_i128, ity),
|
||||
|
|
|
@ -62,8 +62,8 @@ fn lint(cx: &LateContext<'_, '_>, outer_span: Span, inner_span: Span, msg: &str)
|
|||
});
|
||||
}
|
||||
|
||||
fn expr_match(cx: &LateContext<'_, '_>, expr: &Expr) {
|
||||
match &expr.kind {
|
||||
fn expr_match(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
|
||||
match expr.kind {
|
||||
// loops could be using `break` instead of `return`
|
||||
ExprKind::Block(block, ..) | ExprKind::Loop(block, ..) => {
|
||||
if let Some(expr) = &block.expr {
|
||||
|
@ -92,7 +92,7 @@ fn expr_match(cx: &LateContext<'_, '_>, expr: &Expr) {
|
|||
let check_all_arms = match source {
|
||||
MatchSource::IfLetDesugar {
|
||||
contains_else_clause: has_else,
|
||||
} => *has_else,
|
||||
} => has_else,
|
||||
_ => true,
|
||||
};
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(IndexingSlicing => [INDEXING_SLICING, OUT_OF_BOUNDS_INDEXING]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if let ExprKind::Index(ref array, ref index) = &expr.kind {
|
||||
let ty = cx.tables.expr_ty(array);
|
||||
if let Some(range) = higher::range(cx, index) {
|
||||
|
|
|
@ -44,7 +44,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(InfallibleDestructingMatch => [INFALLIBLE_DESTRUCTURING_MATCH]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InfallibleDestructingMatch {
|
||||
fn check_local(&mut self, cx: &LateContext<'a, 'tcx>, local: &'tcx Local) {
|
||||
fn check_local(&mut self, cx: &LateContext<'a, 'tcx>, local: &'tcx Local<'_>) {
|
||||
if_chain! {
|
||||
if let Some(ref expr) = local.init;
|
||||
if let ExprKind::Match(ref target, ref arms, MatchSource::Normal) = expr.kind;
|
||||
|
|
|
@ -46,7 +46,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(InfiniteIter => [INFINITE_ITER, MAYBE_INFINITE_ITER]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InfiniteIter {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
let (lint, msg) = match complete_infinite_iter(cx, expr) {
|
||||
Infinite => (INFINITE_ITER, "infinite iteration detected"),
|
||||
MaybeInfinite => (MAYBE_INFINITE_ITER, "possible infinite iteration detected"),
|
||||
|
@ -141,7 +141,7 @@ const HEURISTICS: [(&str, usize, Heuristic, Finiteness); 19] = [
|
|||
("scan", 3, First, MaybeInfinite),
|
||||
];
|
||||
|
||||
fn is_infinite(cx: &LateContext<'_, '_>, expr: &Expr) -> Finiteness {
|
||||
fn is_infinite(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Finiteness {
|
||||
match expr.kind {
|
||||
ExprKind::MethodCall(ref method, _, ref args) => {
|
||||
for &(name, len, heuristic, cap) in &HEURISTICS {
|
||||
|
@ -217,7 +217,7 @@ const INFINITE_COLLECTORS: [&[&str]; 8] = [
|
|||
&paths::VEC_DEQUE,
|
||||
];
|
||||
|
||||
fn complete_infinite_iter(cx: &LateContext<'_, '_>, expr: &Expr) -> Finiteness {
|
||||
fn complete_infinite_iter(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Finiteness {
|
||||
match expr.kind {
|
||||
ExprKind::MethodCall(ref method, _, ref args) => {
|
||||
for &(name, len) in &COMPLETING_METHODS {
|
||||
|
|
|
@ -29,7 +29,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(IntegerDivision => [INTEGER_DIVISION]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IntegerDivision {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) {
|
||||
if is_integer_division(cx, expr) {
|
||||
span_help_and_lint(
|
||||
cx,
|
||||
|
@ -42,7 +42,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IntegerDivision {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_integer_division<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) -> bool {
|
||||
fn is_integer_division<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) -> bool {
|
||||
if_chain! {
|
||||
if let hir::ExprKind::Binary(binop, left, right) = &expr.kind;
|
||||
if let hir::BinOpKind::Div = &binop.node;
|
||||
|
|
|
@ -40,7 +40,7 @@ impl LargeStackArrays {
|
|||
impl_lint_pass!(LargeStackArrays => [LARGE_STACK_ARRAYS]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LargeStackArrays {
|
||||
fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
|
||||
if_chain! {
|
||||
if let ExprKind::Repeat(_, _) = expr.kind;
|
||||
if let ty::Array(element_type, cst) = cx.tables.expr_ty(expr).kind;
|
||||
|
|
|
@ -84,7 +84,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LenZero {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if expr.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ fn check_impl_items(cx: &LateContext<'_, '_>, item: &Item<'_>, impl_items: &[Imp
|
|||
}
|
||||
}
|
||||
|
||||
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.kind, &lit.kind) {
|
||||
// check if we are in an is_empty() method
|
||||
if let Some(name) = get_item_name(cx, method) {
|
||||
|
@ -224,7 +224,7 @@ fn check_len(
|
|||
cx: &LateContext<'_, '_>,
|
||||
span: Span,
|
||||
method_name: Name,
|
||||
args: &[Expr],
|
||||
args: &[Expr<'_>],
|
||||
lit: &LitKind,
|
||||
op: &str,
|
||||
compare_to: u32,
|
||||
|
@ -255,7 +255,7 @@ fn check_len(
|
|||
}
|
||||
|
||||
/// Checks 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 {
|
||||
/// Gets an `AssocItem` and return true if it matches `is_empty(self)`.
|
||||
fn is_is_empty(cx: &LateContext<'_, '_>, item: &ty::AssocItem) -> bool {
|
||||
if let ty::AssocKind::Method = item.kind {
|
||||
|
|
|
@ -56,7 +56,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(LetIfSeq => [USELESS_LET_IF_SEQ]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
|
||||
fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx hir::Block) {
|
||||
fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx hir::Block<'_>) {
|
||||
let mut it = block.stmts.iter().peekable();
|
||||
while let Some(stmt) = it.next() {
|
||||
if_chain! {
|
||||
|
@ -143,7 +143,7 @@ struct UsedVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for UsedVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) {
|
||||
if_chain! {
|
||||
if let hir::ExprKind::Path(ref qpath) = expr.kind;
|
||||
if let Res::Local(local_id) = qpath_res(self.cx, qpath, expr.hir_id);
|
||||
|
@ -163,8 +163,8 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for UsedVisitor<'a, 'tcx> {
|
|||
fn check_assign<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
decl: hir::HirId,
|
||||
block: &'tcx hir::Block,
|
||||
) -> Option<&'tcx hir::Expr> {
|
||||
block: &'tcx hir::Block<'_>,
|
||||
) -> Option<&'tcx hir::Expr<'tcx>> {
|
||||
if_chain! {
|
||||
if block.expr.is_none();
|
||||
if let Some(expr) = block.stmts.iter().last();
|
||||
|
@ -195,7 +195,7 @@ fn check_assign<'a, 'tcx>(
|
|||
None
|
||||
}
|
||||
|
||||
fn used_in_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, id: hir::HirId, expr: &'tcx hir::Expr) -> bool {
|
||||
fn used_in_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, id: hir::HirId, expr: &'tcx hir::Expr<'_>) -> bool {
|
||||
let mut v = UsedVisitor { cx, id, used: false };
|
||||
hir::intravisit::walk_expr(&mut v, expr);
|
||||
v.used
|
||||
|
|
|
@ -33,7 +33,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(LetUnderscore => [LET_UNDERSCORE_MUST_USE]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnderscore {
|
||||
fn check_stmt(&mut self, cx: &LateContext<'_, '_>, stmt: &Stmt) {
|
||||
fn check_stmt(&mut self, cx: &LateContext<'_, '_>, stmt: &Stmt<'_>) {
|
||||
if_chain! {
|
||||
if let StmtKind::Local(ref local) = stmt.kind;
|
||||
if let PatKind::Wild = local.pat.kind;
|
||||
|
|
|
@ -475,7 +475,7 @@ declare_lint_pass!(Loops => [
|
|||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Loops {
|
||||
#[allow(clippy::too_many_lines)]
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if let Some((pat, arg, body)) = higher::for_loop(expr) {
|
||||
// we don't want to check expanded macros
|
||||
// this check is not at the top of the function
|
||||
|
@ -651,14 +651,14 @@ fn combine_branches(b1: NeverLoopResult, b2: NeverLoopResult) -> NeverLoopResult
|
|||
}
|
||||
}
|
||||
|
||||
fn never_loop_block(block: &Block, main_loop_id: HirId) -> NeverLoopResult {
|
||||
fn never_loop_block(block: &Block<'_>, main_loop_id: HirId) -> NeverLoopResult {
|
||||
let stmts = block.stmts.iter().map(stmt_to_expr);
|
||||
let expr = once(block.expr.as_ref().map(|p| &**p));
|
||||
let mut iter = stmts.chain(expr).filter_map(|e| e);
|
||||
never_loop_expr_seq(&mut iter, main_loop_id)
|
||||
}
|
||||
|
||||
fn stmt_to_expr(stmt: &Stmt) -> Option<&Expr> {
|
||||
fn stmt_to_expr<'tcx>(stmt: &Stmt<'tcx>) -> Option<&'tcx Expr<'tcx>> {
|
||||
match stmt.kind {
|
||||
StmtKind::Semi(ref e, ..) | StmtKind::Expr(ref e, ..) => Some(e),
|
||||
StmtKind::Local(ref local) => local.init.as_ref().map(|p| &**p),
|
||||
|
@ -666,7 +666,7 @@ fn stmt_to_expr(stmt: &Stmt) -> Option<&Expr> {
|
|||
}
|
||||
}
|
||||
|
||||
fn never_loop_expr(expr: &Expr, main_loop_id: HirId) -> NeverLoopResult {
|
||||
fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult {
|
||||
match expr.kind {
|
||||
ExprKind::Box(ref e)
|
||||
| ExprKind::Unary(_, ref e)
|
||||
|
@ -726,27 +726,27 @@ fn never_loop_expr(expr: &Expr, main_loop_id: HirId) -> NeverLoopResult {
|
|||
}
|
||||
}
|
||||
|
||||
fn never_loop_expr_seq<'a, T: Iterator<Item = &'a Expr>>(es: &mut T, main_loop_id: HirId) -> NeverLoopResult {
|
||||
fn never_loop_expr_seq<'a, T: Iterator<Item = &'a Expr<'a>>>(es: &mut T, main_loop_id: HirId) -> NeverLoopResult {
|
||||
es.map(|e| never_loop_expr(e, main_loop_id))
|
||||
.fold(NeverLoopResult::Otherwise, combine_seq)
|
||||
}
|
||||
|
||||
fn never_loop_expr_all<'a, T: Iterator<Item = &'a Expr>>(es: &mut T, main_loop_id: HirId) -> NeverLoopResult {
|
||||
fn never_loop_expr_all<'a, T: Iterator<Item = &'a Expr<'a>>>(es: &mut T, main_loop_id: HirId) -> NeverLoopResult {
|
||||
es.map(|e| never_loop_expr(e, main_loop_id))
|
||||
.fold(NeverLoopResult::Otherwise, combine_both)
|
||||
}
|
||||
|
||||
fn never_loop_expr_branch<'a, T: Iterator<Item = &'a Expr>>(e: &mut T, main_loop_id: HirId) -> NeverLoopResult {
|
||||
fn never_loop_expr_branch<'a, T: Iterator<Item = &'a Expr<'a>>>(e: &mut T, main_loop_id: HirId) -> NeverLoopResult {
|
||||
e.map(|e| never_loop_expr(e, main_loop_id))
|
||||
.fold(NeverLoopResult::AlwaysBreak, combine_branches)
|
||||
}
|
||||
|
||||
fn check_for_loop<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
pat: &'tcx Pat,
|
||||
arg: &'tcx Expr,
|
||||
body: &'tcx Expr,
|
||||
expr: &'tcx Expr,
|
||||
pat: &'tcx Pat<'_>,
|
||||
arg: &'tcx Expr<'_>,
|
||||
body: &'tcx Expr<'_>,
|
||||
expr: &'tcx Expr<'_>,
|
||||
) {
|
||||
check_for_loop_range(cx, pat, arg, body, expr);
|
||||
check_for_loop_reverse_range(cx, arg, expr);
|
||||
|
@ -757,7 +757,7 @@ fn check_for_loop<'a, 'tcx>(
|
|||
detect_manual_memcpy(cx, pat, arg, body, expr);
|
||||
}
|
||||
|
||||
fn same_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var: HirId) -> bool {
|
||||
fn same_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr<'_>, var: HirId) -> bool {
|
||||
if_chain! {
|
||||
if let ExprKind::Path(ref qpath) = expr.kind;
|
||||
if let QPath::Resolved(None, ref path) = *qpath;
|
||||
|
@ -806,8 +806,8 @@ fn is_slice_like<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'_>) -> bool {
|
|||
is_slice || is_type_diagnostic_item(cx, ty, Symbol::intern("vec_type")) || match_type(cx, ty, &paths::VEC_DEQUE)
|
||||
}
|
||||
|
||||
fn get_fixed_offset_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var: HirId) -> Option<FixedOffsetVar> {
|
||||
fn extract_offset<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, e: &Expr, var: HirId) -> Option<String> {
|
||||
fn get_fixed_offset_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr<'_>, var: HirId) -> Option<FixedOffsetVar> {
|
||||
fn extract_offset<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, e: &Expr<'_>, var: HirId) -> Option<String> {
|
||||
match e.kind {
|
||||
ExprKind::Lit(ref l) => match l.node {
|
||||
ast::LitKind::Int(x, _ty) => Some(x.to_string()),
|
||||
|
@ -861,7 +861,7 @@ fn get_fixed_offset_var<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr, var:
|
|||
|
||||
fn fetch_cloned_fixed_offset_var<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
expr: &Expr,
|
||||
expr: &Expr<'_>,
|
||||
var: HirId,
|
||||
) -> Option<FixedOffsetVar> {
|
||||
if_chain! {
|
||||
|
@ -879,12 +879,12 @@ fn fetch_cloned_fixed_offset_var<'a, 'tcx>(
|
|||
|
||||
fn get_indexed_assignments<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
body: &Expr,
|
||||
body: &Expr<'_>,
|
||||
var: HirId,
|
||||
) -> Vec<(FixedOffsetVar, FixedOffsetVar)> {
|
||||
fn get_assignment<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
e: &Expr,
|
||||
e: &Expr<'_>,
|
||||
var: HirId,
|
||||
) -> Option<(FixedOffsetVar, FixedOffsetVar)> {
|
||||
if let ExprKind::Assign(ref lhs, ref rhs, _) = e.kind {
|
||||
|
@ -931,10 +931,10 @@ fn get_indexed_assignments<'a, 'tcx>(
|
|||
/// object to another.
|
||||
fn detect_manual_memcpy<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
pat: &'tcx Pat,
|
||||
arg: &'tcx Expr,
|
||||
body: &'tcx Expr,
|
||||
expr: &'tcx Expr,
|
||||
pat: &'tcx Pat<'_>,
|
||||
arg: &'tcx Expr<'_>,
|
||||
body: &'tcx Expr<'_>,
|
||||
expr: &'tcx Expr<'_>,
|
||||
) {
|
||||
if let Some(higher::Range {
|
||||
start: Some(start),
|
||||
|
@ -968,7 +968,7 @@ fn detect_manual_memcpy<'a, 'tcx>(
|
|||
}
|
||||
};
|
||||
|
||||
let print_limit = |end: &Option<&Expr>, offset: Offset, var_name: &str| {
|
||||
let print_limit = |end: &Option<&Expr<'_>>, offset: Offset, var_name: &str| {
|
||||
if let Some(end) = *end {
|
||||
if_chain! {
|
||||
if let ExprKind::MethodCall(ref method, _, ref len_args) = end.kind;
|
||||
|
@ -1044,10 +1044,10 @@ fn detect_manual_memcpy<'a, 'tcx>(
|
|||
#[allow(clippy::too_many_lines)]
|
||||
fn check_for_loop_range<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
pat: &'tcx Pat,
|
||||
arg: &'tcx Expr,
|
||||
body: &'tcx Expr,
|
||||
expr: &'tcx Expr,
|
||||
pat: &'tcx Pat<'_>,
|
||||
arg: &'tcx Expr<'_>,
|
||||
body: &'tcx Expr<'_>,
|
||||
expr: &'tcx Expr<'_>,
|
||||
) {
|
||||
if let Some(higher::Range {
|
||||
start: Some(start),
|
||||
|
@ -1206,7 +1206,7 @@ fn check_for_loop_range<'a, 'tcx>(
|
|||
}
|
||||
}
|
||||
|
||||
fn is_len_call(expr: &Expr, var: Name) -> bool {
|
||||
fn is_len_call(expr: &Expr<'_>, var: Name) -> bool {
|
||||
if_chain! {
|
||||
if let ExprKind::MethodCall(ref method, _, ref len_args) = expr.kind;
|
||||
if len_args.len() == 1;
|
||||
|
@ -1224,7 +1224,7 @@ fn is_len_call(expr: &Expr, var: Name) -> bool {
|
|||
|
||||
fn is_end_eq_array_len<'tcx>(
|
||||
cx: &LateContext<'_, 'tcx>,
|
||||
end: &Expr,
|
||||
end: &Expr<'_>,
|
||||
limits: ast::RangeLimits,
|
||||
indexed_ty: Ty<'tcx>,
|
||||
) -> bool {
|
||||
|
@ -1244,7 +1244,7 @@ fn is_end_eq_array_len<'tcx>(
|
|||
false
|
||||
}
|
||||
|
||||
fn check_for_loop_reverse_range<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arg: &'tcx Expr, expr: &'tcx Expr) {
|
||||
fn check_for_loop_reverse_range<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arg: &'tcx Expr<'_>, expr: &'tcx Expr<'_>) {
|
||||
// if this for loop is iterating over a two-sided range...
|
||||
if let Some(higher::Range {
|
||||
start: Some(start),
|
||||
|
@ -1316,7 +1316,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 mut applicability = Applicability::MachineApplicable;
|
||||
let object = snippet_with_applicability(cx, args[0].span, "_", &mut applicability);
|
||||
let muta = if method_name == "iter_mut" { "mut " } else { "" };
|
||||
|
@ -1332,7 +1332,7 @@ fn lint_iter_method(cx: &LateContext<'_, '_>, args: &[Expr], arg: &Expr, method_
|
|||
)
|
||||
}
|
||||
|
||||
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.kind {
|
||||
// just the receiver, no arguments
|
||||
|
@ -1389,7 +1389,7 @@ fn check_for_loop_arg(cx: &LateContext<'_, '_>, pat: &Pat, arg: &Expr, expr: &Ex
|
|||
}
|
||||
|
||||
/// Checks for `for` loops over `Option`s and `Result`s.
|
||||
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(
|
||||
|
@ -1428,10 +1428,10 @@ fn check_arg_type(cx: &LateContext<'_, '_>, pat: &Pat, arg: &Expr) {
|
|||
|
||||
fn check_for_loop_explicit_counter<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
pat: &'tcx Pat,
|
||||
arg: &'tcx Expr,
|
||||
body: &'tcx Expr,
|
||||
expr: &'tcx Expr,
|
||||
pat: &'tcx Pat<'_>,
|
||||
arg: &'tcx Expr<'_>,
|
||||
body: &'tcx Expr<'_>,
|
||||
expr: &'tcx Expr<'_>,
|
||||
) {
|
||||
// Look for variables that are incremented once per loop iteration.
|
||||
let mut visitor = IncrementVisitor {
|
||||
|
@ -1491,7 +1491,7 @@ fn check_for_loop_explicit_counter<'a, 'tcx>(
|
|||
|
||||
/// If `arg` was the argument to a `for` loop, return the "cleanest" way of writing the
|
||||
/// actual `Iterator` that the loop uses.
|
||||
fn make_iterator_snippet(cx: &LateContext<'_, '_>, arg: &Expr, applic_ref: &mut Applicability) -> String {
|
||||
fn make_iterator_snippet(cx: &LateContext<'_, '_>, arg: &Expr<'_>, applic_ref: &mut Applicability) -> String {
|
||||
let impls_iterator = get_trait_def_id(cx, &paths::ITERATOR)
|
||||
.map_or(false, |id| implements_trait(cx, cx.tables.expr_ty(arg), id, &[]));
|
||||
if impls_iterator {
|
||||
|
@ -1527,10 +1527,10 @@ fn make_iterator_snippet(cx: &LateContext<'_, '_>, arg: &Expr, applic_ref: &mut
|
|||
/// Checks for the `FOR_KV_MAP` lint.
|
||||
fn check_for_loop_over_map_kv<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
pat: &'tcx Pat,
|
||||
arg: &'tcx Expr,
|
||||
body: &'tcx Expr,
|
||||
expr: &'tcx Expr,
|
||||
pat: &'tcx Pat<'_>,
|
||||
arg: &'tcx Expr<'_>,
|
||||
body: &'tcx Expr<'_>,
|
||||
expr: &'tcx Expr<'_>,
|
||||
) {
|
||||
let pat_span = pat.span;
|
||||
|
||||
|
@ -1618,7 +1618,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),
|
||||
|
@ -1645,7 +1645,7 @@ fn mut_warn_with_span(cx: &LateContext<'_, '_>, span: Option<Span>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_for_mutability(cx: &LateContext<'_, '_>, bound: &Expr) -> Option<HirId> {
|
||||
fn check_for_mutability(cx: &LateContext<'_, '_>, bound: &Expr<'_>) -> Option<HirId> {
|
||||
if_chain! {
|
||||
if let ExprKind::Path(ref qpath) = bound.kind;
|
||||
if let QPath::Resolved(None, _) = *qpath;
|
||||
|
@ -1669,7 +1669,7 @@ fn check_for_mutability(cx: &LateContext<'_, '_>, bound: &Expr) -> Option<HirId>
|
|||
|
||||
fn check_for_mutation(
|
||||
cx: &LateContext<'_, '_>,
|
||||
body: &Expr,
|
||||
body: &Expr<'_>,
|
||||
bound_ids: &[Option<HirId>],
|
||||
) -> (Option<Span>, Option<Span>) {
|
||||
let mut delegate = MutatePairDelegate {
|
||||
|
@ -1686,7 +1686,7 @@ fn check_for_mutation(
|
|||
}
|
||||
|
||||
/// Returns `true` if the pattern is a `PatWild` or an ident prefixed with `_`.
|
||||
fn pat_is_wild<'tcx>(pat: &'tcx PatKind, body: &'tcx Expr) -> bool {
|
||||
fn pat_is_wild<'tcx>(pat: &'tcx PatKind<'_>, body: &'tcx Expr<'_>) -> bool {
|
||||
match *pat {
|
||||
PatKind::Wild => true,
|
||||
PatKind::Binding(.., ident, None) if ident.as_str().starts_with('_') => {
|
||||
|
@ -1707,7 +1707,7 @@ struct UsedVisitor {
|
|||
}
|
||||
|
||||
impl<'tcx> Visitor<'tcx> for UsedVisitor {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr) {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
|
||||
if match_var(expr, self.var) {
|
||||
self.used = true;
|
||||
} else {
|
||||
|
@ -1727,7 +1727,7 @@ struct LocalUsedVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for LocalUsedVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr) {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
|
||||
if same_var(self.cx, expr, self.local) {
|
||||
self.used = true;
|
||||
} else {
|
||||
|
@ -1764,7 +1764,7 @@ struct VarVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
|
||||
fn check(&mut self, idx: &'tcx Expr, seqexpr: &'tcx Expr, expr: &'tcx Expr) -> bool {
|
||||
fn check(&mut self, idx: &'tcx Expr<'_>, seqexpr: &'tcx Expr<'_>, expr: &'tcx Expr<'_>) -> bool {
|
||||
if_chain! {
|
||||
// the indexed container is referenced by a name
|
||||
if let ExprKind::Path(ref seqpath) = seqexpr.kind;
|
||||
|
@ -1825,7 +1825,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr) {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
|
||||
if_chain! {
|
||||
// a range index op
|
||||
if let ExprKind::MethodCall(ref meth, _, ref args) = expr.kind;
|
||||
|
@ -1873,7 +1873,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
|
|||
}
|
||||
self.visit_expr(expr);
|
||||
},
|
||||
ExprKind::Call(ref f, ref args) => {
|
||||
ExprKind::Call(ref f, args) => {
|
||||
self.visit_expr(f);
|
||||
for expr in args {
|
||||
let ty = self.cx.tables.expr_ty_adjusted(expr);
|
||||
|
@ -1886,7 +1886,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
|
|||
self.visit_expr(expr);
|
||||
}
|
||||
},
|
||||
ExprKind::MethodCall(_, _, ref args) => {
|
||||
ExprKind::MethodCall(_, _, args) => {
|
||||
let def_id = self.cx.tables.type_dependent_def_id(expr.hir_id).unwrap();
|
||||
for (ty, expr) in self.cx.tcx.fn_sig(def_id).inputs().skip_binder().iter().zip(args) {
|
||||
self.prefer_mutable = false;
|
||||
|
@ -1911,7 +1911,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_used_inside<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, expr: &'tcx Expr, container: &'tcx Expr) -> bool {
|
||||
fn is_used_inside<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>, container: &'tcx Expr<'_>) -> bool {
|
||||
let def_id = match var_def_id(cx, expr) {
|
||||
Some(id) => id,
|
||||
None => return false,
|
||||
|
@ -1924,7 +1924,7 @@ fn is_used_inside<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, expr: &'tcx Expr, con
|
|||
false
|
||||
}
|
||||
|
||||
fn is_iterator_used_after_while_let<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, iter_expr: &'tcx Expr) -> bool {
|
||||
fn is_iterator_used_after_while_let<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, iter_expr: &'tcx Expr<'_>) -> bool {
|
||||
let def_id = match var_def_id(cx, iter_expr) {
|
||||
Some(id) => id,
|
||||
None => return false,
|
||||
|
@ -1951,7 +1951,7 @@ struct VarUsedAfterLoopVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for VarUsedAfterLoopVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr) {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
|
||||
if self.past_while_let {
|
||||
if Some(self.def_id) == var_def_id(self.cx, expr) {
|
||||
self.var_used_after_while_let = true;
|
||||
|
@ -1969,7 +1969,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarUsedAfterLoopVisitor<'a, 'tcx> {
|
|||
/// Returns `true` if the type of expr is one that provides `IntoIterator` impls
|
||||
/// for `&T` and `&mut T`, such as `Vec`.
|
||||
#[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);
|
||||
|
@ -2000,12 +2000,12 @@ fn is_iterable_array<'tcx>(ty: Ty<'tcx>, cx: &LateContext<'_, 'tcx>) -> bool {
|
|||
|
||||
/// If a block begins with a statement (possibly a `let` binding) and has an
|
||||
/// expression, return it.
|
||||
fn extract_expr_from_first_stmt(block: &Block) -> Option<&Expr> {
|
||||
fn extract_expr_from_first_stmt<'tcx>(block: &Block<'tcx>) -> Option<&'tcx Expr<'tcx>> {
|
||||
if block.stmts.is_empty() {
|
||||
return None;
|
||||
}
|
||||
if let StmtKind::Local(ref local) = block.stmts[0].kind {
|
||||
if let Some(ref expr) = local.init {
|
||||
if let Some(expr) = local.init {
|
||||
Some(expr)
|
||||
} else {
|
||||
None
|
||||
|
@ -2016,7 +2016,7 @@ fn extract_expr_from_first_stmt(block: &Block) -> Option<&Expr> {
|
|||
}
|
||||
|
||||
/// If a block begins with an expression (with or without semicolon), return it.
|
||||
fn extract_first_expr(block: &Block) -> Option<&Expr> {
|
||||
fn extract_first_expr<'tcx>(block: &Block<'tcx>) -> Option<&'tcx Expr<'tcx>> {
|
||||
match block.expr {
|
||||
Some(ref expr) if block.stmts.is_empty() => Some(expr),
|
||||
None if !block.stmts.is_empty() => match block.stmts[0].kind {
|
||||
|
@ -2030,7 +2030,7 @@ fn extract_first_expr(block: &Block) -> Option<&Expr> {
|
|||
/// Returns `true` if expr contains a single break expr without destination label
|
||||
/// and
|
||||
/// passed expression. The expression may be within a block.
|
||||
fn is_simple_break_expr(expr: &Expr) -> bool {
|
||||
fn is_simple_break_expr(expr: &Expr<'_>) -> bool {
|
||||
match expr.kind {
|
||||
ExprKind::Break(dest, ref passed_expr) if dest.label.is_none() && passed_expr.is_none() => true,
|
||||
ExprKind::Block(ref b, _) => extract_first_expr(b).map_or(false, |subexpr| is_simple_break_expr(subexpr)),
|
||||
|
@ -2059,7 +2059,7 @@ struct IncrementVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr) {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
|
||||
if self.done {
|
||||
return;
|
||||
}
|
||||
|
@ -2109,7 +2109,7 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> {
|
|||
/// Checks whether a variable is initialized to zero at the start of a loop.
|
||||
struct InitializeVisitor<'a, 'tcx> {
|
||||
cx: &'a LateContext<'a, 'tcx>, // context reference
|
||||
end_expr: &'tcx Expr, // the for loop. Stop scanning here.
|
||||
end_expr: &'tcx Expr<'tcx>, // the for loop. Stop scanning here.
|
||||
var_id: HirId,
|
||||
state: VarState,
|
||||
name: Option<Name>,
|
||||
|
@ -2118,7 +2118,7 @@ struct InitializeVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
|
||||
fn visit_stmt(&mut self, stmt: &'tcx Stmt) {
|
||||
fn visit_stmt(&mut self, stmt: &'tcx Stmt<'_>) {
|
||||
// Look for declarations of the variable
|
||||
if let StmtKind::Local(ref local) = stmt.kind {
|
||||
if local.pat.hir_id == self.var_id {
|
||||
|
@ -2140,7 +2140,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
|
|||
walk_stmt(self, stmt);
|
||||
}
|
||||
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr) {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
|
||||
if self.state == VarState::DontWarn {
|
||||
return;
|
||||
}
|
||||
|
@ -2196,7 +2196,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn var_def_id(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<HirId> {
|
||||
fn var_def_id(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> Option<HirId> {
|
||||
if let ExprKind::Path(ref qpath) = expr.kind {
|
||||
let path_res = qpath_res(cx, qpath, expr.hir_id);
|
||||
if let Res::Local(node_id) = path_res {
|
||||
|
@ -2206,21 +2206,21 @@ fn var_def_id(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<HirId> {
|
|||
None
|
||||
}
|
||||
|
||||
fn is_loop(expr: &Expr) -> bool {
|
||||
fn is_loop(expr: &Expr<'_>) -> bool {
|
||||
match expr.kind {
|
||||
ExprKind::Loop(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn is_conditional(expr: &Expr) -> bool {
|
||||
fn is_conditional(expr: &Expr<'_>) -> bool {
|
||||
match expr.kind {
|
||||
ExprKind::Match(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
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.hir_id);
|
||||
let parent_node = cx.tcx.hir().get_parent_node(loop_block.hir_id);
|
||||
|
@ -2232,7 +2232,7 @@ fn is_nested(cx: &LateContext<'_, '_>, match_expr: &Expr, iter_expr: &Expr) -> b
|
|||
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.hir_id;
|
||||
let iter_name = if let Some(name) = path_name(iter_expr) {
|
||||
name
|
||||
|
@ -2286,7 +2286,7 @@ struct LoopNestVisitor {
|
|||
}
|
||||
|
||||
impl<'tcx> Visitor<'tcx> for LoopNestVisitor {
|
||||
fn visit_stmt(&mut self, stmt: &'tcx Stmt) {
|
||||
fn visit_stmt(&mut self, stmt: &'tcx Stmt<'_>) {
|
||||
if stmt.hir_id == self.hir_id {
|
||||
self.nesting = LookFurther;
|
||||
} else if self.nesting == Unknown {
|
||||
|
@ -2294,7 +2294,7 @@ impl<'tcx> Visitor<'tcx> for LoopNestVisitor {
|
|||
}
|
||||
}
|
||||
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr) {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
|
||||
if self.nesting != Unknown {
|
||||
return;
|
||||
}
|
||||
|
@ -2312,7 +2312,7 @@ impl<'tcx> Visitor<'tcx> for LoopNestVisitor {
|
|||
}
|
||||
}
|
||||
|
||||
fn visit_pat(&mut self, pat: &'tcx Pat) {
|
||||
fn visit_pat(&mut self, pat: &'tcx Pat<'_>) {
|
||||
if self.nesting != Unknown {
|
||||
return;
|
||||
}
|
||||
|
@ -2330,7 +2330,7 @@ impl<'tcx> Visitor<'tcx> for LoopNestVisitor {
|
|||
}
|
||||
}
|
||||
|
||||
fn path_name(e: &Expr) -> Option<Name> {
|
||||
fn path_name(e: &Expr<'_>) -> Option<Name> {
|
||||
if let ExprKind::Path(QPath::Resolved(_, ref path)) = e.kind {
|
||||
let segments = &path.segments;
|
||||
if segments.len() == 1 {
|
||||
|
@ -2340,7 +2340,7 @@ fn path_name(e: &Expr) -> Option<Name> {
|
|||
None
|
||||
}
|
||||
|
||||
fn check_infinite_loop<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, cond: &'tcx Expr, expr: &'tcx Expr) {
|
||||
fn check_infinite_loop<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, cond: &'tcx Expr<'_>, expr: &'tcx Expr<'_>) {
|
||||
if constant(cx, cx.tables, cond).is_some() {
|
||||
// A pure constant condition (e.g., `while false`) is not linted.
|
||||
return;
|
||||
|
@ -2393,7 +2393,7 @@ struct HasBreakOrReturnVisitor {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for HasBreakOrReturnVisitor {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr) {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
|
||||
if self.has_break_or_return {
|
||||
return;
|
||||
}
|
||||
|
@ -2426,7 +2426,7 @@ struct VarCollectorVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> {
|
||||
fn insert_def_id(&mut self, ex: &'tcx Expr) {
|
||||
fn insert_def_id(&mut self, ex: &'tcx Expr<'_>) {
|
||||
if_chain! {
|
||||
if let ExprKind::Path(ref qpath) = ex.kind;
|
||||
if let QPath::Resolved(None, _) = *qpath;
|
||||
|
@ -2448,7 +2448,7 @@ impl<'a, 'tcx> VarCollectorVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for VarCollectorVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, ex: &'tcx Expr) {
|
||||
fn visit_expr(&mut self, ex: &'tcx Expr<'_>) {
|
||||
match ex.kind {
|
||||
ExprKind::Path(_) => self.insert_def_id(ex),
|
||||
// If there is any function/method call… we just stop analysis
|
||||
|
@ -2465,7 +2465,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarCollectorVisitor<'a, 'tcx> {
|
|||
|
||||
const NEEDLESS_COLLECT_MSG: &str = "avoid using `collect()` when not needed";
|
||||
|
||||
fn check_needless_collect<'a, 'tcx>(expr: &'tcx Expr, cx: &LateContext<'a, 'tcx>) {
|
||||
fn check_needless_collect<'a, 'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'a, 'tcx>) {
|
||||
if_chain! {
|
||||
if let ExprKind::MethodCall(ref method, _, ref args) = expr.kind;
|
||||
if let ExprKind::MethodCall(ref chain_method, _, _) = args[0].kind;
|
||||
|
@ -2525,7 +2525,7 @@ fn check_needless_collect<'a, 'tcx>(expr: &'tcx Expr, cx: &LateContext<'a, 'tcx>
|
|||
}
|
||||
}
|
||||
|
||||
fn shorten_needless_collect_span(expr: &Expr) -> Span {
|
||||
fn shorten_needless_collect_span(expr: &Expr<'_>) -> Span {
|
||||
if_chain! {
|
||||
if let ExprKind::MethodCall(_, _, ref args) = expr.kind;
|
||||
if let ExprKind::MethodCall(_, ref span, _) = args[0].kind;
|
||||
|
|
|
@ -45,7 +45,7 @@ impl LateLintPass<'_, '_> for MainRecursion {
|
|||
});
|
||||
}
|
||||
|
||||
fn check_expr_post(&mut self, cx: &LateContext<'_, '_>, expr: &Expr) {
|
||||
fn check_expr_post(&mut self, cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
|
||||
if self.has_no_std_attr {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(MapClone => [MAP_CLONE]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapClone {
|
||||
fn check_expr(&mut self, cx: &LateContext<'_, '_>, e: &hir::Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'_, '_>, e: &hir::Expr<'_>) {
|
||||
if e.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapClone {
|
|||
}
|
||||
}
|
||||
|
||||
fn ident_eq(name: Ident, path: &hir::Expr) -> bool {
|
||||
fn ident_eq(name: Ident, path: &hir::Expr<'_>) -> bool {
|
||||
if let hir::ExprKind::Path(hir::QPath::Resolved(None, ref path)) = path.kind {
|
||||
path.segments.len() == 1 && path.segments[0].ident == name
|
||||
} else {
|
||||
|
|
|
@ -102,7 +102,7 @@ fn is_unit_type(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::FnDef(id, _) = ty.kind {
|
||||
|
@ -113,7 +113,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))
|
||||
}
|
||||
|
||||
|
@ -121,7 +121,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;
|
||||
}
|
||||
|
@ -164,8 +164,8 @@ fn reduce_unit_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a hir::Expr) ->
|
|||
|
||||
fn unit_closure<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
expr: &'a hir::Expr,
|
||||
) -> Option<(&'tcx hir::Param, &'a hir::Expr)> {
|
||||
expr: &'a hir::Expr<'a>,
|
||||
) -> Option<(&'tcx hir::Param<'tcx>, &'a hir::Expr<'a>)> {
|
||||
if let hir::ExprKind::Closure(_, ref decl, inner_expr_id, _, _) = expr.kind {
|
||||
let body = cx.tcx.hir().body(inner_expr_id);
|
||||
let body_expr = &body.value;
|
||||
|
@ -188,7 +188,7 @@ fn unit_closure<'a, 'tcx>(
|
|||
/// `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.kind {
|
||||
hir::ExprKind::Field(_, _) => snippet(cx, var_arg.span, "_").replace(".", "_"),
|
||||
hir::ExprKind::Path(_) => format!("_{}", snippet(cx, var_arg.span, "")),
|
||||
|
@ -204,7 +204,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 (map_type, variant, lint) = if match_type(cx, cx.tables.expr_ty(var_arg), &paths::OPTION) {
|
||||
|
@ -261,7 +261,7 @@ fn lint_map_unit_fn(cx: &LateContext<'_, '_>, stmt: &hir::Stmt, expr: &hir::Expr
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MapUnit {
|
||||
fn check_stmt(&mut self, cx: &LateContext<'_, '_>, stmt: &hir::Stmt) {
|
||||
fn check_stmt(&mut self, cx: &LateContext<'_, '_>, stmt: &hir::Stmt<'_>) {
|
||||
if stmt.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -235,7 +235,7 @@ declare_lint_pass!(Matches => [
|
|||
]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Matches {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if in_external_macro(cx.sess(), expr.span) {
|
||||
return;
|
||||
}
|
||||
|
@ -254,7 +254,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Matches {
|
|||
}
|
||||
|
||||
#[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].guard.is_none() && arms[1].guard.is_none() {
|
||||
if let PatKind::Or(..) = arms[0].pat.kind {
|
||||
// don't lint for or patterns for now, this makes
|
||||
|
@ -281,10 +281,10 @@ fn check_single_match(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &
|
|||
|
||||
fn check_single_match_single_pattern(
|
||||
cx: &LateContext<'_, '_>,
|
||||
ex: &Expr,
|
||||
arms: &[Arm],
|
||||
expr: &Expr,
|
||||
els: Option<&Expr>,
|
||||
ex: &Expr<'_>,
|
||||
arms: &[Arm<'_>],
|
||||
expr: &Expr<'_>,
|
||||
els: Option<&Expr<'_>>,
|
||||
) {
|
||||
if is_wild(&arms[1].pat) {
|
||||
report_single_match_single_pattern(cx, ex, arms, expr, els);
|
||||
|
@ -293,10 +293,10 @@ fn check_single_match_single_pattern(
|
|||
|
||||
fn report_single_match_single_pattern(
|
||||
cx: &LateContext<'_, '_>,
|
||||
ex: &Expr,
|
||||
arms: &[Arm],
|
||||
expr: &Expr,
|
||||
els: Option<&Expr>,
|
||||
ex: &Expr<'_>,
|
||||
arms: &[Arm<'_>],
|
||||
expr: &Expr<'_>,
|
||||
els: Option<&Expr<'_>>,
|
||||
) {
|
||||
let lint = if els.is_some() { SINGLE_MATCH_ELSE } else { SINGLE_MATCH };
|
||||
let els_str = els.map_or(String::new(), |els| {
|
||||
|
@ -322,11 +322,11 @@ fn report_single_match_single_pattern(
|
|||
|
||||
fn check_single_match_opt_like(
|
||||
cx: &LateContext<'_, '_>,
|
||||
ex: &Expr,
|
||||
arms: &[Arm],
|
||||
expr: &Expr,
|
||||
ex: &Expr<'_>,
|
||||
arms: &[Arm<'_>],
|
||||
expr: &Expr<'_>,
|
||||
ty: Ty<'_>,
|
||||
els: Option<&Expr>,
|
||||
els: Option<&Expr<'_>>,
|
||||
) {
|
||||
// list of candidate `Enum`s we know will never get any more members
|
||||
let candidates = &[
|
||||
|
@ -359,7 +359,7 @@ fn check_single_match_opt_like(
|
|||
}
|
||||
}
|
||||
|
||||
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 is `bool`.
|
||||
if cx.tables.expr_ty(ex).kind == ty::Bool {
|
||||
span_lint_and_then(
|
||||
|
@ -419,7 +419,7 @@ fn check_match_bool(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &Ex
|
|||
}
|
||||
}
|
||||
|
||||
fn check_overlapping_arms<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ex: &'tcx Expr, arms: &'tcx [Arm]) {
|
||||
fn check_overlapping_arms<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ex: &'tcx Expr<'_>, arms: &'tcx [Arm<'_>]) {
|
||||
if arms.len() >= 2 && cx.tables.expr_ty(ex).is_integral() {
|
||||
let ranges = all_ranges(cx, arms);
|
||||
let type_ranges = type_ranges(&ranges);
|
||||
|
@ -438,14 +438,14 @@ fn check_overlapping_arms<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ex: &'tcx Expr,
|
|||
}
|
||||
}
|
||||
|
||||
fn is_wild(pat: &impl std::ops::Deref<Target = Pat>) -> bool {
|
||||
fn is_wild<'tcx>(pat: &impl std::ops::Deref<Target = Pat<'tcx>>) -> bool {
|
||||
match pat.kind {
|
||||
PatKind::Wild => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -472,7 +472,7 @@ fn check_wild_err_arm(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm]) {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_wild_enum_match(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm]) {
|
||||
fn check_wild_enum_match(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>]) {
|
||||
let ty = cx.tables.expr_ty(ex);
|
||||
if !ty.is_enum() {
|
||||
// If there isn't a nice closed set of possible values that can be conveniently enumerated,
|
||||
|
@ -565,7 +565,7 @@ fn check_wild_enum_match(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm]) {
|
|||
}
|
||||
|
||||
// If the block contains only a `panic!` macro (as expression or statement)
|
||||
fn is_panic_block(block: &Block) -> bool {
|
||||
fn is_panic_block(block: &Block<'_>) -> bool {
|
||||
match (&block.expr, block.stmts.len(), block.stmts.first()) {
|
||||
(&Some(ref exp), 0, _) => {
|
||||
is_expn_of(exp.span, "panic").is_some() && is_expn_of(exp.span, "unreachable").is_none()
|
||||
|
@ -577,7 +577,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(BorrowKind::Ref, Mutability::Not, ref inner) = ex.kind {
|
||||
|
@ -612,7 +612,7 @@ fn check_match_ref_pats(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], 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].guard.is_none() && arms[1].guard.is_none() {
|
||||
let arm_ref: Option<BindingAnnotation> = if is_none_arm(&arms[0]) {
|
||||
is_ref_some_arm(&arms[1])
|
||||
|
@ -665,7 +665,7 @@ fn check_match_as_ref(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &
|
|||
}
|
||||
|
||||
/// Gets all arms that are unbounded `PatRange`s.
|
||||
fn all_ranges<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arms: &'tcx [Arm]) -> Vec<SpannedRange<Constant>> {
|
||||
fn all_ranges<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arms: &'tcx [Arm<'_>]) -> Vec<SpannedRange<Constant>> {
|
||||
arms.iter()
|
||||
.flat_map(|arm| {
|
||||
if let Arm {
|
||||
|
@ -730,7 +730,7 @@ fn type_ranges(ranges: &[SpannedRange<Constant>]) -> TypedRanges {
|
|||
.collect()
|
||||
}
|
||||
|
||||
fn is_unit_expr(expr: &Expr) -> bool {
|
||||
fn is_unit_expr(expr: &Expr<'_>) -> bool {
|
||||
match expr.kind {
|
||||
ExprKind::Tup(ref v) if v.is_empty() => true,
|
||||
ExprKind::Block(ref b, _) if b.stmts.is_empty() && b.expr.is_none() => true,
|
||||
|
@ -739,7 +739,7 @@ fn is_unit_expr(expr: &Expr) -> bool {
|
|||
}
|
||||
|
||||
// Checks if arm has the form `None => None`
|
||||
fn is_none_arm(arm: &Arm) -> bool {
|
||||
fn is_none_arm(arm: &Arm<'_>) -> bool {
|
||||
match arm.pat.kind {
|
||||
PatKind::Path(ref path) if match_qpath(path, &paths::OPTION_NONE) => true,
|
||||
_ => false,
|
||||
|
@ -747,7 +747,7 @@ fn is_none_arm(arm: &Arm) -> bool {
|
|||
}
|
||||
|
||||
// Checks if arm has the form `Some(ref v) => Some(v)` (checks for `ref` and `ref mut`)
|
||||
fn is_ref_some_arm(arm: &Arm) -> Option<BindingAnnotation> {
|
||||
fn is_ref_some_arm(arm: &Arm<'_>) -> Option<BindingAnnotation> {
|
||||
if_chain! {
|
||||
if let PatKind::TupleStruct(ref path, ref pats, _) = arm.pat.kind;
|
||||
if pats.len() == 1 && match_qpath(path, &paths::OPTION_SOME);
|
||||
|
@ -766,7 +766,7 @@ fn is_ref_some_arm(arm: &Arm) -> Option<BindingAnnotation> {
|
|||
None
|
||||
}
|
||||
|
||||
fn has_only_ref_pats(arms: &[Arm]) -> bool {
|
||||
fn has_only_ref_pats(arms: &[Arm<'_>]) -> bool {
|
||||
let mapped = arms
|
||||
.iter()
|
||||
.map(|a| {
|
||||
|
|
|
@ -31,7 +31,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(MemDiscriminant => [MEM_DISCRIMINANT_NON_ENUM]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemDiscriminant {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if_chain! {
|
||||
if let ExprKind::Call(ref func, ref func_args) = expr.kind;
|
||||
// is `mem::discriminant`
|
||||
|
|
|
@ -27,7 +27,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(MemForget => [MEM_FORGET]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemForget {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
|
||||
if let ExprKind::Call(ref path_expr, ref args) = e.kind {
|
||||
if let ExprKind::Path(ref qpath) = path_expr.kind {
|
||||
if let Some(def_id) = qpath_res(cx, qpath, path_expr.hir_id).opt_def_id() {
|
||||
|
|
|
@ -71,7 +71,7 @@ declare_lint_pass!(MemReplace =>
|
|||
[MEM_REPLACE_OPTION_WITH_NONE, MEM_REPLACE_WITH_UNINIT]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemReplace {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if_chain! {
|
||||
// Check that `expr` is a call to `mem::replace()`
|
||||
if let ExprKind::Call(ref func, ref func_args) = expr.kind;
|
||||
|
|
|
@ -7,7 +7,7 @@ use rustc::ty::{self, Ty};
|
|||
use rustc_errors::Applicability;
|
||||
|
||||
/// Checks for the `INEFFICIENT_TO_STRING` lint
|
||||
pub fn lint<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &hir::Expr, arg: &hir::Expr, arg_ty: Ty<'tcx>) {
|
||||
pub fn lint<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>, arg_ty: Ty<'tcx>) {
|
||||
if_chain! {
|
||||
if let Some(to_string_meth_did) = cx.tables.type_dependent_def_id(expr.hir_id);
|
||||
if match_def_path(cx, to_string_meth_did, &paths::TO_STRING_METHOD);
|
||||
|
|
|
@ -6,7 +6,7 @@ use rustc_errors::Applicability;
|
|||
use rustc_target::abi::LayoutOf;
|
||||
use syntax::ast;
|
||||
|
||||
pub fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &[&[hir::Expr]], arith: &str) {
|
||||
pub fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[&[hir::Expr<'_>]], arith: &str) {
|
||||
let unwrap_arg = &args[0][1];
|
||||
let arith_lhs = &args[1][0];
|
||||
let arith_rhs = &args[1][1];
|
||||
|
@ -82,7 +82,7 @@ enum MinMax {
|
|||
Max,
|
||||
}
|
||||
|
||||
fn is_min_or_max<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &hir::Expr) -> Option<MinMax> {
|
||||
fn is_min_or_max<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &hir::Expr<'_>) -> Option<MinMax> {
|
||||
// `T::max_value()` `T::min_value()` inherent methods
|
||||
if_chain! {
|
||||
if let hir::ExprKind::Call(func, args) = &expr.kind;
|
||||
|
@ -125,7 +125,7 @@ fn is_min_or_max<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &hir::Expr) -> Option<M
|
|||
(0, if bits == 128 { !0 } else { (1 << bits) - 1 })
|
||||
};
|
||||
|
||||
let check_lit = |expr: &hir::Expr, check_min: bool| {
|
||||
let check_lit = |expr: &hir::Expr<'_>, check_min: bool| {
|
||||
if let hir::ExprKind::Lit(lit) = &expr.kind {
|
||||
if let ast::LitKind::Int(value, _) = lit.node {
|
||||
if value == maxval {
|
||||
|
@ -160,7 +160,7 @@ enum Sign {
|
|||
Neg,
|
||||
}
|
||||
|
||||
fn lit_sign(expr: &hir::Expr) -> Option<Sign> {
|
||||
fn lit_sign(expr: &hir::Expr<'_>) -> Option<Sign> {
|
||||
if let hir::ExprKind::Unary(hir::UnNeg, inner) = &expr.kind {
|
||||
if let hir::ExprKind::Lit(..) = &inner.kind {
|
||||
return Some(Sign::Neg);
|
||||
|
|
|
@ -1152,7 +1152,7 @@ declare_lint_pass!(Methods => [
|
|||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) {
|
||||
if in_macro(expr.span) {
|
||||
return;
|
||||
}
|
||||
|
@ -1370,10 +1370,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
|
|||
#[allow(clippy::too_many_lines)]
|
||||
fn lint_or_fun_call<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
expr: &hir::Expr,
|
||||
expr: &hir::Expr<'_>,
|
||||
method_span: Span,
|
||||
name: &str,
|
||||
args: &'tcx [hir::Expr],
|
||||
args: &'tcx [hir::Expr<'_>],
|
||||
) {
|
||||
// Searches an expression for method calls or function calls that aren't ctors
|
||||
struct FunCallFinder<'a, 'tcx> {
|
||||
|
@ -1382,7 +1382,7 @@ fn lint_or_fun_call<'a, 'tcx>(
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> intravisit::Visitor<'tcx> for FunCallFinder<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) {
|
||||
let call_found = match &expr.kind {
|
||||
// ignore enum and struct constructors
|
||||
hir::ExprKind::Call(..) => !is_ctor_or_promotable_const_function(self.cx, expr),
|
||||
|
@ -1408,9 +1408,9 @@ fn lint_or_fun_call<'a, 'tcx>(
|
|||
fn check_unwrap_or_default(
|
||||
cx: &LateContext<'_, '_>,
|
||||
name: &str,
|
||||
fun: &hir::Expr,
|
||||
self_expr: &hir::Expr,
|
||||
arg: &hir::Expr,
|
||||
fun: &hir::Expr<'_>,
|
||||
self_expr: &hir::Expr<'_>,
|
||||
arg: &hir::Expr<'_>,
|
||||
or_has_args: bool,
|
||||
span: Span,
|
||||
) -> bool {
|
||||
|
@ -1453,8 +1453,8 @@ fn lint_or_fun_call<'a, 'tcx>(
|
|||
name: &str,
|
||||
method_span: Span,
|
||||
fun_span: Span,
|
||||
self_expr: &hir::Expr,
|
||||
arg: &'tcx hir::Expr,
|
||||
self_expr: &hir::Expr<'_>,
|
||||
arg: &'tcx hir::Expr<'_>,
|
||||
or_has_args: bool,
|
||||
span: Span,
|
||||
) {
|
||||
|
@ -1534,10 +1534,16 @@ fn lint_or_fun_call<'a, 'tcx>(
|
|||
|
||||
/// Checks for the `EXPECT_FUN_CALL` lint.
|
||||
#[allow(clippy::too_many_lines)]
|
||||
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<'_>],
|
||||
) {
|
||||
// Strip `&`, `as_ref()` and `as_str()` off `arg` until we're left with either a `String` or
|
||||
// `&str`
|
||||
fn get_arg_root<'a>(cx: &LateContext<'_, '_>, arg: &'a hir::Expr) -> &'a hir::Expr {
|
||||
fn get_arg_root<'a>(cx: &LateContext<'_, '_>, arg: &'a hir::Expr<'a>) -> &'a hir::Expr<'a> {
|
||||
let mut arg_root = arg;
|
||||
loop {
|
||||
arg_root = match &arg_root.kind {
|
||||
|
@ -1564,7 +1570,7 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
|
|||
|
||||
// Only `&'static str` or `String` can be used directly in the `panic!`. Other types should be
|
||||
// converted to string.
|
||||
fn requires_to_string(cx: &LateContext<'_, '_>, arg: &hir::Expr) -> bool {
|
||||
fn requires_to_string(cx: &LateContext<'_, '_>, arg: &hir::Expr<'_>) -> bool {
|
||||
let arg_ty = cx.tables.expr_ty(arg);
|
||||
if match_type(cx, arg_ty, &paths::STRING) {
|
||||
return false;
|
||||
|
@ -1579,7 +1585,7 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
|
|||
|
||||
fn generate_format_arg_snippet(
|
||||
cx: &LateContext<'_, '_>,
|
||||
a: &hir::Expr,
|
||||
a: &hir::Expr<'_>,
|
||||
applicability: &mut Applicability,
|
||||
) -> Vec<String> {
|
||||
if_chain! {
|
||||
|
@ -1598,7 +1604,7 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
|
|||
}
|
||||
}
|
||||
|
||||
fn is_call(node: &hir::ExprKind) -> bool {
|
||||
fn is_call(node: &hir::ExprKind<'_>) -> bool {
|
||||
match node {
|
||||
hir::ExprKind::AddrOf(hir::BorrowKind::Ref, _, expr) => {
|
||||
is_call(&expr.kind)
|
||||
|
@ -1681,7 +1687,7 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
|
|||
}
|
||||
|
||||
/// 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::Ref(_, inner, _) = arg_ty.kind {
|
||||
if let ty::Ref(_, innermost, _) = inner.kind {
|
||||
|
@ -1774,7 +1780,7 @@ fn lint_clone_on_copy(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::Exp
|
|||
}
|
||||
}
|
||||
|
||||
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::Adt(_, subst) = obj_ty.kind {
|
||||
|
@ -1805,7 +1811,7 @@ fn lint_clone_on_ref_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr, arg: &hir::
|
|||
}
|
||||
}
|
||||
|
||||
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];
|
||||
|
@ -1836,14 +1842,14 @@ fn lint_string_extend(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &[hir::E
|
|||
}
|
||||
}
|
||||
|
||||
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, source: &hir::Expr, unwrap: &hir::Expr) {
|
||||
fn lint_cstring_as_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, source: &hir::Expr<'_>, unwrap: &hir::Expr<'_>) {
|
||||
if_chain! {
|
||||
let source_type = cx.tables.expr_ty(source);
|
||||
if let ty::Adt(def, substs) = source_type.kind;
|
||||
|
@ -1863,7 +1869,11 @@ fn lint_cstring_as_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr, source: &hir:
|
|||
}
|
||||
}
|
||||
|
||||
fn lint_iter_cloned_collect<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &hir::Expr, iter_args: &'tcx [hir::Expr]) {
|
||||
fn lint_iter_cloned_collect<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
expr: &hir::Expr<'_>,
|
||||
iter_args: &'tcx [hir::Expr<'_>],
|
||||
) {
|
||||
if_chain! {
|
||||
if is_type_diagnostic_item(cx, cx.tables.expr_ty(expr), Symbol::intern("vec_type"));
|
||||
if let Some(slice) = derefs_to_slice(cx, &iter_args[0], cx.tables.expr_ty(&iter_args[0]));
|
||||
|
@ -1884,11 +1894,11 @@ fn lint_iter_cloned_collect<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &hir::Ex
|
|||
}
|
||||
}
|
||||
|
||||
fn lint_unnecessary_fold(cx: &LateContext<'_, '_>, expr: &hir::Expr, fold_args: &[hir::Expr], fold_span: Span) {
|
||||
fn lint_unnecessary_fold(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, fold_args: &[hir::Expr<'_>], fold_span: Span) {
|
||||
fn check_fold_with_op(
|
||||
cx: &LateContext<'_, '_>,
|
||||
expr: &hir::Expr,
|
||||
fold_args: &[hir::Expr],
|
||||
expr: &hir::Expr<'_>,
|
||||
fold_args: &[hir::Expr<'_>],
|
||||
fold_span: Span,
|
||||
op: hir::BinOpKind,
|
||||
replacement_method_name: &str,
|
||||
|
@ -1971,7 +1981,7 @@ fn lint_unnecessary_fold(cx: &LateContext<'_, '_>, expr: &hir::Expr, fold_args:
|
|||
}
|
||||
}
|
||||
|
||||
fn lint_step_by<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &hir::Expr, args: &'tcx [hir::Expr]) {
|
||||
fn lint_step_by<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &hir::Expr<'_>, args: &'tcx [hir::Expr<'_>]) {
|
||||
if match_trait_method(cx, expr, &paths::ITERATOR) {
|
||||
use crate::consts::{constant, Constant};
|
||||
if let Some((Constant::Int(0), _)) = constant(cx, cx.tables, &args[1]) {
|
||||
|
@ -1985,7 +1995,12 @@ fn lint_step_by<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &hir::Expr, args: &'
|
|||
}
|
||||
}
|
||||
|
||||
fn lint_iter_nth<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &hir::Expr, iter_args: &'tcx [hir::Expr], is_mut: bool) {
|
||||
fn lint_iter_nth<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
expr: &hir::Expr<'_>,
|
||||
iter_args: &'tcx [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"
|
||||
|
@ -2008,7 +2023,12 @@ fn lint_iter_nth<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &hir::Expr, iter_ar
|
|||
);
|
||||
}
|
||||
|
||||
fn lint_get_unwrap<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &hir::Expr, get_args: &'tcx [hir::Expr], is_mut: bool) {
|
||||
fn lint_get_unwrap<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
expr: &hir::Expr<'_>,
|
||||
get_args: &'tcx [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 mut applicability = Applicability::MachineApplicable;
|
||||
|
@ -2081,7 +2101,7 @@ fn lint_get_unwrap<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &hir::Expr, get_a
|
|||
);
|
||||
}
|
||||
|
||||
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(
|
||||
|
@ -2095,9 +2115,9 @@ fn lint_iter_skip_next(cx: &LateContext<'_, '_>, expr: &hir::Expr) {
|
|||
|
||||
fn derefs_to_slice<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
expr: &'tcx hir::Expr,
|
||||
expr: &'tcx hir::Expr<'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
) -> Option<&'tcx hir::Expr> {
|
||||
) -> Option<&'tcx hir::Expr<'tcx>> {
|
||||
fn may_slice<'a>(cx: &LateContext<'_, 'a>, ty: Ty<'a>) -> bool {
|
||||
match ty.kind {
|
||||
ty::Slice(_) => true,
|
||||
|
@ -2132,7 +2152,7 @@ fn derefs_to_slice<'a, 'tcx>(
|
|||
}
|
||||
|
||||
/// 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) {
|
||||
|
@ -2159,7 +2179,7 @@ fn lint_unwrap(cx: &LateContext<'_, '_>, expr: &hir::Expr, unwrap_args: &[hir::E
|
|||
}
|
||||
|
||||
/// lint use of `expect()` for `Option`s and `Result`s
|
||||
fn lint_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr, expect_args: &[hir::Expr]) {
|
||||
fn lint_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, expect_args: &[hir::Expr<'_>]) {
|
||||
let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&expect_args[0]));
|
||||
|
||||
let mess = if match_type(cx, obj_ty, &paths::OPTION) {
|
||||
|
@ -2184,7 +2204,7 @@ fn lint_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr, expect_args: &[hir::E
|
|||
}
|
||||
|
||||
/// 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<'_>]) {
|
||||
if_chain! {
|
||||
// lint if the caller of `ok()` is a `Result`
|
||||
if match_type(cx, cx.tables.expr_ty(&ok_args[0]), &paths::RESULT);
|
||||
|
@ -2204,7 +2224,7 @@ fn lint_ok_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr, ok_args: &[hir::Ex
|
|||
}
|
||||
|
||||
/// lint use of `map().flatten()` for `Iterators`
|
||||
fn lint_map_flatten<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr, map_args: &'tcx [hir::Expr]) {
|
||||
fn lint_map_flatten<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>, map_args: &'tcx [hir::Expr<'_>]) {
|
||||
// lint if caller of `.map().flatten()` is an Iterator
|
||||
if match_trait_method(cx, expr, &paths::ITERATOR) {
|
||||
let msg = "called `map(..).flatten()` on an `Iterator`. \
|
||||
|
@ -2226,9 +2246,9 @@ fn lint_map_flatten<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr,
|
|||
/// lint use of `map().unwrap_or_else()` for `Option`s and `Result`s
|
||||
fn lint_map_unwrap_or_else<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
expr: &'tcx hir::Expr,
|
||||
map_args: &'tcx [hir::Expr],
|
||||
unwrap_args: &'tcx [hir::Expr],
|
||||
expr: &'tcx hir::Expr<'_>,
|
||||
map_args: &'tcx [hir::Expr<'_>],
|
||||
unwrap_args: &'tcx [hir::Expr<'_>],
|
||||
) {
|
||||
// lint if the caller of `map()` is an `Option`
|
||||
let is_option = match_type(cx, cx.tables.expr_ty(&map_args[0]), &paths::OPTION);
|
||||
|
@ -2294,7 +2314,11 @@ fn lint_map_unwrap_or_else<'a, 'tcx>(
|
|||
}
|
||||
|
||||
/// lint use of `_.map_or(None, _)` for `Option`s
|
||||
fn lint_map_or_none<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr, map_or_args: &'tcx [hir::Expr]) {
|
||||
fn lint_map_or_none<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
expr: &'tcx hir::Expr<'_>,
|
||||
map_or_args: &'tcx [hir::Expr<'_>],
|
||||
) {
|
||||
if match_type(cx, cx.tables.expr_ty(&map_or_args[0]), &paths::OPTION) {
|
||||
// check if the first non-self argument to map_or() is None
|
||||
let map_or_arg_is_none = if let hir::ExprKind::Path(ref qpath) = map_or_args[1].kind {
|
||||
|
@ -2323,7 +2347,7 @@ fn lint_map_or_none<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr,
|
|||
}
|
||||
|
||||
/// Lint use of `_.and_then(|x| Some(y))` for `Option`s
|
||||
fn lint_option_and_then_some(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &[hir::Expr]) {
|
||||
fn lint_option_and_then_some(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) {
|
||||
const LINT_MSG: &str = "using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)`";
|
||||
const NO_OP_MSG: &str = "using `Option.and_then(Some)`, which is a no-op";
|
||||
|
||||
|
@ -2390,7 +2414,11 @@ fn lint_option_and_then_some(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &
|
|||
}
|
||||
|
||||
/// lint use of `filter().next()` for `Iterators`
|
||||
fn lint_filter_next<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr, filter_args: &'tcx [hir::Expr]) {
|
||||
fn lint_filter_next<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
expr: &'tcx hir::Expr<'_>,
|
||||
filter_args: &'tcx [hir::Expr<'_>],
|
||||
) {
|
||||
// lint if caller of `.filter().next()` is an Iterator
|
||||
if match_trait_method(cx, expr, &paths::ITERATOR) {
|
||||
let msg = "called `filter(p).next()` on an `Iterator`. This is more succinctly expressed by calling \
|
||||
|
@ -2415,9 +2443,9 @@ fn lint_filter_next<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr,
|
|||
/// lint use of `filter().map()` for `Iterators`
|
||||
fn lint_filter_map<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
expr: &'tcx hir::Expr,
|
||||
_filter_args: &'tcx [hir::Expr],
|
||||
_map_args: &'tcx [hir::Expr],
|
||||
expr: &'tcx hir::Expr<'_>,
|
||||
_filter_args: &'tcx [hir::Expr<'_>],
|
||||
_map_args: &'tcx [hir::Expr<'_>],
|
||||
) {
|
||||
// lint if caller of `.filter().map()` is an Iterator
|
||||
if match_trait_method(cx, expr, &paths::ITERATOR) {
|
||||
|
@ -2428,7 +2456,11 @@ fn lint_filter_map<'a, 'tcx>(
|
|||
}
|
||||
|
||||
/// lint use of `filter_map().next()` for `Iterators`
|
||||
fn lint_filter_map_next<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr, filter_args: &'tcx [hir::Expr]) {
|
||||
fn lint_filter_map_next<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
expr: &'tcx hir::Expr<'_>,
|
||||
filter_args: &'tcx [hir::Expr<'_>],
|
||||
) {
|
||||
if match_trait_method(cx, expr, &paths::ITERATOR) {
|
||||
let msg = "called `filter_map(p).next()` on an `Iterator`. This is more succinctly expressed by calling \
|
||||
`.find_map(p)` instead.";
|
||||
|
@ -2451,9 +2483,9 @@ fn lint_filter_map_next<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::E
|
|||
/// lint use of `find().map()` for `Iterators`
|
||||
fn lint_find_map<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
expr: &'tcx hir::Expr,
|
||||
_find_args: &'tcx [hir::Expr],
|
||||
map_args: &'tcx [hir::Expr],
|
||||
expr: &'tcx hir::Expr<'_>,
|
||||
_find_args: &'tcx [hir::Expr<'_>],
|
||||
map_args: &'tcx [hir::Expr<'_>],
|
||||
) {
|
||||
// lint if caller of `.filter().map()` is an Iterator
|
||||
if match_trait_method(cx, &map_args[0], &paths::ITERATOR) {
|
||||
|
@ -2466,9 +2498,9 @@ fn lint_find_map<'a, 'tcx>(
|
|||
/// lint use of `filter_map().map()` for `Iterators`
|
||||
fn lint_filter_map_map<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
expr: &'tcx hir::Expr,
|
||||
_filter_args: &'tcx [hir::Expr],
|
||||
_map_args: &'tcx [hir::Expr],
|
||||
expr: &'tcx hir::Expr<'_>,
|
||||
_filter_args: &'tcx [hir::Expr<'_>],
|
||||
_map_args: &'tcx [hir::Expr<'_>],
|
||||
) {
|
||||
// lint if caller of `.filter().map()` is an Iterator
|
||||
if match_trait_method(cx, expr, &paths::ITERATOR) {
|
||||
|
@ -2481,9 +2513,9 @@ fn lint_filter_map_map<'a, 'tcx>(
|
|||
/// lint use of `filter().flat_map()` for `Iterators`
|
||||
fn lint_filter_flat_map<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
expr: &'tcx hir::Expr,
|
||||
_filter_args: &'tcx [hir::Expr],
|
||||
_map_args: &'tcx [hir::Expr],
|
||||
expr: &'tcx hir::Expr<'_>,
|
||||
_filter_args: &'tcx [hir::Expr<'_>],
|
||||
_map_args: &'tcx [hir::Expr<'_>],
|
||||
) {
|
||||
// lint if caller of `.filter().flat_map()` is an Iterator
|
||||
if match_trait_method(cx, expr, &paths::ITERATOR) {
|
||||
|
@ -2497,9 +2529,9 @@ fn lint_filter_flat_map<'a, 'tcx>(
|
|||
/// lint use of `filter_map().flat_map()` for `Iterators`
|
||||
fn lint_filter_map_flat_map<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
expr: &'tcx hir::Expr,
|
||||
_filter_args: &'tcx [hir::Expr],
|
||||
_map_args: &'tcx [hir::Expr],
|
||||
expr: &'tcx hir::Expr<'_>,
|
||||
_filter_args: &'tcx [hir::Expr<'_>],
|
||||
_map_args: &'tcx [hir::Expr<'_>],
|
||||
) {
|
||||
// lint if caller of `.filter_map().flat_map()` is an Iterator
|
||||
if match_trait_method(cx, expr, &paths::ITERATOR) {
|
||||
|
@ -2513,8 +2545,8 @@ fn lint_filter_map_flat_map<'a, 'tcx>(
|
|||
/// lint use of `flat_map` for `Iterators` where `flatten` would be sufficient
|
||||
fn lint_flat_map_identity<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
expr: &'tcx hir::Expr,
|
||||
flat_map_args: &'tcx [hir::Expr],
|
||||
expr: &'tcx hir::Expr<'_>,
|
||||
flat_map_args: &'tcx [hir::Expr<'_>],
|
||||
flat_map_span: Span,
|
||||
) {
|
||||
if match_trait_method(cx, expr, &paths::ITERATOR) {
|
||||
|
@ -2562,10 +2594,10 @@ fn lint_flat_map_identity<'a, 'tcx>(
|
|||
/// lint searching an Iterator followed by `is_some()`
|
||||
fn lint_search_is_some<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
expr: &'tcx hir::Expr,
|
||||
expr: &'tcx hir::Expr<'_>,
|
||||
search_method: &str,
|
||||
search_args: &'tcx [hir::Expr],
|
||||
is_some_args: &'tcx [hir::Expr],
|
||||
search_args: &'tcx [hir::Expr<'_>],
|
||||
is_some_args: &'tcx [hir::Expr<'_>],
|
||||
method_span: Span,
|
||||
) {
|
||||
// lint if caller of search is an Iterator
|
||||
|
@ -2618,9 +2650,9 @@ fn lint_search_is_some<'a, 'tcx>(
|
|||
/// Used for `lint_binary_expr_with_method_call`.
|
||||
#[derive(Copy, Clone)]
|
||||
struct BinaryExprInfo<'a> {
|
||||
expr: &'a hir::Expr,
|
||||
chain: &'a hir::Expr,
|
||||
other: &'a hir::Expr,
|
||||
expr: &'a hir::Expr<'a>,
|
||||
chain: &'a hir::Expr<'a>,
|
||||
other: &'a hir::Expr<'a>,
|
||||
eq: bool,
|
||||
}
|
||||
|
||||
|
@ -2751,7 +2783,11 @@ fn lint_chars_last_cmp_with_unwrap<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, info: &
|
|||
}
|
||||
|
||||
/// lint for length-1 `str`s for methods in `PATTERN_METHODS`
|
||||
fn lint_single_char_pattern<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, _expr: &'tcx hir::Expr, arg: &'tcx hir::Expr) {
|
||||
fn lint_single_char_pattern<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
_expr: &'tcx hir::Expr<'_>,
|
||||
arg: &'tcx hir::Expr<'_>,
|
||||
) {
|
||||
if_chain! {
|
||||
if let hir::ExprKind::Lit(lit) = &arg.kind;
|
||||
if let ast::LitKind::Str(r, style) = lit.node;
|
||||
|
@ -2782,7 +2818,7 @@ fn lint_single_char_pattern<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, _expr: &'tcx h
|
|||
}
|
||||
|
||||
/// 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) {
|
||||
|
@ -2831,7 +2867,7 @@ fn ty_has_iter_method(cx: &LateContext<'_, '_>, self_ref_ty: Ty<'_>) -> Option<(
|
|||
})
|
||||
}
|
||||
|
||||
fn lint_into_iter(cx: &LateContext<'_, '_>, expr: &hir::Expr, self_ref_ty: Ty<'_>, method_span: Span) {
|
||||
fn lint_into_iter(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, self_ref_ty: Ty<'_>, method_span: Span) {
|
||||
if !match_trait_method(cx, expr, &paths::INTO_ITERATOR) {
|
||||
return;
|
||||
}
|
||||
|
@ -2852,7 +2888,7 @@ fn lint_into_iter(cx: &LateContext<'_, '_>, expr: &hir::Expr, self_ref_ty: Ty<'_
|
|||
}
|
||||
|
||||
/// lint for `MaybeUninit::uninit().assume_init()` (we already have the latter)
|
||||
fn lint_maybe_uninit(cx: &LateContext<'_, '_>, expr: &hir::Expr, outer: &hir::Expr) {
|
||||
fn lint_maybe_uninit(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, outer: &hir::Expr<'_>) {
|
||||
if_chain! {
|
||||
if let hir::ExprKind::Call(ref callee, ref args) = expr.kind;
|
||||
if args.is_empty();
|
||||
|
@ -2882,7 +2918,7 @@ fn is_maybe_uninit_ty_valid(cx: &LateContext<'_, '_>, ty: Ty<'_>) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn lint_suspicious_map(cx: &LateContext<'_, '_>, expr: &hir::Expr) {
|
||||
fn lint_suspicious_map(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>) {
|
||||
span_help_and_lint(
|
||||
cx,
|
||||
SUSPICIOUS_MAP,
|
||||
|
@ -3095,13 +3131,13 @@ fn is_bool(ty: &hir::Ty) -> bool {
|
|||
}
|
||||
|
||||
// Returns `true` if `expr` contains a return expression
|
||||
fn contains_return(expr: &hir::Expr) -> bool {
|
||||
fn contains_return(expr: &hir::Expr<'_>) -> bool {
|
||||
struct RetCallFinder {
|
||||
found: bool,
|
||||
}
|
||||
|
||||
impl<'tcx> intravisit::Visitor<'tcx> for RetCallFinder {
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) {
|
||||
if self.found {
|
||||
return;
|
||||
}
|
||||
|
@ -3122,7 +3158,7 @@ fn contains_return(expr: &hir::Expr) -> bool {
|
|||
visitor.found
|
||||
}
|
||||
|
||||
fn check_pointer_offset(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &[hir::Expr]) {
|
||||
fn check_pointer_offset(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) {
|
||||
if_chain! {
|
||||
if args.len() == 2;
|
||||
if let ty::RawPtr(ty::TypeAndMut { ref ty, .. }) = cx.tables.expr_ty(&args[0]).kind;
|
||||
|
|
|
@ -11,9 +11,9 @@ use super::OPTION_MAP_UNWRAP_OR;
|
|||
/// lint use of `map().unwrap_or()` for `Option`s
|
||||
pub(super) fn lint<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
expr: &hir::Expr,
|
||||
map_args: &'tcx [hir::Expr],
|
||||
unwrap_args: &'tcx [hir::Expr],
|
||||
expr: &hir::Expr<'_>,
|
||||
map_args: &'tcx [hir::Expr<'_>],
|
||||
unwrap_args: &'tcx [hir::Expr<'_>],
|
||||
) {
|
||||
// lint if the caller of `map()` is an `Option`
|
||||
if match_type(cx, cx.tables.expr_ty(&map_args[0]), &paths::OPTION) {
|
||||
|
|
|
@ -10,7 +10,7 @@ use if_chain::if_chain;
|
|||
|
||||
use super::UNNECESSARY_FILTER_MAP;
|
||||
|
||||
pub(super) fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &[hir::Expr]) {
|
||||
pub(super) fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) {
|
||||
if !match_trait_method(cx, expr, &paths::ITERATOR) {
|
||||
return;
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ pub(super) fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &[hir::Expr
|
|||
fn check_expression<'a, 'tcx>(
|
||||
cx: &'a LateContext<'a, 'tcx>,
|
||||
arg_id: hir::HirId,
|
||||
expr: &'tcx hir::Expr,
|
||||
expr: &'tcx hir::Expr<'_>,
|
||||
) -> (bool, bool) {
|
||||
match &expr.kind {
|
||||
hir::ExprKind::Call(ref func, ref args) => {
|
||||
|
@ -87,10 +87,10 @@ fn check_expression<'a, 'tcx>(
|
|||
(false, false)
|
||||
}
|
||||
},
|
||||
hir::ExprKind::Match(_, ref arms, _) => {
|
||||
hir::ExprKind::Match(_, arms, _) => {
|
||||
let mut found_mapping = false;
|
||||
let mut found_filtering = false;
|
||||
for arm in arms {
|
||||
for arm in *arms {
|
||||
let (m, f) = check_expression(cx, arg_id, &arm.body);
|
||||
found_mapping |= m;
|
||||
found_filtering |= f;
|
||||
|
@ -123,7 +123,7 @@ impl<'a, 'tcx> ReturnVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for ReturnVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) {
|
||||
if let hir::ExprKind::Ret(Some(expr)) = &expr.kind {
|
||||
let (found_mapping, found_filtering) = check_expression(self.cx, self.arg_id, expr);
|
||||
self.found_mapping |= found_mapping;
|
||||
|
|
|
@ -29,7 +29,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(MinMaxPass => [MIN_MAX]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MinMaxPass {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if let Some((outer_max, outer_c, oe)) = min_max(cx, expr) {
|
||||
if let Some((inner_max, inner_c, ie)) = min_max(cx, oe) {
|
||||
if outer_max == inner_max {
|
||||
|
@ -60,7 +60,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<'a>) -> Option<(MinMax, Constant, &'a Expr<'a>)> {
|
||||
if let ExprKind::Call(ref path, ref args) = expr.kind {
|
||||
if let ExprKind::Path(ref qpath) = path.kind {
|
||||
cx.tables.qpath_res(qpath, path.hir_id).opt_def_id().and_then(|def_id| {
|
||||
|
@ -80,7 +80,11 @@ fn min_max<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr) -> Option<(MinMax, Cons
|
|||
}
|
||||
}
|
||||
|
||||
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<'a>],
|
||||
m: MinMax,
|
||||
) -> Option<(MinMax, Constant, &'a Expr<'a>)> {
|
||||
if args.len() != 2 {
|
||||
return None;
|
||||
}
|
||||
|
|
|
@ -262,7 +262,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) {
|
||||
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt<'_>) {
|
||||
if_chain! {
|
||||
if let StmtKind::Local(ref local) = stmt.kind;
|
||||
if let PatKind::Binding(an, .., name, None) = local.pat.kind;
|
||||
|
@ -334,7 +334,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
|
|||
};
|
||||
}
|
||||
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
match expr.kind {
|
||||
ExprKind::Cast(ref e, ref ty) => {
|
||||
check_cast(cx, expr.span, e, ty);
|
||||
|
@ -440,7 +440,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_nan(cx: &LateContext<'_, '_>, expr: &Expr, cmp_expr: &Expr) {
|
||||
fn check_nan(cx: &LateContext<'_, '_>, expr: &Expr<'_>, cmp_expr: &Expr<'_>) {
|
||||
if_chain! {
|
||||
if !in_constant(cx, cmp_expr.hir_id);
|
||||
if let Some((value, _)) = constant(cx, cx.tables, expr);
|
||||
|
@ -463,7 +463,7 @@ fn check_nan(cx: &LateContext<'_, '_>, expr: &Expr, cmp_expr: &Expr) {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_named_constant<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> bool {
|
||||
fn is_named_constant<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> bool {
|
||||
if let Some((_, res)) = constant(cx, cx.tables, expr) {
|
||||
res
|
||||
} else {
|
||||
|
@ -471,7 +471,7 @@ fn is_named_constant<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) ->
|
|||
}
|
||||
}
|
||||
|
||||
fn is_allowed<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> bool {
|
||||
fn is_allowed<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> bool {
|
||||
match constant(cx, cx.tables, expr) {
|
||||
Some((Constant::F32(f), _)) => f == 0.0 || f.is_infinite(),
|
||||
Some((Constant::F64(f), _)) => f == 0.0 || f.is_infinite(),
|
||||
|
@ -480,7 +480,7 @@ fn is_allowed<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> bool {
|
|||
}
|
||||
|
||||
// Return true if `expr` is the result of `signum()` invoked on a float value.
|
||||
fn is_signum(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
|
||||
fn is_signum(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool {
|
||||
// The negation of a signum is still a signum
|
||||
if let ExprKind::Unary(UnNeg, ref child_expr) = expr.kind {
|
||||
return is_signum(cx, &child_expr);
|
||||
|
@ -498,11 +498,11 @@ fn is_signum(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
|
|||
false
|
||||
}
|
||||
|
||||
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)).kind, ty::Float(_))
|
||||
}
|
||||
|
||||
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.kind {
|
||||
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) {
|
||||
|
@ -587,7 +587,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.kind {
|
||||
ExprKind::Assign(_, ref rhs, _) | ExprKind::AssignOp(_, _, ref rhs) => {
|
||||
|
@ -602,7 +602,7 @@ fn is_used(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
|
|||
|
||||
/// Tests whether an expression is in a macro expansion (e.g., something
|
||||
/// generated by `#[derive(...)]` or the like).
|
||||
fn in_attributes_expansion(expr: &Expr) -> bool {
|
||||
fn in_attributes_expansion(expr: &Expr<'_>) -> bool {
|
||||
use syntax_pos::hygiene::MacroKind;
|
||||
if expr.span.from_expansion() {
|
||||
let data = expr.span.ctxt().outer_expn_data();
|
||||
|
@ -626,7 +626,7 @@ fn non_macro_local(cx: &LateContext<'_, '_>, res: def::Res) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
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(ref mut_ty) = ty.kind;
|
||||
if let ExprKind::Lit(ref lit) = e.kind;
|
||||
|
|
|
@ -44,12 +44,15 @@ declare_clippy_lint! {
|
|||
|
||||
declare_lint_pass!(MulAddCheck => [MANUAL_MUL_ADD]);
|
||||
|
||||
fn is_float<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr) -> bool {
|
||||
fn is_float<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr<'_>) -> bool {
|
||||
cx.tables.expr_ty(expr).is_floating_point()
|
||||
}
|
||||
|
||||
// Checks whether expression is multiplication of two floats
|
||||
fn is_float_mult_expr<'a, 'tcx, 'b>(cx: &LateContext<'a, 'tcx>, expr: &'b Expr) -> Option<(&'b Expr, &'b Expr)> {
|
||||
fn is_float_mult_expr<'a, 'tcx, 'b>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
expr: &'b Expr<'b>,
|
||||
) -> Option<(&'b Expr<'b>, &'b Expr<'b>)> {
|
||||
if let ExprKind::Binary(op, lhs, rhs) = &expr.kind {
|
||||
if let BinOpKind::Mul = op.node {
|
||||
if is_float(cx, &lhs) && is_float(cx, &rhs) {
|
||||
|
@ -62,7 +65,7 @@ fn is_float_mult_expr<'a, 'tcx, 'b>(cx: &LateContext<'a, 'tcx>, expr: &'b Expr)
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MulAddCheck {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if let ExprKind::Binary(op, lhs, rhs) = &expr.kind {
|
||||
if let BinOpKind::Add = op.node {
|
||||
//Converts mult_lhs * mult_rhs + rhs to mult_lhs.mult_add(mult_rhs, rhs)
|
||||
|
|
|
@ -73,7 +73,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableKeyType {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_local(&mut self, cx: &LateContext<'_, '_>, local: &hir::Local) {
|
||||
fn check_local(&mut self, cx: &LateContext<'_, '_>, local: &hir::Local<'_>) {
|
||||
if let hir::PatKind::Wild = local.pat.kind {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(MutMut => [MUT_MUT]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutMut {
|
||||
fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx hir::Block) {
|
||||
fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx hir::Block<'_>) {
|
||||
intravisit::walk_block(&mut MutVisitor { cx }, block);
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ pub struct MutVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) {
|
||||
if in_external_macro(self.cx.sess(), expr.span) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(UnnecessaryMutPassed => [UNNECESSARY_MUT_PASSED]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnecessaryMutPassed {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
|
||||
match e.kind {
|
||||
ExprKind::Call(ref fn_expr, ref arguments) => {
|
||||
if let ExprKind::Path(ref path) = fn_expr.kind {
|
||||
|
@ -50,7 +50,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnecessaryMutPassed {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_arguments<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arguments: &[Expr], type_definition: Ty<'tcx>, name: &str) {
|
||||
fn check_arguments<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
arguments: &[Expr<'_>],
|
||||
type_definition: Ty<'tcx>,
|
||||
name: &str,
|
||||
) {
|
||||
match type_definition.kind {
|
||||
ty::FnDef(..) | ty::FnPtr(_) => {
|
||||
let parameters = type_definition.fn_sig(cx.tcx).skip_binder().inputs();
|
||||
|
|
|
@ -36,7 +36,7 @@ declare_lint_pass!(DebugAssertWithMutCall => [DEBUG_ASSERT_WITH_MUT_CALL]);
|
|||
const DEBUG_MACRO_NAMES: [&str; 3] = ["debug_assert", "debug_assert_eq", "debug_assert_ne"];
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DebugAssertWithMutCall {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
|
||||
for dmn in &DEBUG_MACRO_NAMES {
|
||||
if is_direct_expn_of(e.span, dmn).is_some() {
|
||||
if let Some(span) = extract_call(cx, e) {
|
||||
|
@ -54,7 +54,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DebugAssertWithMutCall {
|
|||
|
||||
//HACK(hellow554): remove this when #4694 is implemented
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
fn extract_call<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, e: &'tcx Expr) -> Option<Span> {
|
||||
fn extract_call<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) -> Option<Span> {
|
||||
if_chain! {
|
||||
if let ExprKind::Block(ref block, _) = e.kind;
|
||||
if block.stmts.len() == 1;
|
||||
|
@ -127,7 +127,7 @@ impl<'a, 'tcx> MutArgVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for MutArgVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr) {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
|
||||
match expr.kind {
|
||||
ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, _) => {
|
||||
self.found = true;
|
||||
|
|
|
@ -56,7 +56,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(Mutex => [MUTEX_ATOMIC, MUTEX_INTEGER]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Mutex {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
let ty = cx.tables.expr_ty(expr);
|
||||
if let ty::Adt(_, subst) = ty.kind {
|
||||
if match_type(cx, ty, &paths::MUTEX) {
|
||||
|
|
|
@ -62,7 +62,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(NeedlessBool => [NEEDLESS_BOOL]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBool {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
|
||||
use self::Expression::*;
|
||||
if let Some((ref pred, ref then_block, Some(ref else_expr))) = higher::if_block(&e) {
|
||||
let reduce = |ret, not| {
|
||||
|
@ -122,7 +122,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBool {
|
|||
declare_lint_pass!(BoolComparison => [BOOL_COMPARISON]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
|
||||
if e.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison {
|
|||
|
||||
fn check_comparison<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
e: &'tcx Expr,
|
||||
e: &'tcx Expr<'_>,
|
||||
left_true: Option<(impl FnOnce(Sugg<'a>) -> Sugg<'a>, &str)>,
|
||||
left_false: Option<(impl FnOnce(Sugg<'a>) -> Sugg<'a>, &str)>,
|
||||
right_true: Option<(impl FnOnce(Sugg<'a>) -> Sugg<'a>, &str)>,
|
||||
|
@ -232,8 +232,8 @@ fn check_comparison<'a, 'tcx>(
|
|||
|
||||
fn suggest_bool_comparison<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
e: &'tcx Expr,
|
||||
expr: &Expr,
|
||||
e: &'tcx Expr<'_>,
|
||||
expr: &Expr<'_>,
|
||||
mut applicability: Applicability,
|
||||
message: &str,
|
||||
conv_hint: impl FnOnce(Sugg<'a>) -> Sugg<'a>,
|
||||
|
@ -256,7 +256,7 @@ enum Expression {
|
|||
Other,
|
||||
}
|
||||
|
||||
fn fetch_bool_block(block: &Block) -> Expression {
|
||||
fn fetch_bool_block(block: &Block<'_>) -> Expression {
|
||||
match (&*block.stmts, block.expr.as_ref()) {
|
||||
(&[], Some(e)) => fetch_bool_expr(&**e),
|
||||
(&[ref e], None) => {
|
||||
|
@ -274,7 +274,7 @@ fn fetch_bool_block(block: &Block) -> Expression {
|
|||
}
|
||||
}
|
||||
|
||||
fn fetch_bool_expr(expr: &Expr) -> Expression {
|
||||
fn fetch_bool_expr(expr: &Expr<'_>) -> Expression {
|
||||
match expr.kind {
|
||||
ExprKind::Block(ref block, _) => fetch_bool_block(block),
|
||||
ExprKind::Lit(ref lit_ptr) => {
|
||||
|
|
|
@ -38,7 +38,7 @@ pub struct NeedlessBorrow {
|
|||
impl_lint_pass!(NeedlessBorrow => [NEEDLESS_BORROW]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
|
||||
if e.span.from_expansion() || self.derived_item.is_some() {
|
||||
return;
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrow {
|
|||
}
|
||||
}
|
||||
}
|
||||
fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {
|
||||
fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat<'_>) {
|
||||
if pat.span.from_expansion() || self.derived_item.is_some() {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(NeedlessBorrowedRef => [NEEDLESS_BORROWED_REFERENCE]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBorrowedRef {
|
||||
fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {
|
||||
fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat<'_>) {
|
||||
if pat.span.from_expansion() {
|
||||
// OK, simple enough, lints doesn't check in macro.
|
||||
return;
|
||||
|
|
|
@ -36,7 +36,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(NeedlessUpdate => [NEEDLESS_UPDATE]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessUpdate {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if let ExprKind::Struct(_, ref fields, Some(ref base)) = expr.kind {
|
||||
let ty = cx.tables.expr_ty(expr);
|
||||
if let ty::Adt(def, _) = ty.kind {
|
||||
|
|
|
@ -46,7 +46,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(NoNegCompOpForPartialOrd => [NEG_CMP_OP_ON_PARTIAL_ORD]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NoNegCompOpForPartialOrd {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if_chain! {
|
||||
|
||||
if !in_external_macro(cx.sess(), expr.span);
|
||||
|
|
|
@ -28,7 +28,7 @@ declare_lint_pass!(NegMultiply => [NEG_MULTIPLY]);
|
|||
|
||||
#[allow(clippy::match_same_arms)]
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NegMultiply {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
|
||||
if let ExprKind::Binary(ref op, ref left, ref right) = e.kind {
|
||||
if BinOpKind::Mul == op.node {
|
||||
match (&left.kind, &right.kind) {
|
||||
|
@ -42,7 +42,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.kind;
|
||||
if let Constant::Int(1) = consts::lit_to_constant(&l.node, cx.tables.expr_ty_opt(lit));
|
||||
|
|
|
@ -43,7 +43,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 expr.span.from_expansion() {
|
||||
return false;
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ fn has_no_effect(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
|
|||
declare_lint_pass!(NoEffect => [NO_EFFECT, UNNECESSARY_OPERATION]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NoEffect {
|
||||
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) {
|
||||
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt<'_>) {
|
||||
if let StmtKind::Semi(ref expr) = stmt.kind {
|
||||
if has_no_effect(cx, expr) {
|
||||
span_lint(cx, NO_EFFECT, stmt.span, "statement with no effect");
|
||||
|
@ -120,7 +120,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NoEffect {
|
|||
}
|
||||
}
|
||||
|
||||
fn reduce_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr) -> Option<Vec<&'a Expr>> {
|
||||
fn reduce_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'a>) -> Option<Vec<&'a Expr<'a>>> {
|
||||
if expr.span.from_expansion() {
|
||||
return None;
|
||||
}
|
||||
|
|
|
@ -183,7 +183,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCopyConst {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if let ExprKind::Path(qpath) = &expr.kind {
|
||||
// Only lint if we use the const item inside a function.
|
||||
if in_constant(cx, expr.hir_id) {
|
||||
|
|
|
@ -38,7 +38,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(OkIfLet => [IF_LET_SOME_RESULT]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OkIfLet {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if_chain! { //begin checking variables
|
||||
if let ExprKind::Match(ref op, ref body, ref source) = expr.kind; //test if expr is a match
|
||||
if let MatchSource::IfLetDesugar { .. } = *source; //test if it is an If Let
|
||||
|
|
|
@ -29,7 +29,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(OpenOptions => [NONSENSICAL_OPEN_OPTIONS]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OpenOptions {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
|
||||
if let ExprKind::MethodCall(ref path, _, ref arguments) = e.kind {
|
||||
let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&arguments[0]));
|
||||
if path.ident.name == sym!(open) && match_type(cx, obj_ty, &paths::OPEN_OPTIONS) {
|
||||
|
@ -57,7 +57,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.kind {
|
||||
let obj_ty = walk_ptrs_ty(cx.tables.expr_ty(&arguments[0]));
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ declare_lint_pass!(OverflowCheckConditional => [OVERFLOW_CHECK_CONDITIONAL]);
|
|||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OverflowCheckConditional {
|
||||
// a + b < a, a > a + b, a < a - b, a - b > a
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
let eq = |l, r| SpanlessEq::new(cx).eq_path_segment(l, r);
|
||||
if_chain! {
|
||||
if let ExprKind::Binary(ref op, ref first, ref second) = expr.kind;
|
||||
|
|
|
@ -93,7 +93,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(PanicUnimplemented => [PANIC_PARAMS, UNIMPLEMENTED, UNREACHABLE, TODO, PANIC]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PanicUnimplemented {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if_chain! {
|
||||
if let ExprKind::Block(ref block, _) = expr.kind;
|
||||
if let Some(ref ex) = block.expr;
|
||||
|
@ -123,7 +123,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PanicUnimplemented {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_outer_span(expr: &Expr) -> Span {
|
||||
fn get_outer_span(expr: &Expr<'_>) -> Span {
|
||||
if_chain! {
|
||||
if expr.span.from_expansion();
|
||||
let first = expr.span.ctxt().outer_expn_data();
|
||||
|
@ -137,7 +137,7 @@ fn get_outer_span(expr: &Expr) -> Span {
|
|||
}
|
||||
}
|
||||
|
||||
fn match_panic(params: &[Expr], expr: &Expr, cx: &LateContext<'_, '_>) {
|
||||
fn match_panic(params: &[Expr<'_>], expr: &Expr<'_>, cx: &LateContext<'_, '_>) {
|
||||
if_chain! {
|
||||
if let ExprKind::Lit(ref lit) = params[0].kind;
|
||||
if is_direct_expn_of(expr.span, "panic").is_some();
|
||||
|
|
|
@ -42,7 +42,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(PathBufPushOverwrite => [PATH_BUF_PUSH_OVERWRITE]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PathBufPushOverwrite {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if_chain! {
|
||||
if let ExprKind::MethodCall(ref path, _, ref args) = expr.kind;
|
||||
if path.ident.name == sym!(push);
|
||||
|
|
|
@ -130,7 +130,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ptr {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if let ExprKind::Binary(ref op, ref l, ref r) = expr.kind {
|
||||
if (op.node == BinOpKind::Eq || op.node == BinOpKind::Ne) && (is_null_path(l) || is_null_path(r)) {
|
||||
span_lint(
|
||||
|
@ -293,7 +293,7 @@ fn get_rptr_lm(ty: &Ty) -> Option<(&Lifetime, Mutability, Span)> {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_null_path(expr: &Expr) -> bool {
|
||||
fn is_null_path(expr: &Expr<'_>) -> bool {
|
||||
if let ExprKind::Call(ref pathexp, ref args) = expr.kind {
|
||||
if args.is_empty() {
|
||||
if let ExprKind::Path(ref path) = pathexp.kind {
|
||||
|
|
|
@ -45,7 +45,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(PtrOffsetWithCast => [PTR_OFFSET_WITH_CAST]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PtrOffsetWithCast {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
// Check if the expressions is a ptr.offset or ptr.wrapping_offset method call
|
||||
let (receiver_expr, arg_expr, method) = match expr_as_ptr_offset_call(cx, expr) {
|
||||
Some(call_arg) => call_arg,
|
||||
|
@ -76,7 +76,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PtrOffsetWithCast {
|
|||
}
|
||||
|
||||
// If the given expression is a cast from a usize, return the lhs of the cast
|
||||
fn expr_as_cast_from_usize<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Option<&'tcx Expr> {
|
||||
fn expr_as_cast_from_usize<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> {
|
||||
if let ExprKind::Cast(ref cast_lhs_expr, _) = expr.kind {
|
||||
if is_expr_ty_usize(cx, &cast_lhs_expr) {
|
||||
return Some(cast_lhs_expr);
|
||||
|
@ -89,8 +89,8 @@ fn expr_as_cast_from_usize<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Exp
|
|||
// receiver, the arg of the method call, and the method.
|
||||
fn expr_as_ptr_offset_call<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
expr: &'tcx Expr,
|
||||
) -> Option<(&'tcx Expr, &'tcx Expr, Method)> {
|
||||
expr: &'tcx Expr<'_>,
|
||||
) -> Option<(&'tcx Expr<'tcx>, &'tcx Expr<'tcx>, Method)> {
|
||||
if let ExprKind::MethodCall(ref path_segment, _, ref args) = expr.kind {
|
||||
if is_expr_ty_raw_ptr(cx, &args[0]) {
|
||||
if path_segment.ident.name == sym!(offset) {
|
||||
|
@ -105,20 +105,20 @@ fn expr_as_ptr_offset_call<'a, 'tcx>(
|
|||
}
|
||||
|
||||
// Is the type of the expression a usize?
|
||||
fn is_expr_ty_usize<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr) -> bool {
|
||||
fn is_expr_ty_usize<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr<'_>) -> bool {
|
||||
cx.tables.expr_ty(expr) == cx.tcx.types.usize
|
||||
}
|
||||
|
||||
// Is the type of the expression a raw pointer?
|
||||
fn is_expr_ty_raw_ptr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr) -> bool {
|
||||
fn is_expr_ty_raw_ptr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &Expr<'_>) -> bool {
|
||||
cx.tables.expr_ty(expr).is_unsafe_ptr()
|
||||
}
|
||||
|
||||
fn build_suggestion<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
method: Method,
|
||||
receiver_expr: &Expr,
|
||||
cast_lhs_expr: &Expr,
|
||||
receiver_expr: &Expr<'_>,
|
||||
cast_lhs_expr: &Expr<'_>,
|
||||
) -> Option<String> {
|
||||
let receiver = utils::snippet_opt(cx, receiver_expr.span)?;
|
||||
let cast_lhs = utils::snippet_opt(cx, cast_lhs_expr.span)?;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use if_chain::if_chain;
|
||||
use rustc::declare_lint_pass;
|
||||
use rustc::hir::def::{DefKind, Res};
|
||||
use rustc::hir::ptr::P;
|
||||
use rustc::hir::*;
|
||||
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||
use rustc_errors::Applicability;
|
||||
|
@ -47,7 +46,7 @@ impl QuestionMark {
|
|||
/// ```
|
||||
///
|
||||
/// 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 Some((if_expr, body, else_)) = higher::if_block(&expr);
|
||||
if let ExprKind::MethodCall(segment, _, args) = &if_expr.kind;
|
||||
|
@ -62,7 +61,7 @@ impl QuestionMark {
|
|||
if let Some(else_) = else_ {
|
||||
if_chain! {
|
||||
if let ExprKind::Block(block, None) = &else_.kind;
|
||||
if block.stmts.len() == 0;
|
||||
if block.stmts.is_empty();
|
||||
if let Some(block_expr) = &block.expr;
|
||||
if SpanlessEq::new(cx).ignore_fn().eq_expr(subject, block_expr);
|
||||
then {
|
||||
|
@ -95,19 +94,19 @@ impl QuestionMark {
|
|||
}
|
||||
}
|
||||
|
||||
fn moves_by_default(cx: &LateContext<'_, '_>, expression: &Expr) -> bool {
|
||||
fn moves_by_default(cx: &LateContext<'_, '_>, expression: &Expr<'_>) -> bool {
|
||||
let expr_ty = cx.tables.expr_ty(expression);
|
||||
|
||||
!expr_ty.is_copy_modulo_regions(cx.tcx, cx.param_env, expression.span)
|
||||
}
|
||||
|
||||
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.kind {
|
||||
ExprKind::Block(ref block, _) => {
|
||||
if let Some(return_expression) = Self::return_expression(block) {
|
||||
|
@ -130,14 +129,14 @@ impl QuestionMark {
|
|||
}
|
||||
}
|
||||
|
||||
fn return_expression(block: &Block) -> Option<&P<Expr>> {
|
||||
fn return_expression<'tcx>(block: &Block<'tcx>) -> Option<&'tcx Expr<'tcx>> {
|
||||
// Check if last expression is a return statement. Then, return the expression
|
||||
if_chain! {
|
||||
if block.stmts.len() == 1;
|
||||
if let Some(expr) = block.stmts.iter().last();
|
||||
if let StmtKind::Semi(ref expr) = expr.kind;
|
||||
if let ExprKind::Ret(ref ret_expr) = expr.kind;
|
||||
if let &Some(ref ret_expr) = ret_expr;
|
||||
if let ExprKind::Ret(ret_expr) = expr.kind;
|
||||
if let Some(ret_expr) = ret_expr;
|
||||
|
||||
then {
|
||||
return Some(ret_expr);
|
||||
|
@ -146,7 +145,7 @@ impl QuestionMark {
|
|||
|
||||
// Check for `return` without a semicolon.
|
||||
if_chain! {
|
||||
if block.stmts.len() == 0;
|
||||
if block.stmts.is_empty();
|
||||
if let Some(ExprKind::Ret(Some(ret_expr))) = block.expr.as_ref().map(|e| &e.kind);
|
||||
then {
|
||||
return Some(ret_expr);
|
||||
|
@ -158,7 +157,7 @@ impl QuestionMark {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for QuestionMark {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
Self::check_is_none_and_early_return_none(cx, expr);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ declare_lint_pass!(Ranges => [
|
|||
]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ranges {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if let ExprKind::MethodCall(ref path, _, ref args) = expr.kind {
|
||||
let name = path.ident.as_str();
|
||||
if name == "zip" && args.len() == 2 {
|
||||
|
@ -125,7 +125,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Ranges {
|
|||
}
|
||||
|
||||
// exclusive range plus one: `x..(y+1)`
|
||||
fn check_exclusive_range_plus_one(cx: &LateContext<'_, '_>, expr: &Expr) {
|
||||
fn check_exclusive_range_plus_one(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
|
||||
if_chain! {
|
||||
if let Some(higher::Range {
|
||||
start,
|
||||
|
@ -174,7 +174,7 @@ fn check_exclusive_range_plus_one(cx: &LateContext<'_, '_>, expr: &Expr) {
|
|||
}
|
||||
|
||||
// inclusive range minus one: `x..=(y-1)`
|
||||
fn check_inclusive_range_minus_one(cx: &LateContext<'_, '_>, expr: &Expr) {
|
||||
fn check_inclusive_range_minus_one(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
|
||||
if_chain! {
|
||||
if let Some(higher::Range { start, end: Some(end), limits: RangeLimits::Closed }) = higher::range(cx, expr);
|
||||
if let Some(y) = y_minus_one(cx, end);
|
||||
|
@ -199,7 +199,7 @@ fn check_inclusive_range_minus_one(cx: &LateContext<'_, '_>, expr: &Expr) {
|
|||
}
|
||||
}
|
||||
|
||||
fn y_plus_one<'t>(cx: &LateContext<'_, '_>, expr: &'t Expr) -> Option<&'t Expr> {
|
||||
fn y_plus_one<'t>(cx: &LateContext<'_, '_>, expr: &'t Expr<'_>) -> Option<&'t Expr<'t>> {
|
||||
match expr.kind {
|
||||
ExprKind::Binary(
|
||||
Spanned {
|
||||
|
@ -220,7 +220,7 @@ fn y_plus_one<'t>(cx: &LateContext<'_, '_>, expr: &'t Expr) -> Option<&'t Expr>
|
|||
}
|
||||
}
|
||||
|
||||
fn y_minus_one<'t>(cx: &LateContext<'_, '_>, expr: &'t Expr) -> Option<&'t Expr> {
|
||||
fn y_minus_one<'t>(cx: &LateContext<'_, '_>, expr: &'t Expr<'_>) -> Option<&'t Expr<'t>> {
|
||||
match expr.kind {
|
||||
ExprKind::Binary(
|
||||
Spanned {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use crate::utils::{match_qpath, paths, snippet, span_lint_and_then};
|
||||
use rustc::declare_lint_pass;
|
||||
use rustc::hir::ptr::P;
|
||||
use rustc::hir::*;
|
||||
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||
use rustc_errors::Applicability;
|
||||
|
@ -46,8 +45,8 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(RedundantPatternMatching => [REDUNDANT_PATTERN_MATCHING]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantPatternMatching {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
if let ExprKind::Match(ref op, ref arms, ref match_source) = expr.kind {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if let ExprKind::Match(op, arms, ref match_source) = &expr.kind {
|
||||
match match_source {
|
||||
MatchSource::Normal => find_sugg_for_match(cx, expr, op, arms),
|
||||
MatchSource::IfLetDesugar { contains_else_clause } => {
|
||||
|
@ -61,9 +60,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantPatternMatching {
|
|||
|
||||
fn find_sugg_for_if_let<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
expr: &'tcx Expr,
|
||||
op: &P<Expr>,
|
||||
arms: &HirVec<Arm>,
|
||||
expr: &'tcx Expr<'_>,
|
||||
op: &Expr<'_>,
|
||||
arms: &[Arm<'_>],
|
||||
has_else: bool,
|
||||
) {
|
||||
let good_method = match arms[0].pat.kind {
|
||||
|
@ -107,7 +106,7 @@ fn find_sugg_for_if_let<'a, 'tcx>(
|
|||
);
|
||||
}
|
||||
|
||||
fn find_sugg_for_match<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, op: &P<Expr>, arms: &HirVec<Arm>) {
|
||||
fn find_sugg_for_match<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>, op: &Expr<'_>, arms: &[Arm<'_>]) {
|
||||
if arms.len() == 2 {
|
||||
let node_pair = (&arms[0].pat.kind, &arms[1].pat.kind);
|
||||
|
||||
|
@ -172,7 +171,7 @@ fn find_sugg_for_match<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, o
|
|||
}
|
||||
|
||||
fn find_good_method_for_match<'a>(
|
||||
arms: &HirVec<Arm>,
|
||||
arms: &[Arm<'_>],
|
||||
path_left: &QPath,
|
||||
path_right: &QPath,
|
||||
expected_left: &[&str],
|
||||
|
|
|
@ -79,7 +79,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Regex {
|
|||
self.spans.clear();
|
||||
}
|
||||
|
||||
fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx Block) {
|
||||
fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx Block<'_>) {
|
||||
if_chain! {
|
||||
if self.last.is_none();
|
||||
if let Some(ref expr) = block.expr;
|
||||
|
@ -99,13 +99,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Regex {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_block_post(&mut self, _: &LateContext<'a, 'tcx>, block: &'tcx Block) {
|
||||
fn check_block_post(&mut self, _: &LateContext<'a, 'tcx>, block: &'tcx Block<'_>) {
|
||||
if self.last.map_or(false, |id| block.hir_id == id) {
|
||||
self.last = None;
|
||||
}
|
||||
}
|
||||
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if_chain! {
|
||||
if let ExprKind::Call(ref fun, ref args) = expr.kind;
|
||||
if let ExprKind::Path(ref qpath) = fun.kind;
|
||||
|
@ -138,7 +138,7 @@ fn str_span(base: Span, c: regex_syntax::ast::Span, offset: u16) -> Span {
|
|||
Span::new(start, end, base.ctxt())
|
||||
}
|
||||
|
||||
fn const_str<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) -> Option<String> {
|
||||
fn const_str<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) -> Option<String> {
|
||||
constant(cx, cx.tables, e).and_then(|(c, _)| match c {
|
||||
Constant::Str(s) => Some(s),
|
||||
_ => None,
|
||||
|
@ -184,10 +184,10 @@ fn is_trivial_regex(s: ®ex_syntax::hir::Hir) -> Option<&'static str> {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_set<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, utf8: bool) {
|
||||
fn check_set<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>, utf8: bool) {
|
||||
if_chain! {
|
||||
if let ExprKind::AddrOf(BorrowKind::Ref, _, ref expr) = expr.kind;
|
||||
if let ExprKind::Array(ref exprs) = expr.kind;
|
||||
if let ExprKind::Array(exprs) = expr.kind;
|
||||
then {
|
||||
for expr in exprs {
|
||||
check_regex(cx, expr, utf8);
|
||||
|
@ -196,7 +196,7 @@ fn check_set<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, utf8: bool)
|
|||
}
|
||||
}
|
||||
|
||||
fn check_regex<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, utf8: bool) {
|
||||
fn check_regex<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>, utf8: bool) {
|
||||
let mut parser = regex_syntax::ParserBuilder::new()
|
||||
.unicode(utf8)
|
||||
.allow_invalid_utf8(!utf8)
|
||||
|
|
|
@ -35,7 +35,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(ReplaceConsts => [REPLACE_CONSTS]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ReplaceConsts {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) {
|
||||
if_chain! {
|
||||
if let hir::ExprKind::Path(ref qp) = expr.kind;
|
||||
if let Res::Def(DefKind::Const, def_id) = cx.tables.qpath_res(qp, expr.hir_id);
|
||||
|
|
|
@ -110,9 +110,9 @@ fn check_fn<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, decl: &'tcx FnDecl, body: &'tc
|
|||
check_expr(cx, &body.value, &mut bindings);
|
||||
}
|
||||
|
||||
fn check_block<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, block: &'tcx Block, bindings: &mut Vec<(Name, Span)>) {
|
||||
fn check_block<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, block: &'tcx Block<'_>, bindings: &mut Vec<(Name, Span)>) {
|
||||
let len = bindings.len();
|
||||
for stmt in &block.stmts {
|
||||
for stmt in block.stmts {
|
||||
match stmt.kind {
|
||||
StmtKind::Local(ref local) => check_local(cx, local, bindings),
|
||||
StmtKind::Expr(ref e) | StmtKind::Semi(ref e) => check_expr(cx, e, bindings),
|
||||
|
@ -125,7 +125,7 @@ fn check_block<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, block: &'tcx Block, binding
|
|||
bindings.truncate(len);
|
||||
}
|
||||
|
||||
fn check_local<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, local: &'tcx Local, bindings: &mut Vec<(Name, Span)>) {
|
||||
fn check_local<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, local: &'tcx Local<'_>, bindings: &mut Vec<(Name, Span)>) {
|
||||
if in_external_macro(cx.sess(), local.span) {
|
||||
return;
|
||||
}
|
||||
|
@ -160,8 +160,8 @@ fn is_binding(cx: &LateContext<'_, '_>, pat_id: HirId) -> bool {
|
|||
|
||||
fn check_pat<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
pat: &'tcx Pat,
|
||||
init: Option<&'tcx Expr>,
|
||||
pat: &'tcx Pat<'_>,
|
||||
init: Option<&'tcx Expr<'_>>,
|
||||
span: Span,
|
||||
bindings: &mut Vec<(Name, Span)>,
|
||||
) {
|
||||
|
@ -187,7 +187,7 @@ fn check_pat<'a, 'tcx>(
|
|||
check_pat(cx, p, init, span, bindings);
|
||||
}
|
||||
},
|
||||
PatKind::Struct(_, ref pfields, _) => {
|
||||
PatKind::Struct(_, pfields, _) => {
|
||||
if let Some(init_struct) = init {
|
||||
if let ExprKind::Struct(_, ref efields, _) = init_struct.kind {
|
||||
for field in pfields {
|
||||
|
@ -208,7 +208,7 @@ fn check_pat<'a, 'tcx>(
|
|||
}
|
||||
}
|
||||
},
|
||||
PatKind::Tuple(ref inner, _) => {
|
||||
PatKind::Tuple(inner, _) => {
|
||||
if let Some(init_tup) = init {
|
||||
if let ExprKind::Tup(ref tup) = init_tup.kind {
|
||||
for (i, p) in inner.iter().enumerate() {
|
||||
|
@ -247,7 +247,7 @@ fn lint_shadow<'a, 'tcx>(
|
|||
name: Name,
|
||||
span: Span,
|
||||
pattern_span: Span,
|
||||
init: Option<&'tcx Expr>,
|
||||
init: Option<&'tcx Expr<'_>>,
|
||||
prev_span: Span,
|
||||
) {
|
||||
if let Some(expr) = init {
|
||||
|
@ -309,7 +309,7 @@ fn lint_shadow<'a, 'tcx>(
|
|||
}
|
||||
}
|
||||
|
||||
fn check_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, bindings: &mut Vec<(Name, Span)>) {
|
||||
fn check_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>, bindings: &mut Vec<(Name, Span)>) {
|
||||
if in_external_macro(cx.sess(), expr.span) {
|
||||
return;
|
||||
}
|
||||
|
@ -321,12 +321,12 @@ fn check_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, bindings:
|
|||
ExprKind::Block(ref block, _) | ExprKind::Loop(ref block, _, _) => check_block(cx, block, bindings),
|
||||
// ExprKind::Call
|
||||
// ExprKind::MethodCall
|
||||
ExprKind::Array(ref v) | ExprKind::Tup(ref v) => {
|
||||
ExprKind::Array(v) | ExprKind::Tup(v) => {
|
||||
for e in v {
|
||||
check_expr(cx, e, bindings)
|
||||
}
|
||||
},
|
||||
ExprKind::Match(ref init, ref arms, _) => {
|
||||
ExprKind::Match(ref init, arms, _) => {
|
||||
check_expr(cx, init, bindings);
|
||||
let len = bindings.len();
|
||||
for arm in arms {
|
||||
|
@ -365,7 +365,7 @@ fn check_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: &'tcx Ty, bindings: &mut V
|
|||
}
|
||||
}
|
||||
|
||||
fn is_self_shadow(name: Name, expr: &Expr) -> bool {
|
||||
fn is_self_shadow(name: Name, expr: &Expr<'_>) -> bool {
|
||||
match expr.kind {
|
||||
ExprKind::Box(ref inner) | ExprKind::AddrOf(_, _, ref inner) => is_self_shadow(name, inner),
|
||||
ExprKind::Block(ref block, _) => {
|
||||
|
|
|
@ -43,24 +43,24 @@ struct VecAllocation<'tcx> {
|
|||
variable_name: Symbol,
|
||||
|
||||
/// Reference to the expression which allocates the vector
|
||||
allocation_expr: &'tcx Expr,
|
||||
allocation_expr: &'tcx Expr<'tcx>,
|
||||
|
||||
/// Reference to the expression used as argument on `with_capacity` call. This is used
|
||||
/// to only match slow zero-filling idioms of the same length than vector initialization.
|
||||
len_expr: &'tcx Expr,
|
||||
len_expr: &'tcx Expr<'tcx>,
|
||||
}
|
||||
|
||||
/// Type of slow initialization
|
||||
enum InitializationType<'tcx> {
|
||||
/// Extend is a slow initialization with the form `vec.extend(repeat(0).take(..))`
|
||||
Extend(&'tcx Expr),
|
||||
Extend(&'tcx Expr<'tcx>),
|
||||
|
||||
/// Resize is a slow initialization with the form `vec.resize(.., 0)`
|
||||
Resize(&'tcx Expr),
|
||||
Resize(&'tcx Expr<'tcx>),
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SlowVectorInit {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
// Matches initialization on reassignements. For example: `vec = Vec::with_capacity(100)`
|
||||
if_chain! {
|
||||
if let ExprKind::Assign(ref left, ref right, _) = expr.kind;
|
||||
|
@ -84,7 +84,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SlowVectorInit {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) {
|
||||
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt<'_>) {
|
||||
// Matches statements which initializes vectors. For example: `let mut vec = Vec::with_capacity(10)`
|
||||
if_chain! {
|
||||
if let StmtKind::Local(ref local) = stmt.kind;
|
||||
|
@ -108,7 +108,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SlowVectorInit {
|
|||
impl SlowVectorInit {
|
||||
/// Checks if the given expression is `Vec::with_capacity(..)`. It will return the expression
|
||||
/// of the first argument of `with_capacity` call if it matches or `None` if it does not.
|
||||
fn is_vec_with_capacity(expr: &Expr) -> Option<&Expr> {
|
||||
fn is_vec_with_capacity<'tcx>(expr: &Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> {
|
||||
if_chain! {
|
||||
if let ExprKind::Call(ref func, ref args) = expr.kind;
|
||||
if let ExprKind::Path(ref path) = func.kind;
|
||||
|
@ -163,7 +163,7 @@ impl SlowVectorInit {
|
|||
|
||||
fn emit_lint<'tcx>(
|
||||
cx: &LateContext<'_, 'tcx>,
|
||||
slow_fill: &Expr,
|
||||
slow_fill: &Expr<'_>,
|
||||
vec_alloc: &VecAllocation<'_>,
|
||||
msg: &str,
|
||||
lint: &'static Lint,
|
||||
|
@ -198,7 +198,7 @@ struct VectorInitializationVisitor<'a, 'tcx> {
|
|||
|
||||
impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> {
|
||||
/// Checks if the given expression is extending a vector with `repeat(0).take(..)`
|
||||
fn search_slow_extend_filling(&mut self, expr: &'tcx Expr) {
|
||||
fn search_slow_extend_filling(&mut self, expr: &'tcx Expr<'_>) {
|
||||
if_chain! {
|
||||
if self.initialization_found;
|
||||
if let ExprKind::MethodCall(ref path, _, ref args) = expr.kind;
|
||||
|
@ -215,7 +215,7 @@ impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
/// Checks if the given expression is resizing a vector with 0
|
||||
fn search_slow_resize_filling(&mut self, expr: &'tcx Expr) {
|
||||
fn search_slow_resize_filling(&mut self, expr: &'tcx Expr<'_>) {
|
||||
if_chain! {
|
||||
if self.initialization_found;
|
||||
if let ExprKind::MethodCall(ref path, _, ref args) = expr.kind;
|
||||
|
@ -238,7 +238,7 @@ impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
/// Returns `true` if give expression is `repeat(0).take(...)`
|
||||
fn is_repeat_take(&self, expr: &Expr) -> bool {
|
||||
fn is_repeat_take(&self, expr: &Expr<'_>) -> bool {
|
||||
if_chain! {
|
||||
if let ExprKind::MethodCall(ref take_path, _, ref take_args) = expr.kind;
|
||||
if take_path.ident.name == sym!(take);
|
||||
|
@ -260,7 +260,7 @@ impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
/// Returns `true` if given expression is `repeat(0)`
|
||||
fn is_repeat_zero(expr: &Expr) -> bool {
|
||||
fn is_repeat_zero(expr: &Expr<'_>) -> bool {
|
||||
if_chain! {
|
||||
if let ExprKind::Call(ref fn_expr, ref repeat_args) = expr.kind;
|
||||
if let ExprKind::Path(ref qpath_repeat) = fn_expr.kind;
|
||||
|
@ -279,7 +279,7 @@ impl<'a, 'tcx> VectorInitializationVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for VectorInitializationVisitor<'a, 'tcx> {
|
||||
fn visit_stmt(&mut self, stmt: &'tcx Stmt) {
|
||||
fn visit_stmt(&mut self, stmt: &'tcx Stmt<'_>) {
|
||||
if self.initialization_found {
|
||||
match stmt.kind {
|
||||
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => {
|
||||
|
@ -295,7 +295,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VectorInitializationVisitor<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn visit_block(&mut self, block: &'tcx Block) {
|
||||
fn visit_block(&mut self, block: &'tcx Block<'_>) {
|
||||
if self.initialization_found {
|
||||
if let Some(ref s) = block.stmts.get(0) {
|
||||
self.visit_stmt(s)
|
||||
|
@ -307,7 +307,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VectorInitializationVisitor<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr) {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
|
||||
// Skip all the expressions previous to the vector initialization
|
||||
if self.vec_alloc.allocation_expr.hir_id == expr.hir_id {
|
||||
self.initialization_found = true;
|
||||
|
|
|
@ -79,7 +79,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(StringAdd => [STRING_ADD, STRING_ADD_ASSIGN]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringAdd {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
|
||||
if in_external_macro(cx.sess(), e.span) {
|
||||
return;
|
||||
}
|
||||
|
@ -125,11 +125,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringAdd {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_string(cx: &LateContext<'_, '_>, e: &Expr) -> bool {
|
||||
fn is_string(cx: &LateContext<'_, '_>, e: &Expr<'_>) -> bool {
|
||||
match_type(cx, walk_ptrs_ty(cx.tables.expr_ty(e)), &paths::STRING)
|
||||
}
|
||||
|
||||
fn is_add(cx: &LateContext<'_, '_>, src: &Expr, target: &Expr) -> bool {
|
||||
fn is_add(cx: &LateContext<'_, '_>, src: &Expr<'_>, target: &Expr<'_>) -> bool {
|
||||
match src.kind {
|
||||
ExprKind::Binary(
|
||||
Spanned {
|
||||
|
@ -151,7 +151,7 @@ const MAX_LENGTH_BYTE_STRING_LIT: usize = 32;
|
|||
declare_lint_pass!(StringLitAsBytes => [STRING_LIT_AS_BYTES]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringLitAsBytes {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
|
||||
use crate::utils::{snippet, snippet_with_applicability};
|
||||
use syntax::ast::LitKind;
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(SuspiciousImpl => [SUSPICIOUS_ARITHMETIC_IMPL, SUSPICIOUS_OP_ASSIGN_IMPL]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SuspiciousImpl {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) {
|
||||
if let hir::ExprKind::Binary(binop, _, _) = expr.kind {
|
||||
match binop.node {
|
||||
hir::BinOpKind::Eq
|
||||
|
@ -148,7 +148,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for SuspiciousImpl {
|
|||
|
||||
fn check_binop(
|
||||
cx: &LateContext<'_, '_>,
|
||||
expr: &hir::Expr,
|
||||
expr: &hir::Expr<'_>,
|
||||
binop: hir::BinOpKind,
|
||||
traits: &[&'static str],
|
||||
expected_ops: &[hir::BinOpKind],
|
||||
|
@ -185,7 +185,7 @@ struct BinaryExprVisitor {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for BinaryExprVisitor {
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) {
|
||||
match expr.kind {
|
||||
hir::ExprKind::Binary(..)
|
||||
| hir::ExprKind::Unary(hir::UnOp::UnNot, _)
|
||||
|
|
|
@ -69,14 +69,14 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(Swap => [MANUAL_SWAP, ALMOST_SWAPPED]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Swap {
|
||||
fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx Block) {
|
||||
fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx Block<'_>) {
|
||||
check_manual_swap(cx, block);
|
||||
check_suspicious_swap(cx, block);
|
||||
}
|
||||
}
|
||||
|
||||
/// Implementation of the `MANUAL_SWAP` lint.
|
||||
fn check_manual_swap(cx: &LateContext<'_, '_>, block: &Block) {
|
||||
fn check_manual_swap(cx: &LateContext<'_, '_>, block: &Block<'_>) {
|
||||
for w in block.stmts.windows(3) {
|
||||
if_chain! {
|
||||
// let t = foo();
|
||||
|
@ -176,7 +176,7 @@ enum Slice<'a> {
|
|||
/// // can be written as
|
||||
/// a.swap(0, 1);
|
||||
/// ```
|
||||
Swappable(&'a Expr, &'a Expr, &'a Expr),
|
||||
Swappable(&'a Expr<'a>, &'a Expr<'a>, &'a Expr<'a>),
|
||||
/// The `swap` function cannot be used.
|
||||
///
|
||||
/// ## Example
|
||||
|
@ -193,7 +193,7 @@ enum Slice<'a> {
|
|||
}
|
||||
|
||||
/// Checks if both expressions are index operations into "slice-like" types.
|
||||
fn check_for_slice<'a>(cx: &LateContext<'_, '_>, lhs1: &'a Expr, lhs2: &'a Expr) -> Slice<'a> {
|
||||
fn check_for_slice<'a>(cx: &LateContext<'_, '_>, lhs1: &'a Expr<'_>, lhs2: &'a Expr<'_>) -> Slice<'a> {
|
||||
if let ExprKind::Index(ref lhs1, ref idx1) = lhs1.kind {
|
||||
if let ExprKind::Index(ref lhs2, ref idx2) = lhs2.kind {
|
||||
if SpanlessEq::new(cx).ignore_fn().eq_expr(lhs1, lhs2) {
|
||||
|
@ -216,7 +216,7 @@ fn check_for_slice<'a>(cx: &LateContext<'_, '_>, lhs1: &'a Expr, lhs2: &'a Expr)
|
|||
}
|
||||
|
||||
/// Implementation of the `ALMOST_SWAPPED` lint.
|
||||
fn check_suspicious_swap(cx: &LateContext<'_, '_>, block: &Block) {
|
||||
fn check_suspicious_swap(cx: &LateContext<'_, '_>, block: &Block<'_>) {
|
||||
for w in block.stmts.windows(2) {
|
||||
if_chain! {
|
||||
if let StmtKind::Semi(ref first) = w[0].kind;
|
||||
|
|
|
@ -24,7 +24,7 @@ declare_clippy_lint! {
|
|||
"assignments to temporaries"
|
||||
}
|
||||
|
||||
fn is_temporary(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
|
||||
fn is_temporary(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool {
|
||||
match &expr.kind {
|
||||
ExprKind::Struct(..) | ExprKind::Tup(..) => true,
|
||||
ExprKind::Path(qpath) => {
|
||||
|
@ -41,7 +41,7 @@ fn is_temporary(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
|
|||
declare_lint_pass!(TemporaryAssignment => [TEMPORARY_ASSIGNMENT]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TemporaryAssignment {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if let ExprKind::Assign(target, ..) = &expr.kind {
|
||||
let mut base = target;
|
||||
while let ExprKind::Field(f, _) | ExprKind::Index(f, _) = &base.kind {
|
||||
|
|
|
@ -33,7 +33,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(ToDigitIsSome => [TO_DIGIT_IS_SOME]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ToDigitIsSome {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) {
|
||||
if_chain! {
|
||||
if let hir::ExprKind::MethodCall(is_some_path, _, is_some_args) = &expr.kind;
|
||||
if is_some_path.ident.name.as_str() == "is_some";
|
||||
|
|
|
@ -292,7 +292,7 @@ static COLLECTIONS: &[&[&str]] = &[
|
|||
];
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
|
||||
#[allow(clippy::similar_names, clippy::too_many_lines)]
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
|
||||
if_chain! {
|
||||
if let ExprKind::Call(ref path_expr, ref args) = e.kind;
|
||||
if let ExprKind::Path(ref qpath) = path_expr.kind;
|
||||
|
|
|
@ -30,7 +30,7 @@ declare_lint_pass!(TransmutingNull => [TRANSMUTING_NULL]);
|
|||
const LINT_MSG: &str = "transmuting a known null pointer into a reference.";
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TransmutingNull {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if in_external_macro(cx.sess(), expr.span) {
|
||||
return;
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TransmutingNull {
|
|||
if let ExprKind::Call(ref func1, ref args1) = args[0].kind;
|
||||
if let ExprKind::Path(ref path1) = func1.kind;
|
||||
if match_qpath(path1, &paths::STD_PTR_NULL);
|
||||
if args1.len() == 0;
|
||||
if args1.is_empty();
|
||||
then {
|
||||
span_lint(cx, TRANSMUTING_NULL, expr.span, LINT_MSG)
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(TryErr => [TRY_ERR]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TryErr {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
// Looks for a structure like this:
|
||||
// match ::std::ops::Try::into_result(Err(5)) {
|
||||
// ::std::result::Result::Err(err) =>
|
||||
|
@ -97,7 +97,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TryErr {
|
|||
// In order to determine whether to suggest `.into()` or not, we need to find the error type the
|
||||
// function returns. To do that, we look for the From::from call (see tree above), and capture
|
||||
// its output type.
|
||||
fn find_err_return_type<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx ExprKind) -> Option<Ty<'tcx>> {
|
||||
fn find_err_return_type<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx ExprKind<'_>) -> Option<Ty<'tcx>> {
|
||||
if let ExprKind::Match(_, ref arms, MatchSource::TryDesugar) = expr {
|
||||
arms.iter().find_map(|ty| find_err_return_type_arm(cx, ty))
|
||||
} else {
|
||||
|
@ -106,7 +106,7 @@ fn find_err_return_type<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx ExprKi
|
|||
}
|
||||
|
||||
// Check for From::from in one of the match arms.
|
||||
fn find_err_return_type_arm<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arm: &'tcx Arm) -> Option<Ty<'tcx>> {
|
||||
fn find_err_return_type_arm<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, arm: &'tcx Arm<'_>) -> Option<Ty<'tcx>> {
|
||||
if_chain! {
|
||||
if let ExprKind::Ret(Some(ref err_ret)) = arm.body.kind;
|
||||
if let ExprKind::Call(ref from_error_path, ref from_error_args) = err_ret.kind;
|
||||
|
|
|
@ -193,7 +193,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Types {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_local(&mut self, cx: &LateContext<'_, '_>, local: &Local) {
|
||||
fn check_local(&mut self, cx: &LateContext<'_, '_>, local: &Local<'_>) {
|
||||
if let Some(ref ty) = local.ty {
|
||||
check_ty(cx, ty, true);
|
||||
}
|
||||
|
@ -462,7 +462,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(LetUnitValue => [LET_UNIT_VALUE]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetUnitValue {
|
||||
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) {
|
||||
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt<'_>) {
|
||||
if let StmtKind::Local(ref local) = stmt.kind {
|
||||
if is_unit(cx.tables.pat_ty(&local.pat)) {
|
||||
if in_external_macro(cx.sess(), stmt.span) || local.pat.span.from_expansion() {
|
||||
|
@ -537,7 +537,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(UnitCmp => [UNIT_CMP]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitCmp {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'tcx>) {
|
||||
if expr.span.from_expansion() {
|
||||
if let Some(callee) = expr.span.source_callee() {
|
||||
if let ExpnKind::Macro(MacroKind::Bang, symbol) = callee.kind {
|
||||
|
@ -610,7 +610,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(UnitArg => [UNIT_ARG]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if expr.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
@ -633,7 +633,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg {
|
|||
}
|
||||
|
||||
match expr.kind {
|
||||
ExprKind::Call(_, ref args) | ExprKind::MethodCall(_, _, ref args) => {
|
||||
ExprKind::Call(_, args) | ExprKind::MethodCall(_, _, args) => {
|
||||
for arg in args {
|
||||
if is_unit(cx.tables.expr_ty(arg)) && !is_unit_literal(arg) {
|
||||
if let ExprKind::Match(.., match_source) = &arg.kind {
|
||||
|
@ -659,7 +659,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_questionmark_desugar_marked_call(expr: &Expr) -> bool {
|
||||
fn is_questionmark_desugar_marked_call(expr: &Expr<'_>) -> bool {
|
||||
use syntax_pos::hygiene::DesugaringKind;
|
||||
if let ExprKind::Call(ref callee, _) = expr.kind {
|
||||
callee.span.is_desugaring(DesugaringKind::QuestionMark)
|
||||
|
@ -675,7 +675,7 @@ fn is_unit(ty: Ty<'_>) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_unit_literal(expr: &Expr) -> bool {
|
||||
fn is_unit_literal(expr: &Expr<'_>) -> bool {
|
||||
match expr.kind {
|
||||
ExprKind::Tup(ref slice) if slice.is_empty() => true,
|
||||
_ => false,
|
||||
|
@ -929,7 +929,7 @@ fn is_isize_or_usize(typ: Ty<'_>) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn span_precision_loss_lint(cx: &LateContext<'_, '_>, expr: &Expr, cast_from: Ty<'_>, cast_to_f64: bool) {
|
||||
fn span_precision_loss_lint(cx: &LateContext<'_, '_>, expr: &Expr<'_>, cast_from: Ty<'_>, cast_to_f64: bool) {
|
||||
let mantissa_nbits = if cast_to_f64 { 52 } else { 23 };
|
||||
let arch_dependent = is_isize_or_usize(cast_from) && cast_to_f64;
|
||||
let arch_dependent_str = "on targets with 64-bit wide pointers ";
|
||||
|
@ -956,7 +956,7 @@ fn span_precision_loss_lint(cx: &LateContext<'_, '_>, expr: &Expr, cast_from: Ty
|
|||
);
|
||||
}
|
||||
|
||||
fn should_strip_parens(op: &Expr, snip: &str) -> bool {
|
||||
fn should_strip_parens(op: &Expr<'_>, snip: &str) -> bool {
|
||||
if let ExprKind::Binary(_, _, _) = op.kind {
|
||||
if snip.starts_with('(') && snip.ends_with(')') {
|
||||
return true;
|
||||
|
@ -965,7 +965,7 @@ fn should_strip_parens(op: &Expr, snip: &str) -> bool {
|
|||
false
|
||||
}
|
||||
|
||||
fn span_lossless_lint(cx: &LateContext<'_, '_>, expr: &Expr, op: &Expr, cast_from: Ty<'_>, cast_to: Ty<'_>) {
|
||||
fn span_lossless_lint(cx: &LateContext<'_, '_>, expr: &Expr<'_>, op: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) {
|
||||
// Do not suggest using From in consts/statics until it is valid to do so (see #2267).
|
||||
if in_constant(cx, expr.hir_id) {
|
||||
return;
|
||||
|
@ -1005,7 +1005,7 @@ enum ArchSuffix {
|
|||
None,
|
||||
}
|
||||
|
||||
fn check_loss_of_sign(cx: &LateContext<'_, '_>, expr: &Expr, op: &Expr, cast_from: Ty<'_>, cast_to: Ty<'_>) {
|
||||
fn check_loss_of_sign(cx: &LateContext<'_, '_>, expr: &Expr<'_>, op: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) {
|
||||
if !cast_from.is_signed() || cast_to.is_signed() {
|
||||
return;
|
||||
}
|
||||
|
@ -1049,7 +1049,7 @@ fn check_loss_of_sign(cx: &LateContext<'_, '_>, expr: &Expr, op: &Expr, cast_fro
|
|||
);
|
||||
}
|
||||
|
||||
fn check_truncation_and_wrapping(cx: &LateContext<'_, '_>, expr: &Expr, cast_from: Ty<'_>, cast_to: Ty<'_>) {
|
||||
fn check_truncation_and_wrapping(cx: &LateContext<'_, '_>, expr: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) {
|
||||
let arch_64_suffix = " on targets with 64-bit wide pointers";
|
||||
let arch_32_suffix = " on targets with 32-bit wide pointers";
|
||||
let cast_unsigned_to_signed = !cast_from.is_signed() && cast_to.is_signed();
|
||||
|
@ -1120,7 +1120,7 @@ fn check_truncation_and_wrapping(cx: &LateContext<'_, '_>, expr: &Expr, cast_fro
|
|||
}
|
||||
}
|
||||
|
||||
fn check_lossless(cx: &LateContext<'_, '_>, expr: &Expr, op: &Expr, cast_from: Ty<'_>, cast_to: Ty<'_>) {
|
||||
fn check_lossless(cx: &LateContext<'_, '_>, expr: &Expr<'_>, op: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) {
|
||||
let cast_signed_to_unsigned = cast_from.is_signed() && !cast_to.is_signed();
|
||||
let from_nbits = int_ty_to_nbits(cast_from, cx.tcx);
|
||||
let to_nbits = int_ty_to_nbits(cast_to, cx.tcx);
|
||||
|
@ -1169,7 +1169,7 @@ fn fp_ty_mantissa_nbits(typ: Ty<'_>) -> u32 {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Casts {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if expr.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
@ -1223,8 +1223,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Casts {
|
|||
|
||||
fn lint_numeric_casts<'tcx>(
|
||||
cx: &LateContext<'_, 'tcx>,
|
||||
expr: &Expr,
|
||||
cast_expr: &Expr,
|
||||
expr: &Expr<'tcx>,
|
||||
cast_expr: &Expr<'_>,
|
||||
cast_from: Ty<'tcx>,
|
||||
cast_to: Ty<'tcx>,
|
||||
) {
|
||||
|
@ -1280,7 +1280,7 @@ fn lint_numeric_casts<'tcx>(
|
|||
}
|
||||
}
|
||||
|
||||
fn lint_cast_ptr_alignment<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr, cast_from: Ty<'tcx>, cast_to: Ty<'tcx>) {
|
||||
fn lint_cast_ptr_alignment<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr<'_>, cast_from: Ty<'tcx>, cast_to: Ty<'tcx>) {
|
||||
if_chain! {
|
||||
if let ty::RawPtr(from_ptr_ty) = &cast_from.kind;
|
||||
if let ty::RawPtr(to_ptr_ty) = &cast_to.kind;
|
||||
|
@ -1310,8 +1310,8 @@ fn lint_cast_ptr_alignment<'tcx>(cx: &LateContext<'_, 'tcx>, expr: &Expr, cast_f
|
|||
|
||||
fn lint_fn_to_numeric_cast(
|
||||
cx: &LateContext<'_, '_>,
|
||||
expr: &Expr,
|
||||
cast_expr: &Expr,
|
||||
expr: &Expr<'_>,
|
||||
cast_expr: &Expr<'_>,
|
||||
cast_from: Ty<'_>,
|
||||
cast_to: Ty<'_>,
|
||||
) {
|
||||
|
@ -1432,7 +1432,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeComplexity {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_local(&mut self, cx: &LateContext<'a, 'tcx>, local: &'tcx Local) {
|
||||
fn check_local(&mut self, cx: &LateContext<'a, 'tcx>, local: &'tcx Local<'_>) {
|
||||
if let Some(ref ty) = local.ty {
|
||||
self.check_type(cx, ty);
|
||||
}
|
||||
|
@ -1548,7 +1548,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(CharLitAsU8 => [CHAR_LIT_AS_U8]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CharLitAsU8 {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if_chain! {
|
||||
if !expr.span.from_expansion();
|
||||
if let ExprKind::Cast(e, _) = &expr.kind;
|
||||
|
@ -1619,7 +1619,7 @@ enum ExtremeType {
|
|||
|
||||
struct ExtremeExpr<'a> {
|
||||
which: ExtremeType,
|
||||
expr: &'a Expr,
|
||||
expr: &'a Expr<'a>,
|
||||
}
|
||||
|
||||
enum AbsurdComparisonResult {
|
||||
|
@ -1628,7 +1628,7 @@ enum AbsurdComparisonResult {
|
|||
InequalityImpossible,
|
||||
}
|
||||
|
||||
fn is_cast_between_fixed_and_target<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> bool {
|
||||
fn is_cast_between_fixed_and_target<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'tcx>) -> bool {
|
||||
if let ExprKind::Cast(ref cast_exp, _) = expr.kind {
|
||||
let precast_ty = cx.tables.expr_ty(cast_exp);
|
||||
let cast_ty = cx.tables.expr_ty(expr);
|
||||
|
@ -1642,8 +1642,8 @@ fn is_cast_between_fixed_and_target<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr:
|
|||
fn detect_absurd_comparison<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
op: BinOpKind,
|
||||
lhs: &'tcx Expr,
|
||||
rhs: &'tcx Expr,
|
||||
lhs: &'tcx Expr<'_>,
|
||||
rhs: &'tcx Expr<'_>,
|
||||
) -> Option<(ExtremeExpr<'tcx>, AbsurdComparisonResult)> {
|
||||
use crate::types::AbsurdComparisonResult::*;
|
||||
use crate::types::ExtremeType::*;
|
||||
|
@ -1691,7 +1691,7 @@ fn detect_absurd_comparison<'a, 'tcx>(
|
|||
})
|
||||
}
|
||||
|
||||
fn detect_extreme_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Option<ExtremeExpr<'tcx>> {
|
||||
fn detect_extreme_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> Option<ExtremeExpr<'tcx>> {
|
||||
use crate::types::ExtremeType::*;
|
||||
|
||||
let ty = cx.tables.expr_ty(expr);
|
||||
|
@ -1720,7 +1720,7 @@ fn detect_extreme_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AbsurdExtremeComparisons {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
use crate::types::AbsurdComparisonResult::*;
|
||||
use crate::types::ExtremeType::*;
|
||||
|
||||
|
@ -1828,7 +1828,7 @@ impl Ord for FullInt {
|
|||
}
|
||||
}
|
||||
|
||||
fn numeric_cast_precast_bounds<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr) -> Option<(FullInt, FullInt)> {
|
||||
fn numeric_cast_precast_bounds<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'_>) -> Option<(FullInt, FullInt)> {
|
||||
use std::*;
|
||||
|
||||
if let ExprKind::Cast(ref cast_exp, _) = expr.kind {
|
||||
|
@ -1892,7 +1892,7 @@ fn numeric_cast_precast_bounds<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr) ->
|
|||
}
|
||||
}
|
||||
|
||||
fn node_as_const_fullint<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Option<FullInt> {
|
||||
fn node_as_const_fullint<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> Option<FullInt> {
|
||||
let val = constant(cx, cx.tables, expr)?.0;
|
||||
if let Constant::Int(const_int) = val {
|
||||
match cx.tables.expr_ty(expr).kind {
|
||||
|
@ -1905,7 +1905,7 @@ fn node_as_const_fullint<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr)
|
|||
}
|
||||
}
|
||||
|
||||
fn err_upcast_comparison(cx: &LateContext<'_, '_>, span: Span, expr: &Expr, always: bool) {
|
||||
fn err_upcast_comparison(cx: &LateContext<'_, '_>, span: Span, expr: &Expr<'_>, always: bool) {
|
||||
if let ExprKind::Cast(ref cast_val, _) = expr.kind {
|
||||
span_lint(
|
||||
cx,
|
||||
|
@ -1925,8 +1925,8 @@ fn upcast_comparison_bounds_err<'a, 'tcx>(
|
|||
span: Span,
|
||||
rel: comparisons::Rel,
|
||||
lhs_bounds: Option<(FullInt, FullInt)>,
|
||||
lhs: &'tcx Expr,
|
||||
rhs: &'tcx Expr,
|
||||
lhs: &'tcx Expr<'_>,
|
||||
rhs: &'tcx Expr<'_>,
|
||||
invert: bool,
|
||||
) {
|
||||
use crate::utils::comparisons::*;
|
||||
|
@ -1979,7 +1979,7 @@ fn upcast_comparison_bounds_err<'a, 'tcx>(
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidUpcastComparisons {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if let ExprKind::Binary(ref cmp, ref lhs, ref rhs) = expr.kind {
|
||||
let normalized = comparisons::normalize_comparison(cmp.node, lhs, rhs);
|
||||
let (rel, normalized_lhs, normalized_rhs) = if let Some(val) = normalized {
|
||||
|
@ -2298,7 +2298,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 't
|
|||
self.body = prev_body;
|
||||
}
|
||||
|
||||
fn visit_expr(&mut self, e: &'tcx Expr) {
|
||||
fn visit_expr(&mut self, e: &'tcx Expr<'_>) {
|
||||
if_chain! {
|
||||
if let ExprKind::Call(ref fun, ref args) = e.kind;
|
||||
if let ExprKind::Path(QPath::TypeRelative(ref ty, ref method)) = fun.kind;
|
||||
|
@ -2383,7 +2383,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(RefToMut => [CAST_REF_TO_MUT]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RefToMut {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||
if_chain! {
|
||||
if let ExprKind::Unary(UnOp::UnDeref, e) = &expr.kind;
|
||||
if let ExprKind::Cast(e, t) = &e.kind;
|
||||
|
|
|
@ -67,7 +67,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(Unicode => [ZERO_WIDTH_SPACE, NON_ASCII_LITERAL, UNICODE_NOT_NFC]);
|
||||
|
||||
impl LateLintPass<'_, '_> for Unicode {
|
||||
fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &'_ Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &'_ Expr<'_>) {
|
||||
if let ExprKind::Lit(ref lit) = expr.kind {
|
||||
if let LitKind::Str(_, _) = lit.node {
|
||||
check_str(cx, lit.span, expr.hir_id)
|
||||
|
|
|
@ -34,7 +34,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(UnusedIoAmount => [UNUSED_IO_AMOUNT]);
|
||||
|
||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedIoAmount {
|
||||
fn check_stmt(&mut self, cx: &LateContext<'_, '_>, s: &hir::Stmt) {
|
||||
fn check_stmt(&mut self, cx: &LateContext<'_, '_>, s: &hir::Stmt<'_>) {
|
||||
let expr = match s.kind {
|
||||
hir::StmtKind::Semi(ref expr) | hir::StmtKind::Expr(ref expr) => &**expr,
|
||||
_ => return,
|
||||
|
@ -65,7 +65,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedIoAmount {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_method_call(cx: &LateContext<'_, '_>, call: &hir::Expr, expr: &hir::Expr) {
|
||||
fn check_method_call(cx: &LateContext<'_, '_>, call: &hir::Expr<'_>, expr: &hir::Expr<'_>) {
|
||||
if let hir::ExprKind::MethodCall(ref path, _, _) = call.kind {
|
||||
let symbol = &*path.ident.as_str();
|
||||
if match_trait_method(cx, call, &paths::IO_READ) && symbol == "read" {
|
||||
|
|
|
@ -72,7 +72,7 @@ struct UnwrapInfo<'tcx> {
|
|||
/// The variable that is checked
|
||||
ident: &'tcx Path,
|
||||
/// The check, like `x.is_ok()`
|
||||
check: &'tcx Expr,
|
||||
check: &'tcx Expr<'tcx>,
|
||||
/// Whether `is_some()` or `is_ok()` was called (as opposed to `is_err()` or `is_none()`).
|
||||
safe_to_unwrap: bool,
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ struct UnwrapInfo<'tcx> {
|
|||
/// The `invert` argument tells us whether the condition is negated.
|
||||
fn collect_unwrap_info<'a, 'tcx>(
|
||||
cx: &'a LateContext<'a, 'tcx>,
|
||||
expr: &'tcx Expr,
|
||||
expr: &'tcx Expr<'_>,
|
||||
invert: bool,
|
||||
) -> Vec<UnwrapInfo<'tcx>> {
|
||||
if let ExprKind::Binary(op, left, right) = &expr.kind {
|
||||
|
@ -119,7 +119,7 @@ fn collect_unwrap_info<'a, 'tcx>(
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> UnwrappableVariablesVisitor<'a, 'tcx> {
|
||||
fn visit_branch(&mut self, cond: &'tcx Expr, branch: &'tcx Expr, else_branch: bool) {
|
||||
fn visit_branch(&mut self, cond: &'tcx Expr<'_>, branch: &'tcx Expr<'_>, else_branch: bool) {
|
||||
let prev_len = self.unwrappables.len();
|
||||
for unwrap_info in collect_unwrap_info(self.cx, cond, else_branch) {
|
||||
if is_potentially_mutated(unwrap_info.ident, cond, self.cx)
|
||||
|
@ -136,7 +136,7 @@ impl<'a, 'tcx> UnwrappableVariablesVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for UnwrappableVariablesVisitor<'a, 'tcx> {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr) {
|
||||
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
|
||||
if let Some((cond, then, els)) = if_block(&expr) {
|
||||
walk_expr(self, cond);
|
||||
self.visit_branch(cond, then, false);
|
||||
|
|
|
@ -109,7 +109,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Author {
|
|||
done();
|
||||
}
|
||||
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'_>) {
|
||||
if !has_attr(cx.sess(), &expr.attrs) {
|
||||
return;
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Author {
|
|||
done();
|
||||
}
|
||||
|
||||
fn check_arm(&mut self, cx: &LateContext<'a, 'tcx>, arm: &'tcx hir::Arm) {
|
||||
fn check_arm(&mut self, cx: &LateContext<'a, 'tcx>, arm: &'tcx hir::Arm<'_>) {
|
||||
if !has_attr(cx.sess(), &arm.attrs) {
|
||||
return;
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Author {
|
|||
done();
|
||||
}
|
||||
|
||||
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx hir::Stmt) {
|
||||
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx hir::Stmt<'_>) {
|
||||
if !has_attr(cx.sess(), stmt.kind.attrs()) {
|
||||
return;
|
||||
}
|
||||
|
@ -189,7 +189,7 @@ struct PrintVisitor {
|
|||
|
||||
impl<'tcx> Visitor<'tcx> for PrintVisitor {
|
||||
#[allow(clippy::too_many_lines)]
|
||||
fn visit_expr(&mut self, expr: &Expr) {
|
||||
fn visit_expr(&mut self, expr: &Expr<'_>) {
|
||||
// handle if desugarings
|
||||
// TODO add more desugarings here
|
||||
if let Some((cond, then, opt_else)) = higher::if_block(&expr) {
|
||||
|
@ -508,7 +508,7 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
|
|||
}
|
||||
}
|
||||
|
||||
fn visit_block(&mut self, block: &Block) {
|
||||
fn visit_block(&mut self, block: &Block<'_>) {
|
||||
let trailing_pat = self.next("trailing_expr");
|
||||
println!(" if let Some({}) = &{}.expr;", trailing_pat, self.current);
|
||||
println!(" if {}.stmts.len() == {};", self.current, block.stmts.len());
|
||||
|
@ -520,7 +520,7 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
|
|||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
fn visit_pat(&mut self, pat: &Pat) {
|
||||
fn visit_pat(&mut self, pat: &Pat<'_>) {
|
||||
print!(" if let PatKind::");
|
||||
let current = format!("{}.kind", self.current);
|
||||
match pat.kind {
|
||||
|
@ -646,7 +646,7 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
|
|||
}
|
||||
}
|
||||
|
||||
fn visit_stmt(&mut self, s: &Stmt) {
|
||||
fn visit_stmt(&mut self, s: &Stmt<'_>) {
|
||||
print!(" if let StmtKind::");
|
||||
let current = format!("{}.kind", self.current);
|
||||
match s.kind {
|
||||
|
|
|
@ -19,7 +19,11 @@ pub enum Rel {
|
|||
|
||||
/// Put the expression in the form `lhs < rhs`, `lhs <= rhs`, `lhs == rhs` or
|
||||
/// `lhs != rhs`.
|
||||
pub fn normalize_comparison<'a>(op: BinOpKind, lhs: &'a Expr, rhs: &'a Expr) -> Option<(Rel, &'a Expr, &'a Expr)> {
|
||||
pub fn normalize_comparison<'a>(
|
||||
op: BinOpKind,
|
||||
lhs: &'a Expr<'a>,
|
||||
rhs: &'a Expr<'a>,
|
||||
) -> Option<(Rel, &'a Expr<'a>, &'a Expr<'a>)> {
|
||||
match op {
|
||||
BinOpKind::Lt => Some((Rel::Lt, lhs, rhs)),
|
||||
BinOpKind::Le => Some((Rel::Le, lhs, rhs)),
|
||||
|
|
|
@ -38,18 +38,18 @@ pub fn binop(op: hir::BinOpKind) -> ast::BinOpKind {
|
|||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Range<'a> {
|
||||
/// The lower bound of the range, or `None` for ranges such as `..X`.
|
||||
pub start: Option<&'a hir::Expr>,
|
||||
pub start: Option<&'a hir::Expr<'a>>,
|
||||
/// The upper bound of the range, or `None` for ranges such as `X..`.
|
||||
pub end: Option<&'a hir::Expr>,
|
||||
pub end: Option<&'a hir::Expr<'a>>,
|
||||
/// Whether the interval is open or closed.
|
||||
pub limits: ast::RangeLimits,
|
||||
}
|
||||
|
||||
/// Higher a `hir` range to something similar to `ast::ExprKind::Range`.
|
||||
pub fn range<'a, 'b, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'b hir::Expr) -> Option<Range<'b>> {
|
||||
pub fn range<'a, 'b, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'b hir::Expr<'_>) -> Option<Range<'b>> {
|
||||
/// Finds the field named `name` in the field. Always return `Some` for
|
||||
/// convenience.
|
||||
fn get_field<'c>(name: &str, fields: &'c [hir::Field]) -> Option<&'c hir::Expr> {
|
||||
fn get_field<'c>(name: &str, fields: &'c [hir::Field<'_>]) -> Option<&'c hir::Expr<'c>> {
|
||||
let expr = &fields.iter().find(|field| field.ident.name.as_str() == name)?.expr;
|
||||
|
||||
Some(expr)
|
||||
|
@ -150,7 +150,7 @@ pub fn range<'a, 'b, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'b hir::Expr) -> O
|
|||
}
|
||||
|
||||
/// Checks if a `let` statement is from a `for` loop desugaring.
|
||||
pub fn is_from_for_desugar(local: &hir::Local) -> bool {
|
||||
pub fn is_from_for_desugar(local: &hir::Local<'_>) -> bool {
|
||||
// This will detect plain for-loops without an actual variable binding:
|
||||
//
|
||||
// ```
|
||||
|
@ -183,7 +183,9 @@ pub fn is_from_for_desugar(local: &hir::Local) -> bool {
|
|||
|
||||
/// Recover the essential nodes of a desugared for loop:
|
||||
/// `for pat in arg { body }` becomes `(pat, arg, body)`.
|
||||
pub fn for_loop(expr: &hir::Expr) -> Option<(&hir::Pat, &hir::Expr, &hir::Expr)> {
|
||||
pub fn for_loop<'tcx>(
|
||||
expr: &'tcx hir::Expr<'tcx>,
|
||||
) -> Option<(&hir::Pat<'_>, &'tcx hir::Expr<'tcx>, &'tcx hir::Expr<'tcx>)> {
|
||||
if_chain! {
|
||||
if let hir::ExprKind::Match(ref iterexpr, ref arms, hir::MatchSource::ForLoopDesugar) = expr.kind;
|
||||
if let hir::ExprKind::Call(_, ref iterargs) = iterexpr.kind;
|
||||
|
@ -202,7 +204,7 @@ pub fn for_loop(expr: &hir::Expr) -> Option<(&hir::Pat, &hir::Expr, &hir::Expr)>
|
|||
|
||||
/// Recover the essential nodes of a desugared while loop:
|
||||
/// `while cond { body }` becomes `(cond, body)`.
|
||||
pub fn while_loop(expr: &hir::Expr) -> Option<(&hir::Expr, &hir::Expr)> {
|
||||
pub fn while_loop<'tcx>(expr: &'tcx hir::Expr<'tcx>) -> Option<(&'tcx hir::Expr<'tcx>, &'tcx hir::Expr<'tcx>)> {
|
||||
if_chain! {
|
||||
if let hir::ExprKind::Loop(block, _, hir::LoopSource::While) = &expr.kind;
|
||||
if let hir::Block { expr: Some(expr), .. } = &**block;
|
||||
|
@ -219,7 +221,13 @@ pub fn while_loop(expr: &hir::Expr) -> Option<(&hir::Expr, &hir::Expr)> {
|
|||
|
||||
/// Recover the essential nodes of a desugared if block
|
||||
/// `if cond { then } else { els }` becomes `(cond, then, Some(els))`
|
||||
pub fn if_block(expr: &hir::Expr) -> Option<(&hir::Expr, &hir::Expr, Option<&hir::Expr>)> {
|
||||
pub fn if_block<'tcx>(
|
||||
expr: &'tcx hir::Expr<'tcx>,
|
||||
) -> Option<(
|
||||
&'tcx hir::Expr<'tcx>,
|
||||
&'tcx hir::Expr<'tcx>,
|
||||
Option<&'tcx hir::Expr<'tcx>>,
|
||||
)> {
|
||||
if let hir::ExprKind::Match(ref cond, ref arms, hir::MatchSource::IfDesugar { contains_else_clause }) = expr.kind {
|
||||
let cond = if let hir::ExprKind::DropTemps(ref cond) = cond.kind {
|
||||
cond
|
||||
|
@ -241,14 +249,14 @@ pub fn if_block(expr: &hir::Expr) -> Option<(&hir::Expr, &hir::Expr, Option<&hir
|
|||
/// Represent the pre-expansion arguments of a `vec!` invocation.
|
||||
pub enum VecArgs<'a> {
|
||||
/// `vec![elem; len]`
|
||||
Repeat(&'a hir::Expr, &'a hir::Expr),
|
||||
Repeat(&'a hir::Expr<'a>, &'a hir::Expr<'a>),
|
||||
/// `vec![a, b, c]`
|
||||
Vec(&'a [hir::Expr]),
|
||||
Vec(&'a [hir::Expr<'a>]),
|
||||
}
|
||||
|
||||
/// Returns the arguments of the `vec!` macro if this expression was expanded
|
||||
/// from `vec!`.
|
||||
pub fn vec_macro<'e>(cx: &LateContext<'_, '_>, expr: &'e hir::Expr) -> Option<VecArgs<'e>> {
|
||||
pub fn vec_macro<'e>(cx: &LateContext<'_, '_>, expr: &'e hir::Expr<'_>) -> Option<VecArgs<'e>> {
|
||||
if_chain! {
|
||||
if let hir::ExprKind::Call(ref fun, ref args) = expr.kind;
|
||||
if let hir::ExprKind::Path(ref qpath) = fun.kind;
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue