Fix all occurences of needless_borrow internally

This commit is contained in:
Jason Newcomb 2021-04-02 17:35:32 -04:00
parent d2ba777159
commit 12fce55766
No known key found for this signature in database
GPG key ID: DA59E8643A37ED06
183 changed files with 2150 additions and 2162 deletions

View file

@ -68,7 +68,7 @@ pub fn run(check: bool, verbose: bool) {
continue;
}
success &= rustfmt(context, &path)?;
success &= rustfmt(context, path)?;
}
Ok(success)

View file

@ -101,7 +101,7 @@ impl Lint {
#[must_use]
pub fn gen_lint_group_list<'a>(lints: impl Iterator<Item = &'a Lint>) -> Vec<String> {
lints
.map(|l| format!(" LintId::of(&{}::{}),", l.module, l.name.to_uppercase()))
.map(|l| format!(" LintId::of({}::{}),", l.module, l.name.to_uppercase()))
.sorted()
.collect::<Vec<String>>()
}
@ -154,17 +154,17 @@ pub fn gen_register_lint_list<'a>(
let header = " store.register_lints(&[".to_string();
let footer = " ]);".to_string();
let internal_lints = internal_lints
.sorted_by_key(|l| format!(" &{}::{},", l.module, l.name.to_uppercase()))
.sorted_by_key(|l| format!(" {}::{},", l.module, l.name.to_uppercase()))
.map(|l| {
format!(
" #[cfg(feature = \"internal-lints\")]\n &{}::{},",
" #[cfg(feature = \"internal-lints\")]\n {}::{},",
l.module,
l.name.to_uppercase()
)
});
let other_lints = usable_lints
.sorted_by_key(|l| format!(" &{}::{},", l.module, l.name.to_uppercase()))
.map(|l| format!(" &{}::{},", l.module, l.name.to_uppercase()))
.sorted_by_key(|l| format!(" {}::{},", l.module, l.name.to_uppercase()))
.map(|l| format!(" {}::{},", l.module, l.name.to_uppercase()))
.sorted();
let mut lint_list = vec![header];
lint_list.extend(internal_lints);
@ -550,9 +550,9 @@ fn test_gen_lint_group_list() {
Lint::new("internal", "internal_style", "abc", None, "module_name"),
];
let expected = vec![
" LintId::of(&module_name::ABC),".to_string(),
" LintId::of(&module_name::INTERNAL),".to_string(),
" LintId::of(&module_name::SHOULD_ASSERT_EQ),".to_string(),
" LintId::of(module_name::ABC),".to_string(),
" LintId::of(module_name::INTERNAL),".to_string(),
" LintId::of(module_name::SHOULD_ASSERT_EQ),".to_string(),
];
assert_eq!(expected, gen_lint_group_list(lints.iter()));
}

View file

@ -44,7 +44,7 @@ declare_lint_pass!(AbsurdExtremeComparisons => [ABSURD_EXTREME_COMPARISONS]);
impl<'tcx> LateLintPass<'tcx> for AbsurdExtremeComparisons {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if let ExprKind::Binary(ref cmp, ref lhs, ref rhs) = expr.kind {
if let ExprKind::Binary(ref cmp, lhs, rhs) = expr.kind {
if let Some((culprit, result)) = detect_absurd_comparison(cx, cmp.node, lhs, rhs) {
if !expr.span.from_expansion() {
let msg = "this comparison involving the minimum or maximum element for this \
@ -95,7 +95,7 @@ enum AbsurdComparisonResult {
}
fn is_cast_between_fixed_and_target<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> bool {
if let ExprKind::Cast(ref cast_exp, _) = expr.kind {
if let ExprKind::Cast(cast_exp, _) = expr.kind {
let precast_ty = cx.typeck_results().expr_ty(cast_exp);
let cast_ty = cx.typeck_results().expr_ty(expr);

View file

@ -71,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnConstants {
return;
}
if_chain! {
if let ExprKind::Unary(_, ref lit) = e.kind;
if let ExprKind::Unary(_, lit) = e.kind;
if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.typeck_results(), lit);
if is_true;
then {
@ -82,7 +82,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnConstants {
if assert_span.from_expansion() {
return;
}
if let Some(assert_match) = match_assert_with_message(&cx, e) {
if let Some(assert_match) = match_assert_with_message(cx, e) {
match assert_match {
// matched assert but not message
AssertKind::WithoutMessage(false) => lint_false_without_message(),
@ -113,17 +113,17 @@ enum AssertKind {
/// where `message` is any expression and `c` is a constant bool.
fn match_assert_with_message<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<AssertKind> {
if_chain! {
if let ExprKind::If(ref cond, ref then, _) = expr.kind;
if let ExprKind::Unary(UnOp::Not, ref expr) = cond.kind;
if let ExprKind::If(cond, then, _) = expr.kind;
if let ExprKind::Unary(UnOp::Not, expr) = cond.kind;
// bind the first argument of the `assert!` macro
if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.typeck_results(), expr);
// block
if let ExprKind::Block(ref block, _) = then.kind;
if let ExprKind::Block(block, _) = then.kind;
if block.stmts.is_empty();
if let Some(block_expr) = &block.expr;
// inner block is optional. unwrap it if it exists, or use the expression as is otherwise.
if let Some(begin_panic_call) = match block_expr.kind {
ExprKind::Block(ref inner_block, _) => &inner_block.expr,
ExprKind::Block(inner_block, _) => &inner_block.expr,
_ => &block.expr,
};
// function call

View file

@ -85,7 +85,7 @@ fn match_ordering_def_path(cx: &LateContext<'_>, did: DefId, orderings: &[&str])
fn check_atomic_load_store(cx: &LateContext<'_>, expr: &Expr<'_>) {
if_chain! {
if let ExprKind::MethodCall(ref method_path, _, args, _) = &expr.kind;
if let ExprKind::MethodCall(method_path, _, args, _) = &expr.kind;
let method = method_path.ident.name.as_str();
if type_is_atomic(cx, &args[0]);
if method == "load" || method == "store";
@ -120,7 +120,7 @@ fn check_atomic_load_store(cx: &LateContext<'_>, expr: &Expr<'_>) {
fn check_memory_fence(cx: &LateContext<'_>, expr: &Expr<'_>) {
if_chain! {
if let ExprKind::Call(ref func, ref args) = expr.kind;
if let ExprKind::Call(func, args) = expr.kind;
if let ExprKind::Path(ref func_qpath) = func.kind;
if let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id();
if ["fence", "compiler_fence"]
@ -152,7 +152,7 @@ fn opt_ordering_defid(cx: &LateContext<'_>, ord_arg: &Expr<'_>) -> Option<DefId>
fn check_atomic_compare_exchange(cx: &LateContext<'_>, expr: &Expr<'_>) {
if_chain! {
if let ExprKind::MethodCall(ref method_path, _, args, _) = &expr.kind;
if let ExprKind::MethodCall(method_path, _, args, _) = &expr.kind;
let method = method_path.ident.name.as_str();
if type_is_atomic(cx, &args[0]);
if method == "compare_exchange" || method == "compare_exchange_weak" || method == "fetch_update";

View file

@ -602,7 +602,7 @@ fn check_mismatched_target_os(cx: &EarlyContext<'_>, attr: &Attribute) {
if let NestedMetaItem::MetaItem(meta) = item {
match &meta.kind {
MetaItemKind::List(list) => {
mismatched.extend(find_mismatched_target_os(&list));
mismatched.extend(find_mismatched_target_os(list));
},
MetaItemKind::Word => {
if_chain! {
@ -629,7 +629,7 @@ fn check_mismatched_target_os(cx: &EarlyContext<'_>, attr: &Attribute) {
then {
let mess = "operating system used in target family position";
span_lint_and_then(cx, MISMATCHED_TARGET_OS, attr.span, &mess, |diag| {
span_lint_and_then(cx, MISMATCHED_TARGET_OS, attr.span, mess, |diag| {
// Avoid showing the unix suggestion multiple times in case
// we have more than one mismatch for unix-like systems
let mut unix_suggested = false;

View file

@ -101,7 +101,7 @@ impl LateLintPass<'_> for AwaitHolding {
let typeck_results = cx.tcx.typeck_body(body_id);
check_interior_types(
cx,
&typeck_results.generator_interior_types.as_ref().skip_binder(),
typeck_results.generator_interior_types.as_ref().skip_binder(),
body.value.span,
);
}

View file

@ -38,17 +38,17 @@ declare_lint_pass!(ByteCount => [NAIVE_BYTECOUNT]);
impl<'tcx> LateLintPass<'tcx> for ByteCount {
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
if_chain! {
if let ExprKind::MethodCall(ref count, _, ref count_args, _) = expr.kind;
if let ExprKind::MethodCall(count, _, count_args, _) = expr.kind;
if count.ident.name == sym!(count);
if count_args.len() == 1;
if let ExprKind::MethodCall(ref filter, _, ref filter_args, _) = count_args[0].kind;
if let ExprKind::MethodCall(filter, _, filter_args, _) = count_args[0].kind;
if filter.ident.name == sym!(filter);
if filter_args.len() == 2;
if let ExprKind::Closure(_, _, body_id, _, _) = filter_args[1].kind;
let body = cx.tcx.hir().body(body_id);
if body.params.len() == 1;
if let Some(argname) = get_pat_name(&body.params[0].pat);
if let ExprKind::Binary(ref op, ref l, ref r) = body.value.kind;
if let Some(argname) = get_pat_name(body.params[0].pat);
if let ExprKind::Binary(ref op, l, r) = body.value.kind;
if op.node == BinOpKind::Eq;
if match_type(cx,
cx.typeck_results().expr_ty(&filter_args[0]).peel_refs(),
@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for ByteCount {
if ty::Uint(UintTy::U8) != *cx.typeck_results().expr_ty(needle).peel_refs().kind() {
return;
}
let haystack = if let ExprKind::MethodCall(ref path, _, ref args, _) =
let haystack = if let ExprKind::MethodCall(path, _, args, _) =
filter_args[0].kind {
let p = path.ident.name;
if (p == sym::iter || p == sym!(iter_mut)) && args.len() == 1 {
@ -98,10 +98,10 @@ fn check_arg(name: Symbol, arg: Symbol, needle: &Expr<'_>) -> bool {
fn get_path_name(expr: &Expr<'_>) -> Option<Symbol> {
match expr.kind {
ExprKind::Box(ref e) | ExprKind::AddrOf(BorrowKind::Ref, _, ref e) | ExprKind::Unary(UnOp::Deref, ref e) => {
ExprKind::Box(e) | ExprKind::AddrOf(BorrowKind::Ref, _, e) | ExprKind::Unary(UnOp::Deref, e) => {
get_path_name(e)
},
ExprKind::Block(ref b, _) => {
ExprKind::Block(b, _) => {
if b.stmts.is_empty() {
b.expr.as_ref().and_then(|p| get_path_name(p))
} else {

View file

@ -10,7 +10,7 @@ use rustc_target::abi::LayoutOf;
use super::CAST_PTR_ALIGNMENT;
pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if let ExprKind::Cast(ref cast_expr, cast_to) = expr.kind {
if let ExprKind::Cast(cast_expr, cast_to) = expr.kind {
if is_hir_ty_cfg_dependant(cx, cast_to) {
return;
}

View file

@ -30,7 +30,7 @@ fn should_lint(cx: &LateContext<'_>, cast_op: &Expr<'_>, cast_from: Ty<'_>, cast
}
// Don't lint for positive constants.
let const_val = constant(cx, &cx.typeck_results(), cast_op);
let const_val = constant(cx, cx.typeck_results(), cast_op);
if_chain! {
if let Some((Constant::Int(n), _)) = const_val;
if let ty::Int(ity) = *cast_from.kind();
@ -41,14 +41,14 @@ fn should_lint(cx: &LateContext<'_>, cast_op: &Expr<'_>, cast_from: Ty<'_>, cast
}
// Don't lint for the result of methods that always return non-negative values.
if let ExprKind::MethodCall(ref path, _, _, _) = cast_op.kind {
if let ExprKind::MethodCall(path, _, _, _) = cast_op.kind {
let mut method_name = path.ident.name.as_str();
let allowed_methods = ["abs", "checked_abs", "rem_euclid", "checked_rem_euclid"];
if_chain! {
if method_name == "unwrap";
if let Some(arglist) = method_chain_args(cast_op, &["unwrap"]);
if let ExprKind::MethodCall(ref inner_path, _, _, _) = &arglist[0][0].kind;
if let ExprKind::MethodCall(inner_path, _, _, _) = &arglist[0][0].kind;
then {
method_name = inner_path.ident.name.as_str();
}

View file

@ -372,7 +372,7 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
return;
}
if let ExprKind::Cast(ref cast_expr, cast_to) = expr.kind {
if let ExprKind::Cast(cast_expr, cast_to) = expr.kind {
if is_hir_ty_cfg_dependant(cx, cast_to) {
return;
}

View file

@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for CheckedConversions {
let result = if_chain! {
if !in_external_macro(cx.sess(), item.span);
if let ExprKind::Binary(op, ref left, ref right) = &item.kind;
if let ExprKind::Binary(op, left, right) = &item.kind;
then {
match op.node {
@ -200,7 +200,7 @@ impl ConversionType {
/// Check for `expr <= (to_type::MAX as from_type)`
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 ExprKind::Binary(ref op, left, right) = &expr.kind;
if let Some((candidate, check)) = normalize_le_ge(op, left, right);
if let Some((from, to)) = get_types_from_cast(check, INTS, "max_value", "MAX");
@ -219,7 +219,7 @@ fn check_lower_bound<'tcx>(expr: &'tcx Expr<'tcx>) -> Option<Conversion<'tcx>> {
}
// First of we need a binary containing the expression & the cast
if let ExprKind::Binary(ref op, ref left, ref right) = &expr.kind {
if let ExprKind::Binary(ref op, left, right) = &expr.kind {
normalize_le_ge(op, right, left).and_then(|(l, r)| check_function(l, r))
} else {
None
@ -260,7 +260,7 @@ fn get_types_from_cast<'a>(
// or `to_type::MAX as from_type`
let call_from_cast: Option<(&Expr<'_>, &str)> = if_chain! {
// to_type::max_value(), from_type
if let ExprKind::Cast(ref limit, ref from_type) = &expr.kind;
if let ExprKind::Cast(limit, from_type) = &expr.kind;
if let TyKind::Path(ref from_type_path) = &from_type.kind;
if let Some(from_sym) = int_ty_to_sym(from_type_path);
@ -275,7 +275,7 @@ fn get_types_from_cast<'a>(
let limit_from: Option<(&Expr<'_>, &str)> = call_from_cast.or_else(|| {
if_chain! {
// `from_type::from, to_type::max_value()`
if let ExprKind::Call(ref from_func, ref args) = &expr.kind;
if let ExprKind::Call(from_func, args) = &expr.kind;
// `to_type::max_value()`
if args.len() == 1;
if let limit = &args[0];
@ -317,9 +317,9 @@ fn get_types_from_cast<'a>(
/// Gets the type which implements the called function
fn get_implementing_type<'a>(path: &QPath<'_>, candidates: &'a [&str], function: &str) -> Option<&'a str> {
if_chain! {
if let QPath::TypeRelative(ref ty, ref path) = &path;
if let QPath::TypeRelative(ty, path) = &path;
if path.ident.name.as_str() == function;
if let TyKind::Path(QPath::Resolved(None, ref tp)) = &ty.kind;
if let TyKind::Path(QPath::Resolved(None, tp)) = &ty.kind;
if let [int] = &*tp.segments;
then {
let name = &int.ident.name.as_str();
@ -333,7 +333,7 @@ fn get_implementing_type<'a>(path: &QPath<'_>, candidates: &'a [&str], function:
/// Gets the type as a string, if it is a supported integer
fn int_ty_to_sym<'tcx>(path: &QPath<'_>) -> Option<&'tcx str> {
if_chain! {
if let QPath::Resolved(_, ref path) = *path;
if let QPath::Resolved(_, path) = *path;
if let [ty] = &*path.segments;
then {
let name = &ty.ident.name.as_str();

View file

@ -152,7 +152,7 @@ impl<'tcx> Visitor<'tcx> for CcHelper {
ExprKind::If(_, _, _) => {
self.cc += 1;
},
ExprKind::Match(_, ref arms, _) => {
ExprKind::Match(_, arms, _) => {
if arms.len() > 1 {
self.cc += 1;
}

View file

@ -71,10 +71,8 @@ impl<'tcx> LateLintPass<'tcx> for ComparisonChain {
}
for cond in conds.windows(2) {
if let (
&ExprKind::Binary(ref kind1, ref lhs1, ref rhs1),
&ExprKind::Binary(ref kind2, ref lhs2, ref rhs2),
) = (&cond[0].kind, &cond[1].kind)
if let (&ExprKind::Binary(ref kind1, lhs1, rhs1), &ExprKind::Binary(ref kind2, lhs2, rhs2)) =
(&cond[0].kind, &cond[1].kind)
{
if !kind_is_cmp(kind1.node) || !kind_is_cmp(kind2.node) {
return;

View file

@ -160,7 +160,7 @@ impl<'tcx> LateLintPass<'tcx> for CopyAndPaste {
if let ExprKind::If(_, _, _) = expr.kind {
// skip ifs directly in else, it will be checked in the parent if
if let Some(&Expr {
kind: ExprKind::If(_, _, Some(ref else_expr)),
kind: ExprKind::If(_, _, Some(else_expr)),
..
}) = get_parent_expr(cx, expr)
{
@ -247,7 +247,7 @@ fn lint_same_then_else<'tcx>(
for value in &end_walker.uses {
// Well we can't move this and all prev statements. So reset
if block_defs.contains(&value) {
if block_defs.contains(value) {
moved_start = Some(index + 1);
end_walker.defs.drain().for_each(|x| {
block_defs.insert(x);
@ -555,7 +555,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UsedValueFinderVisitor<'a, 'tcx> {
}
fn visit_qpath(&mut self, qpath: &'tcx rustc_hir::QPath<'tcx>, id: HirId, _span: rustc_span::Span) {
if let rustc_hir::QPath::Resolved(_, ref path) = *qpath {
if let rustc_hir::QPath::Resolved(_, path) = *qpath {
if path.segments.len() == 1 {
if let rustc_hir::def::Res::Local(var) = self.cx.qpath_res(qpath, id) {
self.uses.insert(var);

View file

@ -33,7 +33,7 @@ declare_lint_pass!(CreateDir => [CREATE_DIR]);
impl LateLintPass<'_> for CreateDir {
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
if_chain! {
if let ExprKind::Call(ref func, ref args) = expr.kind;
if let ExprKind::Call(func, args) = expr.kind;
if let ExprKind::Path(ref path) = func.kind;
if let Some(def_id) = cx.qpath_res(path, func.hir_id).opt_def_id();
if match_def_path(cx, def_id, &paths::STD_FS_CREATE_DIR);

View file

@ -77,7 +77,7 @@ impl LateLintPass<'_> for Default {
if_chain! {
// Avoid cases already linted by `field_reassign_with_default`
if !self.reassigned_linted.contains(&expr.span);
if let ExprKind::Call(ref path, ..) = expr.kind;
if let ExprKind::Call(path, ..) = expr.kind;
if !any_parent_is_automatically_derived(cx.tcx, expr.hir_id);
if let ExprKind::Path(ref qpath) = path.kind;
if let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id();
@ -246,7 +246,7 @@ impl LateLintPass<'_> for Default {
/// Checks if the given expression is the `default` method belonging to the `Default` trait.
fn is_expr_default<'tcx>(expr: &'tcx Expr<'tcx>, cx: &LateContext<'tcx>) -> bool {
if_chain! {
if let ExprKind::Call(ref fn_expr, _) = &expr.kind;
if let ExprKind::Call(fn_expr, _) = &expr.kind;
if let ExprKind::Path(qpath) = &fn_expr.kind;
if let Res::Def(_, def_id) = cx.qpath_res(qpath, fn_expr.hir_id);
then {
@ -262,11 +262,11 @@ fn is_expr_default<'tcx>(expr: &'tcx Expr<'tcx>, cx: &LateContext<'tcx>) -> bool
fn field_reassigned_by_stmt<'tcx>(this: &Stmt<'tcx>, binding_name: Symbol) -> Option<(Ident, &'tcx Expr<'tcx>)> {
if_chain! {
// only take assignments
if let StmtKind::Semi(ref later_expr) = this.kind;
if let ExprKind::Assign(ref assign_lhs, ref assign_rhs, _) = later_expr.kind;
if let StmtKind::Semi(later_expr) = this.kind;
if let ExprKind::Assign(assign_lhs, assign_rhs, _) = later_expr.kind;
// only take assignments to fields where the left-hand side field is a field of
// the same binding as the previous statement
if let ExprKind::Field(ref binding, field_ident) = assign_lhs.kind;
if let ExprKind::Field(binding, field_ident) = assign_lhs.kind;
if let ExprKind::Path(QPath::Resolved(_, path)) = binding.kind;
if let Some(second_binding_name) = path.segments.last();
if second_binding_name.ident.name == binding_name;

View file

@ -199,7 +199,7 @@ fn check_hash_peq<'tcx>(
then {
// Look for the PartialEq implementations for `ty`
cx.tcx.for_each_relevant_impl(peq_trait_def_id, ty, |impl_id| {
let peq_is_automatically_derived = is_automatically_derived(&cx.tcx.get_attrs(impl_id));
let peq_is_automatically_derived = is_automatically_derived(cx.tcx.get_attrs(impl_id));
if peq_is_automatically_derived == hash_is_automatically_derived {
return;
@ -253,7 +253,7 @@ fn check_ord_partial_ord<'tcx>(
then {
// Look for the PartialOrd implementations for `ty`
cx.tcx.for_each_relevant_impl(partial_ord_trait_def_id, ty, |impl_id| {
let partial_ord_is_automatically_derived = is_automatically_derived(&cx.tcx.get_attrs(impl_id));
let partial_ord_is_automatically_derived = is_automatically_derived(cx.tcx.get_attrs(impl_id));
if partial_ord_is_automatically_derived == ord_is_automatically_derived {
return;

View file

@ -710,8 +710,8 @@ impl<'a, 'tcx> Visitor<'tcx> for FindPanicUnwrap<'a, 'tcx> {
// check for `begin_panic`
if_chain! {
if let ExprKind::Call(ref func_expr, _) = expr.kind;
if let ExprKind::Path(QPath::Resolved(_, ref path)) = func_expr.kind;
if let ExprKind::Call(func_expr, _) = expr.kind;
if let ExprKind::Path(QPath::Resolved(_, path)) = func_expr.kind;
if let Some(path_def_id) = path.res.opt_def_id();
if match_panic_def_id(self.cx, path_def_id);
if is_expn_of(expr.span, "unreachable").is_none();

View file

@ -47,7 +47,7 @@ impl<'tcx> DoubleComparisons {
},
_ => return,
};
if !(eq_expr_value(cx, &llhs, &rlhs) && eq_expr_value(cx, &lrhs, &rrhs)) {
if !(eq_expr_value(cx, llhs, rlhs) && eq_expr_value(cx, lrhs, rrhs)) {
return;
}
macro_rules! lint_double_comparison {
@ -88,7 +88,7 @@ impl<'tcx> DoubleComparisons {
impl<'tcx> LateLintPass<'tcx> for DoubleComparisons {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if let ExprKind::Binary(ref kind, ref lhs, ref rhs) = expr.kind {
if let ExprKind::Binary(ref kind, lhs, rhs) = expr.kind {
Self::check_binop(cx, kind.node, lhs, rhs, expr.span);
}
}

View file

@ -50,7 +50,7 @@ impl EarlyLintPass for DoubleParens {
match expr.kind {
ExprKind::Paren(ref in_paren) => match in_paren.kind {
ExprKind::Paren(_) | ExprKind::Tup(_) => {
span_lint(cx, DOUBLE_PARENS, expr.span, &msg);
span_lint(cx, DOUBLE_PARENS, expr.span, msg);
},
_ => {},
},
@ -58,7 +58,7 @@ impl EarlyLintPass for DoubleParens {
if params.len() == 1 {
let param = &params[0];
if let ExprKind::Paren(_) = param.kind {
span_lint(cx, DOUBLE_PARENS, param.span, &msg);
span_lint(cx, DOUBLE_PARENS, param.span, msg);
}
}
},
@ -66,7 +66,7 @@ impl EarlyLintPass for DoubleParens {
if params.len() == 2 {
let param = &params[1];
if let ExprKind::Paren(_) = param.kind {
span_lint(cx, DOUBLE_PARENS, param.span, &msg);
span_lint(cx, DOUBLE_PARENS, param.span, msg);
}
}
},

View file

@ -113,7 +113,7 @@ declare_lint_pass!(DropForgetRef => [DROP_REF, FORGET_REF, DROP_COPY, FORGET_COP
impl<'tcx> LateLintPass<'tcx> for DropForgetRef {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if_chain! {
if let ExprKind::Call(ref path, ref args) = expr.kind;
if let ExprKind::Call(path, args) = expr.kind;
if let ExprKind::Path(ref qpath) = path.kind;
if args.len() == 1;
if let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id();

View file

@ -43,8 +43,8 @@ declare_lint_pass!(DurationSubsec => [DURATION_SUBSEC]);
impl<'tcx> LateLintPass<'tcx> for DurationSubsec {
fn check_expr(&mut self, cx: &LateContext<'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;
if let ExprKind::Binary(Spanned { node: BinOpKind::Div, .. }, left, right) = expr.kind;
if let ExprKind::MethodCall(method_path, _ , args, _) = left.kind;
if match_type(cx, cx.typeck_results().expr_ty(&args[0]).peel_refs(), &paths::DURATION);
if let Some((Constant::Int(divisor), _)) = constant(cx, cx.typeck_results(), right);
then {

View file

@ -57,14 +57,14 @@ declare_lint_pass!(HashMapPass => [MAP_ENTRY]);
impl<'tcx> LateLintPass<'tcx> for HashMapPass {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if let ExprKind::If(ref check, ref then_block, ref else_block) = expr.kind {
if let ExprKind::Unary(UnOp::Not, ref check) = check.kind {
if let ExprKind::If(check, then_block, ref else_block) = expr.kind {
if let ExprKind::Unary(UnOp::Not, check) = check.kind {
if let Some((ty, map, key)) = check_cond(cx, check) {
// in case of `if !m.contains_key(&k) { m.insert(k, v); }`
// we can give a better error message
let sole_expr = {
else_block.is_none()
&& if let ExprKind::Block(ref then_block, _) = then_block.kind {
&& if let ExprKind::Block(then_block, _) = then_block.kind {
(then_block.expr.is_some() as usize) + then_block.stmts.len() == 1
} else {
true
@ -81,9 +81,9 @@ impl<'tcx> LateLintPass<'tcx> for HashMapPass {
sole_expr,
};
walk_expr(&mut visitor, &**then_block);
walk_expr(&mut visitor, then_block);
}
} else if let Some(ref else_block) = *else_block {
} else if let Some(else_block) = *else_block {
if let Some((ty, map, key)) = check_cond(cx, check) {
let mut visitor = InsertVisitor {
cx,
@ -103,10 +103,10 @@ impl<'tcx> LateLintPass<'tcx> for HashMapPass {
fn check_cond<'a>(cx: &LateContext<'_>, check: &'a Expr<'a>) -> Option<(&'static str, &'a Expr<'a>, &'a Expr<'a>)> {
if_chain! {
if let ExprKind::MethodCall(ref path, _, ref params, _) = check.kind;
if let ExprKind::MethodCall(path, _, params, _) = check.kind;
if params.len() >= 2;
if path.ident.name == sym!(contains_key);
if let ExprKind::AddrOf(BorrowKind::Ref, _, ref key) = params[1].kind;
if let ExprKind::AddrOf(BorrowKind::Ref, _, key) = params[1].kind;
then {
let map = &params[0];
let obj_ty = cx.typeck_results().expr_ty(map).peel_refs();
@ -140,7 +140,7 @@ impl<'a, 'tcx, 'b> Visitor<'tcx> for InsertVisitor<'a, 'tcx, 'b> {
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
if_chain! {
if let ExprKind::MethodCall(ref path, _, ref params, _) = expr.kind;
if let ExprKind::MethodCall(path, _, params, _) = expr.kind;
if params.len() == 3;
if path.ident.name == sym!(insert);
if get_item_name(self.cx, self.map) == get_item_name(self.cx, &params[0]);

View file

@ -65,12 +65,12 @@ const ASSERT_MACRO_NAMES: [&str; 4] = ["assert_eq", "assert_ne", "debug_assert_e
impl<'tcx> LateLintPass<'tcx> for EqOp {
#[allow(clippy::similar_names, clippy::too_many_lines)]
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
if let ExprKind::Block(ref block, _) = e.kind {
if let ExprKind::Block(block, _) = e.kind {
for stmt in block.stmts {
for amn in &ASSERT_MACRO_NAMES {
if_chain! {
if is_expn_of(stmt.span, amn).is_some();
if let StmtKind::Semi(ref matchexpr) = stmt.kind;
if let StmtKind::Semi(matchexpr) = stmt.kind;
if let Some(macro_args) = higher::extract_assert_macro_args(matchexpr);
if macro_args.len() == 2;
let (lhs, rhs) = (macro_args[0], macro_args[1]);
@ -88,12 +88,12 @@ impl<'tcx> LateLintPass<'tcx> for EqOp {
}
}
}
if let ExprKind::Binary(op, ref left, ref right) = e.kind {
if let ExprKind::Binary(op, left, right) = e.kind {
if e.span.from_expansion() {
return;
}
let macro_with_not_op = |expr_kind: &ExprKind<'_>| {
if let ExprKind::Unary(_, ref expr) = *expr_kind {
if let ExprKind::Unary(_, expr) = *expr_kind {
in_macro(expr.span)
} else {
false
@ -135,7 +135,7 @@ impl<'tcx> LateLintPass<'tcx> for EqOp {
// do not suggest to dereference literals
(&ExprKind::Lit(..), _) | (_, &ExprKind::Lit(..)) => {},
// &foo == &bar
(&ExprKind::AddrOf(BorrowKind::Ref, _, ref l), &ExprKind::AddrOf(BorrowKind::Ref, _, ref r)) => {
(&ExprKind::AddrOf(BorrowKind::Ref, _, l), &ExprKind::AddrOf(BorrowKind::Ref, _, r)) => {
let lty = cx.typeck_results().expr_ty(l);
let rty = cx.typeck_results().expr_ty(r);
let lcpy = is_copy(cx, lty);
@ -198,7 +198,7 @@ impl<'tcx> LateLintPass<'tcx> for EqOp {
}
},
// &foo == bar
(&ExprKind::AddrOf(BorrowKind::Ref, _, ref l), _) => {
(&ExprKind::AddrOf(BorrowKind::Ref, _, l), _) => {
let lty = cx.typeck_results().expr_ty(l);
let lcpy = is_copy(cx, lty);
if (requires_ref || lcpy)
@ -222,7 +222,7 @@ impl<'tcx> LateLintPass<'tcx> for EqOp {
}
},
// foo == &bar
(_, &ExprKind::AddrOf(BorrowKind::Ref, _, ref r)) => {
(_, &ExprKind::AddrOf(BorrowKind::Ref, _, r)) => {
let rty = cx.typeck_results().expr_ty(r);
let rcpy = is_copy(cx, rty);
if (requires_ref || rcpy)

View file

@ -34,7 +34,7 @@ impl<'tcx> LateLintPass<'tcx> for ErasingOp {
if e.span.from_expansion() {
return;
}
if let ExprKind::Binary(ref cmp, ref left, ref right) = e.kind {
if let ExprKind::Binary(ref cmp, left, right) = e.kind {
match cmp.node {
BinOpKind::Mul | BinOpKind::BitAnd => {
check(cx, left, e.span);

View file

@ -87,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction {
}
fn check_closure(cx: &LateContext<'_>, expr: &Expr<'_>) {
if let ExprKind::Closure(_, ref decl, eid, _, _) = expr.kind {
if let ExprKind::Closure(_, decl, eid, _, _) = expr.kind {
let body = cx.tcx.hir().body(eid);
let ex = &body.value;
@ -109,7 +109,7 @@ fn check_closure(cx: &LateContext<'_>, expr: &Expr<'_>) {
}
if_chain!(
if let ExprKind::Call(ref caller, ref args) = ex.kind;
if let ExprKind::Call(caller, args) = ex.kind;
if let ExprKind::Path(_) = caller.kind;
@ -142,7 +142,7 @@ fn check_closure(cx: &LateContext<'_>, expr: &Expr<'_>) {
);
if_chain!(
if let ExprKind::MethodCall(ref path, _, ref args, _) = ex.kind;
if let ExprKind::MethodCall(path, _, args, _) = ex.kind;
// Not the same number of arguments, there is no way the closure is the same as the function return;
if args.len() == decl.inputs.len();
@ -178,7 +178,7 @@ fn get_ufcs_type_name(cx: &LateContext<'_>, method_def_id: def_id::DefId, self_a
let actual_type_of_self = &cx.typeck_results().node_type(self_arg.hir_id);
if let Some(trait_id) = cx.tcx.trait_of_item(method_def_id) {
if match_borrow_depth(expected_type_of_self, &actual_type_of_self)
if match_borrow_depth(expected_type_of_self, actual_type_of_self)
&& implements_trait(cx, actual_type_of_self, trait_id, &[])
{
return Some(cx.tcx.def_path_str(trait_id));
@ -187,8 +187,8 @@ fn get_ufcs_type_name(cx: &LateContext<'_>, method_def_id: def_id::DefId, self_a
cx.tcx.impl_of_method(method_def_id).and_then(|_| {
//a type may implicitly implement other type's methods (e.g. Deref)
if match_types(expected_type_of_self, &actual_type_of_self) {
return Some(get_type_name(cx, &actual_type_of_self));
if match_types(expected_type_of_self, actual_type_of_self) {
return Some(get_type_name(cx, actual_type_of_self));
}
None
})
@ -196,7 +196,7 @@ fn get_ufcs_type_name(cx: &LateContext<'_>, method_def_id: def_id::DefId, self_a
fn match_borrow_depth(lhs: Ty<'_>, rhs: Ty<'_>) -> bool {
match (&lhs.kind(), &rhs.kind()) {
(ty::Ref(_, t1, mut1), ty::Ref(_, t2, mut2)) => mut1 == mut2 && match_borrow_depth(&t1, &t2),
(ty::Ref(_, t1, mut1), ty::Ref(_, t2, mut2)) => mut1 == mut2 && match_borrow_depth(t1, t2),
(l, r) => !matches!((l, r), (ty::Ref(_, _, _), _) | (_, ty::Ref(_, _, _))),
}
}
@ -218,7 +218,7 @@ fn match_types(lhs: Ty<'_>, rhs: Ty<'_>) -> bool {
fn get_type_name(cx: &LateContext<'_>, ty: Ty<'_>) -> String {
match ty.kind() {
ty::Adt(t, _) => cx.tcx.def_path_str(t.did),
ty::Ref(_, r, _) => get_type_name(cx, &r),
ty::Ref(_, r, _) => get_type_name(cx, r),
_ => ty.to_string(),
}
}
@ -230,7 +230,7 @@ fn compare_inputs(
for (closure_input, function_arg) in closure_inputs.zip(call_args) {
if let PatKind::Binding(_, _, ident, _) = closure_input.pat.kind {
// XXXManishearth Should I be checking the binding mode here?
if let ExprKind::Path(QPath::Resolved(None, ref p)) = function_arg.kind {
if let ExprKind::Path(QPath::Resolved(None, p)) = function_arg.kind {
if p.segments.len() != 1 {
// If it's a proper path, it can't be a local variable
return false;

View file

@ -71,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for EvalOrderDependence {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
// Find a write to a local variable.
match expr.kind {
ExprKind::Assign(ref lhs, ..) | ExprKind::AssignOp(_, ref lhs, _) => {
ExprKind::Assign(lhs, ..) | ExprKind::AssignOp(_, lhs, _) => {
if let Some(var) = path_to_local(lhs) {
let mut visitor = ReadVisitor {
cx,
@ -87,12 +87,12 @@ impl<'tcx> LateLintPass<'tcx> for EvalOrderDependence {
}
fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) {
match stmt.kind {
StmtKind::Local(ref local) => {
if let Local { init: Some(ref e), .. } = **local {
StmtKind::Local(local) => {
if let Local { init: Some(e), .. } = local {
DivergenceVisitor { cx }.visit_expr(e);
}
},
StmtKind::Expr(ref e) | StmtKind::Semi(ref e) => DivergenceVisitor { cx }.maybe_walk_expr(e),
StmtKind::Expr(e) | StmtKind::Semi(e) => DivergenceVisitor { cx }.maybe_walk_expr(e),
StmtKind::Item(..) => {},
}
}
@ -106,7 +106,7 @@ impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> {
fn maybe_walk_expr(&mut self, e: &'tcx Expr<'_>) {
match e.kind {
ExprKind::Closure(..) => {},
ExprKind::Match(ref e, arms, _) => {
ExprKind::Match(e, arms, _) => {
self.visit_expr(e);
for arm in arms {
if let Some(Guard::If(if_expr)) = arm.guard {
@ -130,7 +130,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> {
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, _) => {
ExprKind::Call(func, _) => {
let typ = self.cx.typeck_results().expr_ty(func);
match typ.kind() {
ty::FnDef(..) | ty::FnPtr(_) => {
@ -266,10 +266,10 @@ fn check_expr<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, expr: &'tcx Expr<'_>) -
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),
StmtKind::Expr(expr) | StmtKind::Semi(expr) => check_expr(vis, expr),
// If the declaration is of a local variable, check its initializer
// expression if it has one. Otherwise, keep going.
StmtKind::Local(ref local) => local
StmtKind::Local(local) => local
.init
.as_ref()
.map_or(StopEarly::KeepGoing, |expr| check_expr(vis, expr)),
@ -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 {
if let Some(parent) = get_parent_expr(cx, expr) {
if let ExprKind::Assign(ref lhs, ..) = parent.kind {
if let ExprKind::Assign(lhs, ..) = parent.kind {
return lhs.hir_id == expr.hir_id;
}
}

View file

@ -28,7 +28,7 @@ declare_lint_pass!(Exit => [EXIT]);
impl<'tcx> LateLintPass<'tcx> for Exit {
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
if_chain! {
if let ExprKind::Call(ref path_expr, ref _args) = e.kind;
if let ExprKind::Call(path_expr, _args) = e.kind;
if let ExprKind::Path(ref path) = path_expr.kind;
if let Some(def_id) = cx.qpath_res(path, path_expr.hir_id).opt_def_id();
if match_def_path(cx, def_id, &paths::EXIT);

View file

@ -34,11 +34,11 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitWrite {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if_chain! {
// match call to unwrap
if let ExprKind::MethodCall(ref unwrap_fun, _, ref unwrap_args, _) = expr.kind;
if let ExprKind::MethodCall(unwrap_fun, _, unwrap_args, _) = expr.kind;
if unwrap_fun.ident.name == sym::unwrap;
// match call to write_fmt
if !unwrap_args.is_empty();
if let ExprKind::MethodCall(ref write_fun, _, write_args, _) =
if let ExprKind::MethodCall(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 ()
@ -135,10 +135,10 @@ 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 let ExprKind::Call(_, output_args) = write_args[1].kind;
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;
if let ExprKind::AddrOf(BorrowKind::Ref, _, output_string_expr) = output_args[0].kind;
if let ExprKind::Array(string_exprs) = output_string_expr.kind;
// we only want to provide an automatic suggestion for simple (non-format) strings
if string_exprs.len() == 1;
if let ExprKind::Lit(ref lit) = string_exprs[0].kind;

View file

@ -81,8 +81,8 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, impl_items: &[h
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
// check for `begin_panic`
if_chain! {
if let ExprKind::Call(ref func_expr, _) = expr.kind;
if let ExprKind::Path(QPath::Resolved(_, ref path)) = func_expr.kind;
if let ExprKind::Call(func_expr, _) = expr.kind;
if let ExprKind::Path(QPath::Resolved(_, path)) = func_expr.kind;
if let Some(path_def_id) = path.res.opt_def_id();
if match_panic_def_id(self.lcx, path_def_id);
if is_expn_of(expr.span, "unreachable").is_none();

View file

@ -48,7 +48,7 @@ impl<'tcx> LateLintPass<'tcx> for FloatEqualityWithoutAbs {
let rhs;
// check if expr is a binary expression with a lt or gt operator
if let ExprKind::Binary(op, ref left, ref right) = expr.kind {
if let ExprKind::Binary(op, left, right) = expr.kind {
match op.node {
BinOpKind::Lt => {
lhs = left;
@ -88,8 +88,8 @@ impl<'tcx> LateLintPass<'tcx> for FloatEqualityWithoutAbs {
if let ty::Float(_) = t_val_r.kind();
then {
let sug_l = sugg::Sugg::hir(cx, &val_l, "..");
let sug_r = sugg::Sugg::hir(cx, &val_r, "..");
let sug_l = sugg::Sugg::hir(cx, val_l, "..");
let sug_r = sugg::Sugg::hir(cx, val_r, "..");
// format the suggestion
let suggestion = format!("{}.abs()", sugg::make_assoc(AssocOp::Subtract, &sug_l, &sug_r).maybe_par());
// spans the lint

View file

@ -131,7 +131,7 @@ fn prepare_receiver_sugg<'a>(cx: &LateContext<'_>, mut expr: &'a Expr<'a>) -> Su
let mut suggestion = Sugg::hir(cx, expr, "..");
if let ExprKind::Unary(UnOp::Neg, inner_expr) = &expr.kind {
expr = &inner_expr;
expr = inner_expr;
}
if_chain! {
@ -313,8 +313,8 @@ fn check_powi(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) {
Spanned {
node: BinOpKind::Add, ..
},
ref lhs,
ref rhs,
lhs,
rhs,
) = parent.kind
{
let other_addend = if lhs.hir_id == expr.hir_id { rhs } else { lhs };
@ -329,7 +329,7 @@ fn check_powi(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) {
"{}.mul_add({}, {})",
Sugg::hir(cx, &args[0], ".."),
Sugg::hir(cx, &args[0], ".."),
Sugg::hir(cx, &other_addend, ".."),
Sugg::hir(cx, other_addend, ".."),
),
Applicability::MachineApplicable,
);
@ -356,18 +356,18 @@ fn detect_hypot(cx: &LateContext<'_>, args: &[Expr<'_>]) -> Option<String> {
Spanned {
node: BinOpKind::Add, ..
},
ref add_lhs,
ref add_rhs,
add_lhs,
add_rhs,
) = args[0].kind
{
// check if expression of the form x * x + y * y
if_chain! {
if let ExprKind::Binary(Spanned { node: BinOpKind::Mul, .. }, ref lmul_lhs, ref lmul_rhs) = add_lhs.kind;
if let ExprKind::Binary(Spanned { node: BinOpKind::Mul, .. }, ref rmul_lhs, ref rmul_rhs) = add_rhs.kind;
if let ExprKind::Binary(Spanned { node: BinOpKind::Mul, .. }, lmul_lhs, lmul_rhs) = add_lhs.kind;
if let ExprKind::Binary(Spanned { node: BinOpKind::Mul, .. }, rmul_lhs, rmul_rhs) = add_rhs.kind;
if eq_expr_value(cx, lmul_lhs, lmul_rhs);
if eq_expr_value(cx, rmul_lhs, rmul_rhs);
then {
return Some(format!("{}.hypot({})", Sugg::hir(cx, &lmul_lhs, ".."), Sugg::hir(cx, &rmul_lhs, "..")));
return Some(format!("{}.hypot({})", Sugg::hir(cx, lmul_lhs, ".."), Sugg::hir(cx, rmul_lhs, "..")));
}
}
@ -376,13 +376,13 @@ fn detect_hypot(cx: &LateContext<'_>, args: &[Expr<'_>]) -> Option<String> {
if let ExprKind::MethodCall(
PathSegment { ident: lmethod_name, .. },
ref _lspan,
ref largs,
largs,
_
) = add_lhs.kind;
if let ExprKind::MethodCall(
PathSegment { ident: rmethod_name, .. },
ref _rspan,
ref rargs,
rargs,
_
) = add_rhs.kind;
if lmethod_name.as_str() == "powi" && rmethod_name.as_str() == "powi";
@ -416,11 +416,11 @@ fn check_hypot(cx: &LateContext<'_>, expr: &Expr<'_>, args: &[Expr<'_>]) {
// and suggest usage of `x.exp_m1() - (y - 1)` instead
fn check_expm1(cx: &LateContext<'_>, expr: &Expr<'_>) {
if_chain! {
if let ExprKind::Binary(Spanned { node: BinOpKind::Sub, .. }, ref lhs, ref rhs) = expr.kind;
if let ExprKind::Binary(Spanned { node: BinOpKind::Sub, .. }, lhs, rhs) = expr.kind;
if cx.typeck_results().expr_ty(lhs).is_floating_point();
if let Some((value, _)) = constant(cx, cx.typeck_results(), rhs);
if F32(1.0) == value || F64(1.0) == value;
if let ExprKind::MethodCall(ref path, _, ref method_args, _) = lhs.kind;
if let ExprKind::MethodCall(path, _, method_args, _) = lhs.kind;
if cx.typeck_results().expr_ty(&method_args[0]).is_floating_point();
if path.ident.name.as_str() == "exp";
then {
@ -442,7 +442,7 @@ fn check_expm1(cx: &LateContext<'_>, expr: &Expr<'_>) {
fn is_float_mul_expr<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<(&'a Expr<'a>, &'a Expr<'a>)> {
if_chain! {
if let ExprKind::Binary(Spanned { node: BinOpKind::Mul, .. }, ref lhs, ref rhs) = &expr.kind;
if let ExprKind::Binary(Spanned { node: BinOpKind::Mul, .. }, lhs, rhs) = &expr.kind;
if cx.typeck_results().expr_ty(lhs).is_floating_point();
if cx.typeck_results().expr_ty(rhs).is_floating_point();
then {
@ -604,8 +604,8 @@ fn check_custom_abs(cx: &LateContext<'_>, expr: &Expr<'_>) {
fn are_same_base_logs(cx: &LateContext<'_>, expr_a: &Expr<'_>, expr_b: &Expr<'_>) -> bool {
if_chain! {
if let ExprKind::MethodCall(PathSegment { ident: method_name_a, .. }, _, ref args_a, _) = expr_a.kind;
if let ExprKind::MethodCall(PathSegment { ident: method_name_b, .. }, _, ref args_b, _) = expr_b.kind;
if let ExprKind::MethodCall(PathSegment { ident: method_name_a, .. }, _, args_a, _) = expr_a.kind;
if let ExprKind::MethodCall(PathSegment { ident: method_name_b, .. }, _, args_b, _) = expr_b.kind;
then {
return method_name_a.as_str() == method_name_b.as_str() &&
args_a.len() == args_b.len() &&
@ -630,8 +630,8 @@ fn check_log_division(cx: &LateContext<'_>, expr: &Expr<'_>) {
rhs,
) = &expr.kind;
if are_same_base_logs(cx, lhs, rhs);
if let ExprKind::MethodCall(_, _, ref largs, _) = lhs.kind;
if let ExprKind::MethodCall(_, _, ref rargs, _) = rhs.kind;
if let ExprKind::MethodCall(_, _, largs, _) = lhs.kind;
if let ExprKind::MethodCall(_, _, rargs, _) = rhs.kind;
then {
span_lint_and_sugg(
cx,
@ -675,7 +675,7 @@ fn check_radians(cx: &LateContext<'_>, expr: &Expr<'_>) {
expr.span,
"conversion to degrees can be done more accurately",
"consider using",
format!("{}.to_degrees()", Sugg::hir(cx, &mul_lhs, "..")),
format!("{}.to_degrees()", Sugg::hir(cx, mul_lhs, "..")),
Applicability::MachineApplicable,
);
} else if
@ -688,7 +688,7 @@ fn check_radians(cx: &LateContext<'_>, expr: &Expr<'_>) {
expr.span,
"conversion to radians can be done more accurately",
"consider using",
format!("{}.to_radians()", Sugg::hir(cx, &mul_lhs, "..")),
format!("{}.to_radians()", Sugg::hir(cx, mul_lhs, "..")),
Applicability::MachineApplicable,
);
}
@ -698,7 +698,7 @@ fn check_radians(cx: &LateContext<'_>, expr: &Expr<'_>) {
impl<'tcx> LateLintPass<'tcx> for FloatingPointArithmetic {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if let ExprKind::MethodCall(ref path, _, args, _) = &expr.kind {
if let ExprKind::MethodCall(path, _, args, _) = &expr.kind {
let recv_ty = cx.typeck_results().expr_ty(&args[0]);
if recv_ty.is_floating_point() {

View file

@ -78,8 +78,8 @@ fn span_useless_format<T: LintContext>(cx: &T, span: Span, help: &str, mut sugg:
fn on_argumentv1_new<'tcx>(cx: &LateContext<'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;
if let ExprKind::AddrOf(BorrowKind::Ref, _, format_args) = expr.kind;
if let ExprKind::Array(elems) = arms[0].body.kind;
if elems.len() == 1;
if let Some(args) = match_function_call(cx, &elems[0], &paths::FMT_ARGUMENTV1_NEW);
// matches `core::fmt::Display::fmt`
@ -88,10 +88,10 @@ fn on_argumentv1_new<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, arms: &
if let Some(did) = cx.qpath_res(qpath, args[1].hir_id).opt_def_id();
if match_def_path(cx, did, &paths::DISPLAY_FMT_METHOD);
// check `(arg0,)` in match block
if let PatKind::Tuple(ref pats, None) = arms[0].pat.kind;
if let PatKind::Tuple(pats, None) = arms[0].pat.kind;
if pats.len() == 1;
then {
let ty = cx.typeck_results().pat_ty(&pats[0]).peel_refs();
let ty = cx.typeck_results().pat_ty(pats[0]).peel_refs();
if *ty.kind() != rustc_middle::ty::Str && !is_type_diagnostic_item(cx, ty, sym::string_type) {
return None;
}
@ -101,7 +101,7 @@ fn on_argumentv1_new<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, arms: &
}
} else {
let snip = snippet(cx, format_args.span, "<arg>");
if let ExprKind::MethodCall(ref path, _, _, _) = format_args.kind {
if let ExprKind::MethodCall(path, _, _, _) = format_args.kind {
if path.ident.name == sym!(to_string) {
return Some(format!("{}", snip));
}
@ -120,16 +120,16 @@ fn on_new_v1<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<Strin
if let Some(args) = match_function_call(cx, expr, &paths::FMT_ARGUMENTS_NEW_V1);
if args.len() == 2;
// Argument 1 in `new_v1()`
if let ExprKind::AddrOf(BorrowKind::Ref, _, ref arr) = args[0].kind;
if let ExprKind::Array(ref pieces) = arr.kind;
if let ExprKind::AddrOf(BorrowKind::Ref, _, arr) = args[0].kind;
if let ExprKind::Array(pieces) = arr.kind;
if pieces.len() == 1;
if let ExprKind::Lit(ref lit) = pieces[0].kind;
if let LitKind::Str(ref s, _) = lit.node;
// Argument 2 in `new_v1()`
if let ExprKind::AddrOf(BorrowKind::Ref, _, ref arg1) = args[1].kind;
if let ExprKind::Match(ref matchee, ref arms, MatchSource::Normal) = arg1.kind;
if let ExprKind::AddrOf(BorrowKind::Ref, _, arg1) = args[1].kind;
if let ExprKind::Match(matchee, arms, MatchSource::Normal) = arg1.kind;
if arms.len() == 1;
if let ExprKind::Tup(ref tup) = matchee.kind;
if let ExprKind::Tup(tup) = matchee.kind;
then {
// `format!("foo")` expansion contains `match () { () => [], }`
if tup.is_empty() {
@ -152,16 +152,16 @@ fn on_new_v1_fmt<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<S
if args.len() == 3;
if check_unformatted(&args[2]);
// Argument 1 in `new_v1_formatted()`
if let ExprKind::AddrOf(BorrowKind::Ref, _, ref arr) = args[0].kind;
if let ExprKind::Array(ref pieces) = arr.kind;
if let ExprKind::AddrOf(BorrowKind::Ref, _, arr) = args[0].kind;
if let ExprKind::Array(pieces) = arr.kind;
if pieces.len() == 1;
if let ExprKind::Lit(ref lit) = pieces[0].kind;
if let LitKind::Str(..) = lit.node;
// Argument 2 in `new_v1_formatted()`
if let ExprKind::AddrOf(BorrowKind::Ref, _, ref arg1) = args[1].kind;
if let ExprKind::Match(ref matchee, ref arms, MatchSource::Normal) = arg1.kind;
if let ExprKind::AddrOf(BorrowKind::Ref, _, arg1) = args[1].kind;
if let ExprKind::Match(matchee, arms, MatchSource::Normal) = arg1.kind;
if arms.len() == 1;
if let ExprKind::Tup(ref tup) = matchee.kind;
if let ExprKind::Tup(tup) = matchee.kind;
then {
return on_argumentv1_new(cx, &tup[0], arms);
}
@ -182,14 +182,14 @@ fn on_new_v1_fmt<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<S
/// ```
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;
if let ExprKind::AddrOf(BorrowKind::Ref, _, expr) = expr.kind;
if let ExprKind::Array(exprs) = expr.kind;
if exprs.len() == 1;
// struct `core::fmt::rt::v1::Argument`
if let ExprKind::Struct(_, ref fields, _) = exprs[0].kind;
if let ExprKind::Struct(_, fields, _) = exprs[0].kind;
if let Some(format_field) = fields.iter().find(|f| f.ident.name == sym::format);
// struct `core::fmt::rt::v1::FormatSpec`
if let ExprKind::Struct(_, ref fields, _) = format_field.expr.kind;
if let ExprKind::Struct(_, fields, _) = format_field.expr.kind;
if let Some(precision_field) = fields.iter().find(|f| f.ident.name == sym::precision);
if let ExprKind::Path(ref precision_path) = precision_field.expr.kind;
if last_path_segment(precision_path).ident.name == sym::Implied;

View file

@ -25,12 +25,12 @@ pub(super) fn check_item(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
let is_public = cx.access_levels.is_exported(item.hir_id());
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
if let Some(attr) = attr {
check_needless_must_use(cx, &sig.decl, item.hir_id(), item.span, fn_header_span, attr);
check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr);
return;
} else if is_public && !is_proc_macro(cx.sess(), attrs) && attr_by_name(attrs, "no_mangle").is_none() {
check_must_use_candidate(
cx,
&sig.decl,
sig.decl,
cx.tcx.hir().body(*body_id),
item.span,
item.hir_id(),
@ -48,11 +48,11 @@ pub(super) fn check_impl_item(cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<
let attrs = cx.tcx.hir().attrs(item.hir_id());
let attr = must_use_attr(attrs);
if let Some(attr) = attr {
check_needless_must_use(cx, &sig.decl, item.hir_id(), item.span, fn_header_span, attr);
check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr);
} else if is_public && !is_proc_macro(cx.sess(), attrs) && trait_ref_of_method(cx, item.hir_id()).is_none() {
check_must_use_candidate(
cx,
&sig.decl,
sig.decl,
cx.tcx.hir().body(*body_id),
item.span,
item.hir_id(),
@ -71,13 +71,13 @@ pub(super) fn check_trait_item(cx: &LateContext<'tcx>, item: &'tcx hir::TraitIte
let attrs = cx.tcx.hir().attrs(item.hir_id());
let attr = must_use_attr(attrs);
if let Some(attr) = attr {
check_needless_must_use(cx, &sig.decl, item.hir_id(), item.span, fn_header_span, attr);
check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr);
} else if let hir::TraitFn::Provided(eid) = *eid {
let body = cx.tcx.hir().body(eid);
if attr.is_none() && is_public && !is_proc_macro(cx.sess(), attrs) {
check_must_use_candidate(
cx,
&sig.decl,
sig.decl,
body,
item.span,
item.hir_id(),
@ -160,8 +160,8 @@ fn check_must_use_candidate<'tcx>(
fn returns_unit(decl: &hir::FnDecl<'_>) -> bool {
match decl.output {
hir::FnRetTy::DefaultReturn(_) => true,
hir::FnRetTy::Return(ref ty) => match ty.kind {
hir::TyKind::Tup(ref tys) => tys.is_empty(),
hir::FnRetTy::Return(ty) => match ty.kind {
hir::TyKind::Tup(tys) => tys.is_empty(),
hir::TyKind::Never => true,
_ => false,
},
@ -170,7 +170,7 @@ fn returns_unit(decl: &hir::FnDecl<'_>) -> bool {
fn has_mutable_arg(cx: &LateContext<'_>, body: &hir::Body<'_>) -> bool {
let mut tys = DefIdSet::default();
body.params.iter().any(|param| is_mutable_pat(cx, &param.pat, &mut tys))
body.params.iter().any(|param| is_mutable_pat(cx, param.pat, &mut tys))
}
fn is_mutable_pat(cx: &LateContext<'_>, pat: &hir::Pat<'_>, tys: &mut DefIdSet) -> bool {
@ -178,7 +178,7 @@ fn is_mutable_pat(cx: &LateContext<'_>, pat: &hir::Pat<'_>, tys: &mut DefIdSet)
return false; // ignore `_` patterns
}
if cx.tcx.has_typeck_results(pat.hir_id.owner.to_def_id()) {
is_mutable_ty(cx, &cx.tcx.typeck(pat.hir_id.owner).pat_ty(pat), pat.span, tys)
is_mutable_ty(cx, cx.tcx.typeck(pat.hir_id.owner).pat_ty(pat), pat.span, tys)
} else {
false
}
@ -190,12 +190,12 @@ fn is_mutable_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Span, tys: &m
match *ty.kind() {
// primitive types are never mutable
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str => false,
ty::Adt(ref adt, ref substs) => {
ty::Adt(adt, substs) => {
tys.insert(adt.did) && !ty.is_freeze(cx.tcx.at(span), cx.param_env)
|| KNOWN_WRAPPER_TYS.iter().any(|path| match_def_path(cx, adt.did, path))
&& substs.types().any(|ty| is_mutable_ty(cx, ty, span, tys))
},
ty::Tuple(ref substs) => substs.types().any(|ty| is_mutable_ty(cx, ty, span, tys)),
ty::Tuple(substs) => substs.types().any(|ty| is_mutable_ty(cx, ty, span, tys)),
ty::Array(ty, _) | ty::Slice(ty) => is_mutable_ty(cx, ty, span, tys),
ty::RawPtr(ty::TypeAndMut { ty, mutbl }) | ty::Ref(_, ty, mutbl) => {
mutbl == hir::Mutability::Mut || is_mutable_ty(cx, ty, span, tys)
@ -239,7 +239,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> {
tys.clear();
}
},
Assign(ref target, ..) | AssignOp(_, ref target, _) | AddrOf(_, hir::Mutability::Mut, ref target) => {
Assign(target, ..) | AssignOp(_, target, _) | AddrOf(_, hir::Mutability::Mut, target) => {
self.mutates_static |= is_mutated_static(target)
},
_ => {},
@ -257,7 +257,7 @@ fn is_mutated_static(e: &hir::Expr<'_>) -> bool {
match e.kind {
Path(QPath::Resolved(_, path)) => !matches!(path.res, Res::Local(_)),
Path(_) => true,
Field(ref inner, _) | Index(ref inner, _) => is_mutated_static(inner),
Field(inner, _) | Index(inner, _) => is_mutated_static(inner),
_ => false,
}
}

View file

@ -27,7 +27,7 @@ pub(super) fn check_fn(
pub(super) fn check_trait_item(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) {
if let hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(eid)) = item.kind {
let body = cx.tcx.hir().body(eid);
check_raw_ptr(cx, sig.header.unsafety, &sig.decl, body, item.hir_id());
check_raw_ptr(cx, sig.header.unsafety, sig.decl, body, item.hir_id());
}
}
@ -77,7 +77,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> {
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) {
match expr.kind {
hir::ExprKind::Call(ref f, args) => {
hir::ExprKind::Call(f, args) => {
let ty = self.typeck_results.expr_ty(f);
if type_is_unsafe_function(self.cx, ty) {
@ -96,7 +96,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> {
}
}
},
hir::ExprKind::Unary(hir::UnOp::Deref, ref ptr) => self.check_arg(ptr),
hir::ExprKind::Unary(hir::UnOp::Deref, ptr) => self.check_arg(ptr),
_ => (),
}

View file

@ -18,7 +18,7 @@ pub(super) fn check_item(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
let is_public = cx.access_levels.is_exported(item.hir_id());
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
if is_public {
check_result_unit_err(cx, &sig.decl, item.span, fn_header_span);
check_result_unit_err(cx, sig.decl, item.span, fn_header_span);
}
}
}
@ -28,7 +28,7 @@ pub(super) fn check_impl_item(cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<
let is_public = cx.access_levels.is_exported(item.hir_id());
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
if is_public && trait_ref_of_method(cx, item.hir_id()).is_none() {
check_result_unit_err(cx, &sig.decl, item.span, fn_header_span);
check_result_unit_err(cx, sig.decl, item.span, fn_header_span);
}
}
}
@ -38,7 +38,7 @@ pub(super) fn check_trait_item(cx: &LateContext<'tcx>, item: &'tcx hir::TraitIte
let is_public = cx.access_levels.is_exported(item.hir_id());
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
if is_public {
check_result_unit_err(cx, &sig.decl, item.span, fn_header_span);
check_result_unit_err(cx, sig.decl, item.span, fn_header_span);
}
}
}
@ -46,7 +46,7 @@ pub(super) fn check_trait_item(cx: &LateContext<'tcx>, item: &'tcx hir::TraitIte
fn check_result_unit_err(cx: &LateContext<'_>, decl: &hir::FnDecl<'_>, item_span: Span, fn_header_span: Span) {
if_chain! {
if !in_external_macro(cx.sess(), item_span);
if let hir::FnRetTy::Return(ref ty) = decl.output;
if let hir::FnRetTy::Return(ty) = decl.output;
let ty = hir_ty_to_ty(cx.tcx, ty);
if is_type_diagnostic_item(cx, ty, sym::result_type);
if let ty::Adt(_, substs) = ty.kind();

View file

@ -49,7 +49,7 @@ pub(super) fn check_trait_item(
if sig.header.abi == Abi::Rust {
check_arg_number(
cx,
&sig.decl,
sig.decl,
item.span.with_hi(sig.decl.output.span().hi()),
too_many_arguments_threshold,
);

View file

@ -51,7 +51,7 @@ impl<'tcx> LateLintPass<'tcx> for GetLastWithLen {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if_chain! {
// Is a method call
if let ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind;
if let ExprKind::MethodCall(path, _, args, _) = expr.kind;
// Method name is "get"
if path.ident.name == sym!(get);

View file

@ -35,7 +35,7 @@ impl<'tcx> LateLintPass<'tcx> for IdentityOp {
if e.span.from_expansion() {
return;
}
if let ExprKind::Binary(cmp, ref left, ref right) = e.kind {
if let ExprKind::Binary(cmp, left, right) = e.kind {
if is_allowed(cx, cmp, left, right) {
return;
}

View file

@ -55,8 +55,8 @@ impl<'tcx> LateLintPass<'tcx> for IfLetMutex {
cx,
};
if let ExprKind::Match(
ref op,
ref arms,
op,
arms,
MatchSource::IfLetDesugar {
contains_else_clause: true,
},
@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for IfLetMutex {
{
op_visit.visit_expr(op);
if op_visit.mutex_lock_called {
for arm in *arms {
for arm in arms {
arm_visit.visit_arm(arm);
}

View file

@ -44,9 +44,9 @@ declare_lint_pass!(OkIfLet => [IF_LET_SOME_RESULT]);
impl<'tcx> LateLintPass<'tcx> for OkIfLet {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if_chain! { //begin checking variables
if let ExprKind::Match(ref op, ref body, MatchSource::IfLetDesugar { .. }) = expr.kind; //test if expr is if let
if let ExprKind::MethodCall(_, ok_span, ref result_types, _) = op.kind; //check is expr.ok() has type Result<T,E>.ok(, _)
if let PatKind::TupleStruct(QPath::Resolved(_, ref x), ref y, _) = body[0].pat.kind; //get operation
if let ExprKind::Match(op, body, MatchSource::IfLetDesugar { .. }) = expr.kind; //test if expr is if let
if let ExprKind::MethodCall(_, ok_span, result_types, _) = op.kind; //check is expr.ok() has type Result<T,E>.ok(, _)
if let PatKind::TupleStruct(QPath::Resolved(_, x), y, _) = body[0].pat.kind; //get operation
if method_chain_args(op, &["ok"]).is_some(); //test to see if using ok() methoduse std::marker::Sized;
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&result_types[0]), sym::result_type);
if rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_path(x, false)) == "Some";

View file

@ -72,15 +72,15 @@ impl LateLintPass<'_> for IfThenSomeElseNone {
}
if_chain! {
if let ExprKind::If(ref cond, ref then, Some(ref els)) = expr.kind;
if let ExprKind::Block(ref then_block, _) = then.kind;
if let Some(ref then_expr) = then_block.expr;
if let ExprKind::Call(ref then_call, [then_arg]) = then_expr.kind;
if let ExprKind::If(cond, then, Some(els)) = expr.kind;
if let ExprKind::Block(then_block, _) = then.kind;
if let Some(then_expr) = then_block.expr;
if let ExprKind::Call(then_call, [then_arg]) = then_expr.kind;
if let ExprKind::Path(ref then_call_qpath) = then_call.kind;
if match_qpath(then_call_qpath, &clippy_utils::paths::OPTION_SOME);
if let ExprKind::Block(ref els_block, _) = els.kind;
if let ExprKind::Block(els_block, _) = els.kind;
if els_block.stmts.is_empty();
if let Some(ref els_expr) = els_block.expr;
if let Some(els_expr) = els_block.expr;
if let ExprKind::Path(ref els_call_qpath) = els_expr.kind;
if match_qpath(els_call_qpath, &clippy_utils::paths::OPTION_NONE);
then {

View file

@ -207,7 +207,7 @@ enum ImplicitHasherType<'tcx> {
impl<'tcx> ImplicitHasherType<'tcx> {
/// Checks that `ty` is a target type without a `BuildHasher`.
fn new(cx: &LateContext<'tcx>, hir_ty: &hir::Ty<'_>) -> Option<Self> {
if let TyKind::Path(QPath::Resolved(None, ref path)) = hir_ty.kind {
if let TyKind::Path(QPath::Resolved(None, path)) = hir_ty.kind {
let params: Vec<_> = path
.segments
.last()
@ -330,8 +330,8 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 't
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;
if let ExprKind::Call(fun, args) = e.kind;
if let ExprKind::Path(QPath::TypeRelative(ty, method)) = fun.kind;
if let TyKind::Path(QPath::Resolved(None, ty_path)) = ty.kind;
then {
if !TyS::same_type(self.target.ty(), self.maybe_typeck_results.unwrap().expr_ty(e)) {

View file

@ -100,10 +100,10 @@ fn expr_match(cx: &LateContext<'_>, expr: &Expr<'_>) {
if check_all_arms {
for arm in arms {
expr_match(cx, &arm.body);
expr_match(cx, arm.body);
}
} else {
expr_match(cx, &arms.first().expect("`if let` doesn't have a single arm").body);
expr_match(cx, arms.first().expect("`if let` doesn't have a single arm").body);
}
},
// skip if it already has a return statement

View file

@ -46,21 +46,21 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
if let ExprKind::If(cond, then, None) = &expr.kind;
// Check if the conditional expression is a binary operation
if let ExprKind::Binary(ref cond_op, ref cond_left, ref cond_right) = cond.kind;
if let ExprKind::Binary(ref cond_op, cond_left, cond_right) = cond.kind;
// Ensure that the binary operator is >, != and <
if BinOpKind::Ne == cond_op.node || BinOpKind::Gt == cond_op.node || BinOpKind::Lt == cond_op.node;
// Check if the true condition block has only one statement
if let ExprKind::Block(ref block, _) = then.kind;
if let ExprKind::Block(block, _) = then.kind;
if block.stmts.len() == 1 && block.expr.is_none();
// Check if assign operation is done
if let StmtKind::Semi(ref e) = block.stmts[0].kind;
if let StmtKind::Semi(e) = block.stmts[0].kind;
if let Some(target) = subtracts_one(cx, e);
// Extracting out the variable name
if let ExprKind::Path(QPath::Resolved(_, ref ares_path)) = target.kind;
if let ExprKind::Path(QPath::Resolved(_, ares_path)) = target.kind;
then {
// Handle symmetric conditions in the if statement
@ -104,7 +104,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
print_lint_and_sugg(cx, &var_name, expr);
};
},
ExprKind::Call(ref func, _) => {
ExprKind::Call(func, _) => {
if let ExprKind::Path(ref cond_num_path) = func.kind {
if INT_TYPES.iter().any(|int_type| match_qpath(cond_num_path, &[int_type, "min_value"])) {
print_lint_and_sugg(cx, &var_name, expr);
@ -120,7 +120,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
fn subtracts_one<'a>(cx: &LateContext<'_>, expr: &Expr<'a>) -> Option<&'a Expr<'a>> {
match expr.kind {
ExprKind::AssignOp(ref op1, ref target, ref value) => {
ExprKind::AssignOp(ref op1, target, value) => {
if_chain! {
if BinOpKind::Sub == op1.node;
// Check if literal being subtracted is one
@ -133,9 +133,9 @@ fn subtracts_one<'a>(cx: &LateContext<'_>, expr: &Expr<'a>) -> Option<&'a Expr<'
}
}
},
ExprKind::Assign(ref target, ref value, _) => {
ExprKind::Assign(target, value, _) => {
if_chain! {
if let ExprKind::Binary(ref op1, ref left1, ref right1) = value.kind;
if let ExprKind::Binary(ref op1, left1, right1) = value.kind;
if BinOpKind::Sub == op1.node;
if SpanlessEq::new(cx).eq_expr(left1, target);

View file

@ -88,7 +88,7 @@ declare_lint_pass!(IndexingSlicing => [INDEXING_SLICING, OUT_OF_BOUNDS_INDEXING]
impl<'tcx> LateLintPass<'tcx> for IndexingSlicing {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if let ExprKind::Index(ref array, ref index) = &expr.kind {
if let ExprKind::Index(array, index) = &expr.kind {
let ty = cx.typeck_results().expr_ty(array).peel_refs();
if let Some(range) = higher::range(index) {
// Ranged indexes, i.e., &x[n..m], &x[n..], &x[..n] and &x[..]

View file

@ -139,7 +139,7 @@ const HEURISTICS: [(&str, usize, Heuristic, Finiteness); 19] = [
fn is_infinite(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness {
match expr.kind {
ExprKind::MethodCall(ref method, _, ref args, _) => {
ExprKind::MethodCall(method, _, args, _) => {
for &(name, len, heuristic, cap) in &HEURISTICS {
if method.ident.name.as_str() == name && args.len() == len {
return (match heuristic {
@ -159,9 +159,9 @@ fn is_infinite(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness {
}
Finite
},
ExprKind::Block(ref block, _) => block.expr.as_ref().map_or(Finite, |e| is_infinite(cx, e)),
ExprKind::Box(ref e) | ExprKind::AddrOf(BorrowKind::Ref, _, ref e) => is_infinite(cx, e),
ExprKind::Call(ref path, _) => {
ExprKind::Block(block, _) => block.expr.as_ref().map_or(Finite, |e| is_infinite(cx, e)),
ExprKind::Box(e) | ExprKind::AddrOf(BorrowKind::Ref, _, e) => is_infinite(cx, e),
ExprKind::Call(path, _) => {
if let ExprKind::Path(ref qpath) = path.kind {
match_qpath(qpath, &paths::REPEAT).into()
} else {
@ -215,7 +215,7 @@ const INFINITE_COLLECTORS: [&[&str]; 8] = [
fn complete_infinite_iter(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness {
match expr.kind {
ExprKind::MethodCall(ref method, _, ref args, _) => {
ExprKind::MethodCall(method, _, args, _) => {
for &(name, len) in &COMPLETING_METHODS {
if method.ident.name.as_str() == name && args.len() == len {
return is_infinite(cx, &args[0]);
@ -240,7 +240,7 @@ fn complete_infinite_iter(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness {
}
}
},
ExprKind::Binary(op, ref l, ref r) => {
ExprKind::Binary(op, l, r) => {
if op.node.is_comparison() {
return is_infinite(cx, l).and(is_infinite(cx, r)).and(MaybeInfinite);
}

View file

@ -86,7 +86,7 @@ impl Ord for FullInt {
}
fn numeric_cast_precast_bounds<'a>(cx: &LateContext<'_>, expr: &'a Expr<'_>) -> Option<(FullInt, FullInt)> {
if let ExprKind::Cast(ref cast_exp, _) = expr.kind {
if let ExprKind::Cast(cast_exp, _) = expr.kind {
let pre_cast_ty = cx.typeck_results().expr_ty(cast_exp);
let cast_ty = cx.typeck_results().expr_ty(expr);
// if it's a cast from i32 to u32 wrapping will invalidate all these checks
@ -131,7 +131,7 @@ fn node_as_const_fullint<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) ->
}
fn err_upcast_comparison(cx: &LateContext<'_>, span: Span, expr: &Expr<'_>, always: bool) {
if let ExprKind::Cast(ref cast_val, _) = expr.kind {
if let ExprKind::Cast(cast_val, _) = expr.kind {
span_lint(
cx,
INVALID_UPCAST_COMPARISONS,
@ -203,7 +203,7 @@ fn upcast_comparison_bounds_err<'tcx>(
impl<'tcx> LateLintPass<'tcx> for InvalidUpcastComparisons {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if let ExprKind::Binary(ref cmp, ref lhs, ref rhs) = expr.kind {
if let ExprKind::Binary(ref cmp, lhs, rhs) = expr.kind {
let normalized = comparisons::normalize_comparison(cmp.node, lhs, rhs);
let (rel, normalized_lhs, normalized_rhs) = if let Some(val) = normalized {
val

View file

@ -113,7 +113,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant {
);
if variant.fields.len() == 1 {
let span = match def.variants[i].data {
VariantData::Struct(ref fields, ..) | VariantData::Tuple(ref fields, ..) => {
VariantData::Struct(fields, ..) | VariantData::Tuple(fields, ..) => {
fields[0].ty.span
},
VariantData::Unit(..) => unreachable!(),

View file

@ -121,7 +121,7 @@ impl<'tcx> LateLintPass<'tcx> for LenZero {
return;
}
if let ItemKind::Trait(_, _, _, _, ref trait_items) = item.kind {
if let ItemKind::Trait(_, _, _, _, trait_items) = item.kind {
check_trait_items(cx, item, trait_items);
}
}
@ -162,7 +162,7 @@ impl<'tcx> LateLintPass<'tcx> for LenZero {
return;
}
if let ExprKind::Binary(Spanned { node: cmp, .. }, ref left, ref right) = expr.kind {
if let ExprKind::Binary(Spanned { node: cmp, .. }, left, right) = expr.kind {
match cmp {
BinOpKind::Eq => {
check_cmp(cx, expr.span, left, right, "", 0); // len == 0
@ -372,8 +372,7 @@ fn check_for_is_empty(
}
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)
{
if let (&ExprKind::MethodCall(method_path, _, 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) {
if name.as_str() == "is_empty" {
@ -451,7 +450,7 @@ fn is_empty_string(expr: &Expr<'_>) -> bool {
}
fn is_empty_array(expr: &Expr<'_>) -> bool {
if let ExprKind::Array(ref arr) = expr.kind {
if let ExprKind::Array(arr) = expr.kind {
return arr.is_empty();
}
false
@ -480,17 +479,17 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
cx.tcx
.associated_items(*imp)
.in_definition_order()
.any(|item| is_is_empty(cx, &item))
.any(|item| is_is_empty(cx, item))
})
}
let ty = &cx.typeck_results().expr_ty(expr).peel_refs();
match ty.kind() {
ty::Dynamic(ref tt, ..) => tt.principal().map_or(false, |principal| {
ty::Dynamic(tt, ..) => tt.principal().map_or(false, |principal| {
cx.tcx
.associated_items(principal.def_id())
.in_definition_order()
.any(|item| is_is_empty(cx, &item))
.any(|item| is_is_empty(cx, item))
}),
ty::Projection(ref proj) => has_is_empty_impl(cx, proj.item_def_id),
ty::Adt(id, _) => has_is_empty_impl(cx, id.did),

View file

@ -61,13 +61,13 @@ impl<'tcx> LateLintPass<'tcx> for LetIfSeq {
while let Some(stmt) = it.next() {
if_chain! {
if let Some(expr) = it.peek();
if let hir::StmtKind::Local(ref local) = stmt.kind;
if let hir::StmtKind::Local(local) = stmt.kind;
if let hir::PatKind::Binding(mode, canonical_id, ident, None) = local.pat.kind;
if let hir::StmtKind::Expr(ref if_) = expr.kind;
if let hir::ExprKind::If(ref cond, ref then, ref else_) = if_.kind;
if let hir::StmtKind::Expr(if_) = expr.kind;
if let hir::ExprKind::If(cond, then, ref else_) = if_.kind;
let mut used_visitor = LocalUsedVisitor::new(cx, canonical_id);
if !used_visitor.check_expr(cond);
if let hir::ExprKind::Block(ref then, _) = then.kind;
if let hir::ExprKind::Block(then, _) = then.kind;
if let Some(value) = check_assign(cx, canonical_id, &*then);
if !used_visitor.check_expr(value);
then {
@ -79,20 +79,20 @@ impl<'tcx> LateLintPass<'tcx> for LetIfSeq {
);
if has_interior_mutability { return; }
let (default_multi_stmts, default) = if let Some(ref else_) = *else_ {
if let hir::ExprKind::Block(ref else_, _) = else_.kind {
let (default_multi_stmts, default) = if let Some(else_) = *else_ {
if let hir::ExprKind::Block(else_, _) = else_.kind {
if let Some(default) = check_assign(cx, canonical_id, else_) {
(else_.stmts.len() > 1, default)
} else if let Some(ref default) = local.init {
(true, &**default)
} else if let Some(default) = local.init {
(true, default)
} else {
continue;
}
} else {
continue;
}
} else if let Some(ref default) = local.init {
(false, &**default)
} else if let Some(default) = local.init {
(false, default)
} else {
continue;
};
@ -144,8 +144,8 @@ fn check_assign<'tcx>(
if_chain! {
if block.expr.is_none();
if let Some(expr) = block.stmts.iter().last();
if let hir::StmtKind::Semi(ref expr) = expr.kind;
if let hir::ExprKind::Assign(ref var, ref value, _) = expr.kind;
if let hir::StmtKind::Semi(expr) = expr.kind;
if let hir::ExprKind::Assign(var, value, _) = expr.kind;
if path_to_local_id(var, decl);
then {
let mut v = LocalUsedVisitor::new(cx, decl);

View file

@ -116,7 +116,7 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
if_chain! {
if let PatKind::Wild = local.pat.kind;
if let Some(ref init) = local.init;
if let Some(init) = local.init;
then {
let init_ty = cx.typeck_results().expr_ty(init);
let contains_sync_guard = init_ty.walk().any(|inner| match inner.unpack() {

File diff suppressed because it is too large Load diff

View file

@ -81,7 +81,7 @@ declare_lint_pass!(Lifetimes => [NEEDLESS_LIFETIMES, EXTRA_UNUSED_LIFETIMES]);
impl<'tcx> LateLintPass<'tcx> for Lifetimes {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
if let ItemKind::Fn(ref sig, ref generics, id) = item.kind {
check_fn_inner(cx, &sig.decl, Some(id), generics, item.span, true);
check_fn_inner(cx, sig.decl, Some(id), generics, item.span, true);
}
}
@ -90,7 +90,7 @@ impl<'tcx> LateLintPass<'tcx> for Lifetimes {
let report_extra_lifetimes = trait_ref_of_method(cx, item.hir_id()).is_none();
check_fn_inner(
cx,
&sig.decl,
sig.decl,
Some(id),
&item.generics,
item.span,
@ -105,7 +105,7 @@ impl<'tcx> LateLintPass<'tcx> for Lifetimes {
TraitFn::Required(_) => None,
TraitFn::Provided(id) => Some(id),
};
check_fn_inner(cx, &sig.decl, body, &item.generics, item.span, true);
check_fn_inner(cx, sig.decl, body, &item.generics, item.span, true);
}
}
}
@ -149,7 +149,7 @@ fn check_fn_inner<'tcx>(
.last()
.expect("a path must have at least one segment")
.args;
if let Some(ref params) = *params {
if let Some(params) = *params {
let lifetimes = params.args.iter().filter_map(|arg| match arg {
GenericArg::Lifetime(lt) => Some(lt),
_ => None,
@ -163,7 +163,7 @@ fn check_fn_inner<'tcx>(
}
}
}
if could_use_elision(cx, decl, body, &generics.params) {
if could_use_elision(cx, decl, body, generics.params) {
span_lint(
cx,
NEEDLESS_LIFETIMES,
@ -201,7 +201,7 @@ fn could_use_elision<'tcx>(
input_visitor.visit_ty(arg);
}
// extract lifetimes in output type
if let Return(ref ty) = func.output {
if let Return(ty) = func.output {
output_visitor.visit_ty(ty);
}
for lt in named_generics {
@ -416,12 +416,12 @@ fn has_where_lifetimes<'tcx>(cx: &LateContext<'tcx>, where_clause: &'tcx WhereCl
// a predicate like F: Trait or F: for<'a> Trait<'a>
let mut visitor = RefVisitor::new(cx);
// walk the type F, it may not contain LT refs
walk_ty(&mut visitor, &pred.bounded_ty);
walk_ty(&mut visitor, pred.bounded_ty);
if !visitor.all_lts().is_empty() {
return true;
}
// if the bounds define new lifetimes, they are fine to occur
let allowed_lts = allowed_lts_from(&pred.bound_generic_params);
let allowed_lts = allowed_lts_from(pred.bound_generic_params);
// now walk the bounds
for bound in pred.bounds.iter() {
walk_param_bound(&mut visitor, bound);
@ -433,8 +433,8 @@ fn has_where_lifetimes<'tcx>(cx: &LateContext<'tcx>, where_clause: &'tcx WhereCl
},
WherePredicate::EqPredicate(ref pred) => {
let mut visitor = RefVisitor::new(cx);
walk_ty(&mut visitor, &pred.lhs_ty);
walk_ty(&mut visitor, &pred.rhs_ty);
walk_ty(&mut visitor, pred.lhs_ty);
walk_ty(&mut visitor, pred.rhs_ty);
if !visitor.lts.is_empty() {
return true;
}

View file

@ -248,7 +248,7 @@ impl LiteralDigitGrouping {
fn check_lit(self, cx: &EarlyContext<'_>, lit: &Lit) {
if_chain! {
if let Some(src) = snippet_opt(cx, lit.span);
if let Some(mut num_lit) = NumericLiteral::from_lit(&src, &lit);
if let Some(mut num_lit) = NumericLiteral::from_lit(&src, lit);
then {
if !Self::check_for_mistyped_suffix(cx, lit.span, &mut num_lit) {
return;
@ -438,7 +438,7 @@ impl DecimalLiteralRepresentation {
if_chain! {
if let LitKind::Int(val, _) = lit.kind;
if let Some(src) = snippet_opt(cx, lit.span);
if let Some(num_lit) = NumericLiteral::from_lit(&src, &lit);
if let Some(num_lit) = NumericLiteral::from_lit(&src, lit);
if num_lit.radix == Radix::Decimal;
if val >= u128::from(self.threshold);
then {

View file

@ -26,7 +26,7 @@ pub(super) fn check<'tcx>(
// For each candidate, check the parent block to see if
// it's initialized to zero at the start of the loop.
if let Some(block) = get_enclosing_block(&cx, expr.hir_id) {
if let Some(block) = get_enclosing_block(cx, expr.hir_id) {
for id in increment_visitor.into_results() {
let mut initialize_visitor = InitializeVisitor::new(cx, expr, id);
walk_block(&mut initialize_visitor, block);

View file

@ -19,7 +19,7 @@ pub(super) fn check<'tcx>(
) {
let pat_span = pat.span;
if let PatKind::Tuple(ref pat, _) = pat.kind {
if let PatKind::Tuple(pat, _) = pat.kind {
if pat.len() == 2 {
let arg_span = arg.span;
let (new_pat_span, kind, ty, mutbl) = match *cx.typeck_results().expr_ty(arg).kind() {
@ -35,7 +35,7 @@ pub(super) fn check<'tcx>(
Mutability::Mut => "_mut",
};
let arg = match arg.kind {
ExprKind::AddrOf(BorrowKind::Ref, _, ref expr) => &**expr,
ExprKind::AddrOf(BorrowKind::Ref, _, expr) => expr,
_ => arg,
};

View file

@ -18,7 +18,7 @@ pub(super) fn check<'tcx>(
body: &'tcx Expr<'_>,
span: Span,
) {
if let ExprKind::Block(ref block, _) = body.kind {
if let ExprKind::Block(block, _) = body.kind {
// Ensure the `if let` statement is the only expression or statement in the for-loop
let inner_expr = if block.stmts.len() == 1 && block.expr.is_none() {
let match_stmt = &block.stmts[0];
@ -36,7 +36,7 @@ pub(super) fn check<'tcx>(
if_chain! {
if let Some(inner_expr) = inner_expr;
if let ExprKind::Match(
ref match_expr, ref match_arms, MatchSource::IfLetDesugar{ contains_else_clause: false }
match_expr, match_arms, MatchSource::IfLetDesugar{ contains_else_clause: false }
) = inner_expr.kind;
// Ensure match_expr in `if let` statement is the same as the pat from the for-loop
if let PatKind::Binding(_, pat_hir_id, _, _) = pat.kind;

View file

@ -63,8 +63,8 @@ pub(super) fn check<'tcx>(
if let ExprKind::Index(base_right, idx_right) = rhs.kind;
if is_slice_like(cx, cx.typeck_results().expr_ty(base_left));
if is_slice_like(cx, cx.typeck_results().expr_ty(base_right));
if let Some((start_left, offset_left)) = get_details_from_idx(cx, &idx_left, &starts);
if let Some((start_right, offset_right)) = get_details_from_idx(cx, &idx_right, &starts);
if let Some((start_left, offset_left)) = get_details_from_idx(cx, idx_left, &starts);
if let Some((start_right, offset_right)) = get_details_from_idx(cx, idx_right, &starts);
// Source and destination must be different
if path_to_local(base_left) != path_to_local(base_right);
@ -168,8 +168,8 @@ fn build_manual_memcpy_suggestion<'tcx>(
},
};
let (dst_offset, dst_limit) = print_offset_and_limit(&dst);
let (src_offset, src_limit) = print_offset_and_limit(&src);
let (dst_offset, dst_limit) = print_offset_and_limit(dst);
let (src_offset, src_limit) = print_offset_and_limit(src);
let dst_base_str = snippet(cx, dst.base.span, "???");
let src_base_str = snippet(cx, src.base.span, "???");
@ -435,7 +435,7 @@ fn get_loop_counters<'a, 'tcx>(
// For each candidate, check the parent block to see if
// it's initialized to zero at the start of the loop.
get_enclosing_block(&cx, expr.hir_id).and_then(|block| {
get_enclosing_block(cx, expr.hir_id).and_then(|block| {
increment_visitor
.into_results()
.filter_map(move |var_id| {

View file

@ -562,7 +562,7 @@ impl<'tcx> LateLintPass<'tcx> for Loops {
// check for `loop { if let {} else break }` that could be `while let`
// (also matches an explicit "match" instead of "if let")
// (even if the "match" or "if let" is used for declaration)
if let ExprKind::Loop(ref block, _, LoopSource::Loop, _) = expr.kind {
if let ExprKind::Loop(block, _, LoopSource::Loop, _) = expr.kind {
// also check for empty `loop {}` statements, skipping those in #[panic_handler]
empty_loop::check(cx, expr, block);
while_let_loop::check(cx, expr, block);
@ -570,7 +570,7 @@ impl<'tcx> LateLintPass<'tcx> for Loops {
while_let_on_iterator::check(cx, expr);
if let Some((cond, body)) = higher::while_loop(&expr) {
if let Some((cond, body)) = higher::while_loop(expr) {
while_immutable_condition::check(cx, cond, body);
}
@ -602,7 +602,7 @@ fn check_for_loop<'tcx>(
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 {
if let ExprKind::MethodCall(method, _, args, _) = arg.kind {
// just the receiver, no arguments
if args.len() == 1 {
let method_name = &*method.ident.as_str();

View file

@ -21,10 +21,10 @@ pub(super) fn check<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) {
}
fn check_needless_collect_direct_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) {
if_chain! {
if let ExprKind::MethodCall(ref method, _, ref args, _) = expr.kind;
if let ExprKind::MethodCall(ref chain_method, method0_span, _, _) = args[0].kind;
if let ExprKind::MethodCall(method, _, args, _) = expr.kind;
if let ExprKind::MethodCall(chain_method, method0_span, _, _) = args[0].kind;
if chain_method.ident.name == sym!(collect) && is_trait_method(cx, &args[0], sym::Iterator);
if let Some(ref generic_args) = chain_method.args;
if let Some(generic_args) = chain_method.args;
if let Some(GenericArg::Type(ref ty)) = generic_args.args.get(0);
let ty = cx.typeck_results().node_type(ty.hir_id);
if is_type_diagnostic_item(cx, ty, sym::vec_type)
@ -58,16 +58,16 @@ fn check_needless_collect_direct_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCont
}
fn check_needless_collect_indirect_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) {
if let ExprKind::Block(ref block, _) = expr.kind {
for ref stmt in block.stmts {
if let ExprKind::Block(block, _) = expr.kind {
for stmt in block.stmts {
if_chain! {
if let StmtKind::Local(
Local { pat: Pat { hir_id: pat_id, kind: PatKind::Binding(_, _, ident, .. ), .. },
init: Some(ref init_expr), .. }
init: Some(init_expr), .. }
) = stmt.kind;
if let ExprKind::MethodCall(ref method_name, collect_span, &[ref iter_source], ..) = init_expr.kind;
if method_name.ident.name == sym!(collect) && is_trait_method(cx, &init_expr, sym::Iterator);
if let Some(ref generic_args) = method_name.args;
if let ExprKind::MethodCall(method_name, collect_span, &[ref iter_source], ..) = init_expr.kind;
if method_name.ident.name == sym!(collect) && is_trait_method(cx, init_expr, sym::Iterator);
if let Some(generic_args) = method_name.args;
if let Some(GenericArg::Type(ref ty)) = generic_args.args.get(0);
if let ty = cx.typeck_results().node_type(ty.hir_id);
if is_type_diagnostic_item(cx, ty, sym::vec_type) ||
@ -165,8 +165,8 @@ impl<'tcx> Visitor<'tcx> for IterFunctionVisitor {
fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) {
// Check function calls on our collection
if_chain! {
if let ExprKind::MethodCall(method_name, _, ref args, _) = &expr.kind;
if let Some(Expr { kind: ExprKind::Path(QPath::Resolved(_, ref path)), .. }) = args.get(0);
if let ExprKind::MethodCall(method_name, _, args, _) = &expr.kind;
if let Some(Expr { kind: ExprKind::Path(QPath::Resolved(_, path)), .. }) = args.get(0);
if let &[name] = &path.segments;
if name.ident == self.target;
then {
@ -193,7 +193,7 @@ impl<'tcx> Visitor<'tcx> for IterFunctionVisitor {
}
// Check if the collection is used for anything else
if_chain! {
if let Expr { kind: ExprKind::Path(QPath::Resolved(_, ref path)), .. } = expr;
if let Expr { kind: ExprKind::Path(QPath::Resolved(_, path)), .. } = expr;
if let &[name] = &path.segments;
if name.ident == self.target;
then {

View file

@ -96,7 +96,7 @@ pub(super) fn check<'tcx>(
let take = if let Some(end) = *end {
let mut take_expr = end;
if let ExprKind::Binary(ref op, ref left, ref right) = end.kind {
if let ExprKind::Binary(ref op, left, right) = end.kind {
if let BinOpKind::Add = op.node {
let start_equal_left = SpanlessEq::new(cx).eq_expr(start, left);
let start_equal_right = SpanlessEq::new(cx).eq_expr(start, right);
@ -190,10 +190,10 @@ pub(super) fn check<'tcx>(
fn is_len_call(expr: &Expr<'_>, var: Symbol) -> bool {
if_chain! {
if let ExprKind::MethodCall(ref method, _, ref len_args, _) = expr.kind;
if let ExprKind::MethodCall(method, _, len_args, _) = expr.kind;
if len_args.len() == 1;
if method.ident.name == sym!(len);
if let ExprKind::Path(QPath::Resolved(_, ref path)) = len_args[0].kind;
if let ExprKind::Path(QPath::Resolved(_, path)) = len_args[0].kind;
if path.segments.len() == 1;
if path.segments[0].ident.name == var;
then {
@ -254,7 +254,7 @@ impl<'a, 'tcx> VarVisitor<'a, 'tcx> {
if_chain! {
// the indexed container is referenced by a name
if let ExprKind::Path(ref seqpath) = seqexpr.kind;
if let QPath::Resolved(None, ref seqvar) = *seqpath;
if let QPath::Resolved(None, seqvar) = *seqpath;
if seqvar.segments.len() == 1;
let index_used_directly = path_to_local_id(idx, self.var);
let indexed_indirectly = {
@ -310,7 +310,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
if_chain! {
// a range index op
if let ExprKind::MethodCall(ref meth, _, ref args, _) = expr.kind;
if let ExprKind::MethodCall(meth, _, args, _) = expr.kind;
if (meth.ident.name == sym::index && match_trait_method(self.cx, expr, &paths::INDEX))
|| (meth.ident.name == sym::index_mut && match_trait_method(self.cx, expr, &paths::INDEX_MUT));
if !self.check(&args[1], &args[0], expr);
@ -319,7 +319,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
if_chain! {
// an index op
if let ExprKind::Index(ref seqexpr, ref idx) = expr.kind;
if let ExprKind::Index(seqexpr, idx) = expr.kind;
if !self.check(idx, seqexpr, expr);
then { return }
}
@ -340,19 +340,19 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
let old = self.prefer_mutable;
match expr.kind {
ExprKind::AssignOp(_, ref lhs, ref rhs) | ExprKind::Assign(ref lhs, ref rhs, _) => {
ExprKind::AssignOp(_, lhs, rhs) | ExprKind::Assign(lhs, rhs, _) => {
self.prefer_mutable = true;
self.visit_expr(lhs);
self.prefer_mutable = false;
self.visit_expr(rhs);
},
ExprKind::AddrOf(BorrowKind::Ref, mutbl, ref expr) => {
ExprKind::AddrOf(BorrowKind::Ref, mutbl, expr) => {
if mutbl == Mutability::Mut {
self.prefer_mutable = true;
}
self.visit_expr(expr);
},
ExprKind::Call(ref f, args) => {
ExprKind::Call(f, args) => {
self.visit_expr(f);
for expr in args {
let ty = self.cx.typeck_results().expr_ty_adjusted(expr);

View file

@ -5,7 +5,7 @@ use rustc_lint::LateContext;
use std::iter::{once, Iterator};
pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if let ExprKind::Loop(ref block, _, _, _) = expr.kind {
if let ExprKind::Loop(block, _, _, _) = expr.kind {
match never_loop_block(block, expr.hir_id) {
NeverLoopResult::AlwaysBreak => span_lint(cx, NEVER_LOOP, expr.span, "this loop never actually loops"),
NeverLoopResult::MayContinueMainLoop | NeverLoopResult::Otherwise => (),
@ -76,36 +76,36 @@ fn never_loop_expr_seq<'a, T: Iterator<Item = &'a Expr<'a>>>(es: &mut T, main_lo
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_deref(),
StmtKind::Semi(e, ..) | StmtKind::Expr(e, ..) => Some(e),
StmtKind::Local(local) => local.init.as_deref(),
StmtKind::Item(..) => None,
}
}
fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult {
match expr.kind {
ExprKind::Box(ref e)
| ExprKind::Unary(_, ref e)
| ExprKind::Cast(ref e, _)
| ExprKind::Type(ref e, _)
| ExprKind::Field(ref e, _)
| ExprKind::AddrOf(_, _, ref e)
| ExprKind::Struct(_, _, Some(ref e))
| ExprKind::Repeat(ref e, _)
| ExprKind::DropTemps(ref e) => never_loop_expr(e, main_loop_id),
ExprKind::Array(ref es) | ExprKind::MethodCall(_, _, ref es, _) | ExprKind::Tup(ref es) => {
ExprKind::Box(e)
| ExprKind::Unary(_, e)
| ExprKind::Cast(e, _)
| ExprKind::Type(e, _)
| ExprKind::Field(e, _)
| ExprKind::AddrOf(_, _, e)
| ExprKind::Struct(_, _, Some(e))
| ExprKind::Repeat(e, _)
| ExprKind::DropTemps(e) => never_loop_expr(e, main_loop_id),
ExprKind::Array(es) | ExprKind::MethodCall(_, _, es, _) | ExprKind::Tup(es) => {
never_loop_expr_all(&mut es.iter(), main_loop_id)
},
ExprKind::Call(ref e, ref es) => never_loop_expr_all(&mut once(&**e).chain(es.iter()), main_loop_id),
ExprKind::Binary(_, ref e1, ref e2)
| ExprKind::Assign(ref e1, ref e2, _)
| ExprKind::AssignOp(_, ref e1, ref e2)
| ExprKind::Index(ref e1, ref e2) => never_loop_expr_all(&mut [&**e1, &**e2].iter().cloned(), main_loop_id),
ExprKind::Loop(ref b, _, _, _) => {
ExprKind::Call(e, es) => never_loop_expr_all(&mut once(e).chain(es.iter()), main_loop_id),
ExprKind::Binary(_, e1, e2)
| ExprKind::Assign(e1, e2, _)
| ExprKind::AssignOp(_, e1, e2)
| ExprKind::Index(e1, e2) => never_loop_expr_all(&mut [e1, e2].iter().cloned(), main_loop_id),
ExprKind::Loop(b, _, _, _) => {
// Break can come from the inner loop so remove them.
absorb_break(&never_loop_block(b, main_loop_id))
},
ExprKind::If(ref e, ref e2, ref e3) => {
ExprKind::If(e, e2, ref e3) => {
let e1 = never_loop_expr(e, main_loop_id);
let e2 = never_loop_expr(e2, main_loop_id);
let e3 = e3
@ -113,7 +113,7 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult {
.map_or(NeverLoopResult::Otherwise, |e| never_loop_expr(e, main_loop_id));
combine_seq(e1, combine_branches(e2, e3))
},
ExprKind::Match(ref e, ref arms, _) => {
ExprKind::Match(e, arms, _) => {
let e = never_loop_expr(e, main_loop_id);
if arms.is_empty() {
e
@ -122,7 +122,7 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult {
combine_seq(e, arms)
}
},
ExprKind::Block(ref b, _) => never_loop_block(b, main_loop_id),
ExprKind::Block(b, _) => never_loop_block(b, main_loop_id),
ExprKind::Continue(d) => {
let id = d
.target_id
@ -136,7 +136,7 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult {
ExprKind::Break(_, ref e) | ExprKind::Ret(ref e) => e.as_ref().map_or(NeverLoopResult::AlwaysBreak, |e| {
combine_seq(never_loop_expr(e, main_loop_id), NeverLoopResult::AlwaysBreak)
}),
ExprKind::InlineAsm(ref asm) => asm
ExprKind::InlineAsm(asm) => asm
.operands
.iter()
.map(|(o, _)| match o {

View file

@ -161,7 +161,7 @@ impl<'a, 'tcx> Visitor<'tcx> for SameItemPushVisitor<'a, 'tcx> {
if vec_push_option.is_none() {
// Current statement is not a push so visit inside
match &s.kind {
StmtKind::Expr(expr) | StmtKind::Semi(expr) => self.visit_expr(&expr),
StmtKind::Expr(expr) | StmtKind::Semi(expr) => self.visit_expr(expr),
_ => {},
}
} else {

View file

@ -15,12 +15,12 @@ pub(super) fn check<'tcx>(
expr: &'tcx Expr<'_>,
) {
if_chain! {
if let ExprKind::AddrOf(BorrowKind::Ref, _, ref arg_expr) = arg.kind;
if let ExprKind::AddrOf(BorrowKind::Ref, _, arg_expr) = arg.kind;
if let PatKind::Binding(.., target, _) = pat.kind;
if let ExprKind::Array([arg_expression]) = arg_expr.kind;
if let ExprKind::Path(ref list_item) = arg_expression.kind;
if let Some(list_item_name) = single_segment_path(list_item).map(|ps| ps.ident.name);
if let ExprKind::Block(ref block, _) = body.kind;
if let ExprKind::Block(block, _) = body.kind;
if !block.stmts.is_empty();
then {

View file

@ -65,7 +65,7 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> {
}
match parent.kind {
ExprKind::AssignOp(op, ref lhs, ref rhs) => {
ExprKind::AssignOp(op, lhs, rhs) => {
if lhs.hir_id == expr.hir_id {
*state = if op.node == BinOpKind::Add
&& is_integer_const(self.cx, rhs, 1)
@ -79,7 +79,7 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> {
};
}
},
ExprKind::Assign(ref lhs, _, _) if lhs.hir_id == expr.hir_id => {
ExprKind::Assign(lhs, _, _) if lhs.hir_id == expr.hir_id => {
*state = IncrementVisitorVarState::DontWarn
},
ExprKind::AddrOf(BorrowKind::Ref, mutability, _) if mutability == Mutability::Mut => {
@ -153,7 +153,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
fn visit_stmt(&mut self, stmt: &'tcx Stmt<'_>) {
// Look for declarations of the variable
if_chain! {
if let StmtKind::Local(ref local) = stmt.kind;
if let StmtKind::Local(local) = stmt.kind;
if local.pat.hir_id == self.var_id;
if let PatKind::Binding(.., ident, _) = local.pat.kind;
then {
@ -191,10 +191,10 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
if let Some(parent) = get_parent_expr(self.cx, expr) {
match parent.kind {
ExprKind::AssignOp(_, ref lhs, _) if lhs.hir_id == expr.hir_id => {
ExprKind::AssignOp(_, lhs, _) if lhs.hir_id == expr.hir_id => {
self.state = InitializeVisitorState::DontWarn;
},
ExprKind::Assign(ref lhs, ref rhs, _) if lhs.hir_id == expr.hir_id => {
ExprKind::Assign(lhs, rhs, _) if lhs.hir_id == expr.hir_id => {
self.state = if_chain! {
if self.depth == 0;
if let InitializeVisitorState::Declared(name)
@ -273,7 +273,7 @@ impl<'tcx> Visitor<'tcx> for LoopNestVisitor {
return;
}
match expr.kind {
ExprKind::Assign(ref path, _, _) | ExprKind::AssignOp(_, ref path, _) => {
ExprKind::Assign(path, _, _) | ExprKind::AssignOp(_, path, _) => {
if path_to_local_id(path, self.iterator) {
self.nesting = RuledOut;
}
@ -327,7 +327,7 @@ pub(super) fn make_iterator_snippet(cx: &LateContext<'_>, arg: &Expr<'_>, applic
// (&mut x).into_iter() ==> x.iter_mut()
match &arg.kind {
ExprKind::AddrOf(BorrowKind::Ref, mutability, arg_inner)
if has_iter_method(cx, cx.typeck_results().expr_ty(&arg_inner)).is_some() =>
if has_iter_method(cx, cx.typeck_results().expr_ty(arg_inner)).is_some() =>
{
let meth_name = match mutability {
Mutability::Mut => "iter_mut",
@ -335,7 +335,7 @@ pub(super) fn make_iterator_snippet(cx: &LateContext<'_>, arg: &Expr<'_>, applic
};
format!(
"{}.{}()",
sugg::Sugg::hir_with_applicability(cx, &arg_inner, "_", applic_ref).maybe_par(),
sugg::Sugg::hir_with_applicability(cx, arg_inner, "_", applic_ref).maybe_par(),
meth_name,
)
}

View file

@ -11,14 +11,14 @@ pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, loop_block: &'
let inner_stmt_expr = extract_expr_from_first_stmt(loop_block);
// or extract the first expression (if any) from the block
if let Some(inner) = inner_stmt_expr.or_else(|| extract_first_expr(loop_block)) {
if let ExprKind::Match(ref matchexpr, ref arms, ref source) = inner.kind {
if let ExprKind::Match(matchexpr, arms, ref source) = inner.kind {
// ensure "if let" compatible match structure
match *source {
MatchSource::Normal | MatchSource::IfLetDesugar { .. } => {
if arms.len() == 2
&& arms[0].guard.is_none()
&& arms[1].guard.is_none()
&& is_simple_break_expr(&arms[1].body)
&& is_simple_break_expr(arms[1].body)
{
if in_external_macro(cx.sess(), expr.span) {
return;
@ -57,7 +57,7 @@ fn extract_expr_from_first_stmt<'tcx>(block: &Block<'tcx>) -> Option<&'tcx Expr<
if block.stmts.is_empty() {
return None;
}
if let StmtKind::Local(ref local) = block.stmts[0].kind {
if let StmtKind::Local(local) = block.stmts[0].kind {
local.init //.map(|expr| expr)
} else {
None
@ -67,9 +67,9 @@ fn extract_expr_from_first_stmt<'tcx>(block: &Block<'tcx>) -> Option<&'tcx Expr<
/// If a block begins with an expression (with or without semicolon), return it.
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),
Some(expr) if block.stmts.is_empty() => Some(expr),
None if !block.stmts.is_empty() => match block.stmts[0].kind {
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => Some(expr),
StmtKind::Expr(expr) | StmtKind::Semi(expr) => Some(expr),
StmtKind::Local(..) | StmtKind::Item(..) => None,
},
_ => None,
@ -82,7 +82,7 @@ fn extract_first_expr<'tcx>(block: &Block<'tcx>) -> Option<&'tcx Expr<'tcx>> {
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)),
ExprKind::Block(b, _) => extract_first_expr(b).map_or(false, |subexpr| is_simple_break_expr(subexpr)),
_ => false,
}
}

View file

@ -16,12 +16,10 @@ use rustc_middle::hir::map::Map;
use rustc_span::symbol::sym;
pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if let ExprKind::Match(ref match_expr, ref arms, MatchSource::WhileLetDesugar) = expr.kind {
if let ExprKind::Match(match_expr, arms, MatchSource::WhileLetDesugar) = expr.kind {
let pat = &arms[0].pat.kind;
if let (
&PatKind::TupleStruct(ref qpath, ref pat_args, _),
&ExprKind::MethodCall(ref method_path, _, ref method_args, _),
) = (pat, &match_expr.kind)
if let (&PatKind::TupleStruct(ref qpath, pat_args, _), &ExprKind::MethodCall(method_path, _, method_args, _)) =
(pat, &match_expr.kind)
{
let iter_expr = &method_args[0];
@ -40,8 +38,8 @@ pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
&& is_trait_method(cx, match_expr, sym::Iterator)
&& lhs_constructor.ident.name == sym::Some
&& (pat_args.is_empty()
|| !is_refutable(cx, &pat_args[0])
&& !is_used_inside(cx, iter_expr, &arms[0].body)
|| !is_refutable(cx, pat_args[0])
&& !is_used_inside(cx, iter_expr, arms[0].body)
&& !is_iterator_used_after_while_let(cx, iter_expr)
&& !is_nested(cx, expr, &method_args[0]))
{

View file

@ -91,7 +91,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualStrip {
} else {
return;
};
let target_res = cx.qpath_res(&target_path, target_arg.hir_id);
let target_res = cx.qpath_res(target_path, target_arg.hir_id);
if target_res == Res::Err {
return;
};
@ -174,7 +174,7 @@ fn eq_pattern_length<'tcx>(cx: &LateContext<'tcx>, pattern: &Expr<'_>, expr: &'t
// Tests if `expr` is a `&str`.
fn is_ref_str(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
match cx.typeck_results().expr_ty_adjusted(&expr).kind() {
match cx.typeck_results().expr_ty_adjusted(expr).kind() {
ty::Ref(_, ty, _) => ty.is_str(),
_ => false,
}

View file

@ -52,7 +52,7 @@ impl<'tcx> LateLintPass<'tcx> for MapClone {
}
if_chain! {
if let hir::ExprKind::MethodCall(ref method, _, ref args, _) = e.kind;
if let hir::ExprKind::MethodCall(method, _, args, _) = e.kind;
if args.len() == 2;
if method.ident.name == sym::map;
let ty = cx.typeck_results().expr_ty(&args[0]);
@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for MapClone {
let closure_body = cx.tcx.hir().body(body_id);
let closure_expr = remove_blocks(&closure_body.value);
match closure_body.params[0].pat.kind {
hir::PatKind::Ref(ref inner, hir::Mutability::Not) => if let hir::PatKind::Binding(
hir::PatKind::Ref(inner, hir::Mutability::Not) => if let hir::PatKind::Binding(
hir::BindingAnnotation::Unannotated, .., name, None
) = inner.kind {
if ident_eq(name, closure_expr) {
@ -71,14 +71,14 @@ impl<'tcx> LateLintPass<'tcx> for MapClone {
},
hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, .., name, None) => {
match closure_expr.kind {
hir::ExprKind::Unary(hir::UnOp::Deref, ref inner) => {
hir::ExprKind::Unary(hir::UnOp::Deref, inner) => {
if ident_eq(name, inner) {
if let ty::Ref(.., Mutability::Not) = cx.typeck_results().expr_ty(inner).kind() {
lint(cx, e.span, args[0].span, true);
}
}
},
hir::ExprKind::MethodCall(ref method, _, [obj], _) => if_chain! {
hir::ExprKind::MethodCall(method, _, [obj], _) => if_chain! {
if ident_eq(name, obj) && method.ident.name == sym::clone;
if let Some(fn_id) = cx.typeck_results().type_dependent_def_id(closure_expr.hir_id);
if let Some(trait_id) = cx.tcx.trait_of_item(fn_id);
@ -109,7 +109,7 @@ impl<'tcx> LateLintPass<'tcx> for MapClone {
}
fn ident_eq(name: Ident, path: &hir::Expr<'_>) -> bool {
if let hir::ExprKind::Path(hir::QPath::Resolved(None, ref path)) = path.kind {
if let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = path.kind {
path.segments.len() == 1 && path.segments[0].ident == name
} else {
false

View file

@ -112,7 +112,7 @@ impl<'tcx> LateLintPass<'tcx> for MapErrIgnore {
}
// check if this is a method call (e.g. x.foo())
if let ExprKind::MethodCall(ref method, _t_span, ref args, _) = e.kind {
if let ExprKind::MethodCall(method, _t_span, args, _) = e.kind {
// only work if the method name is `map_err` and there are only 2 arguments (e.g. x.map_err(|_|[1]
// Enum::Variant[2]))
if method.ident.as_str() == "map_err" && args.len() == 2 {

View file

@ -61,7 +61,7 @@ impl<'tcx> LateLintPass<'tcx> for MapIdentity {
/// map(). Otherwise, returns None.
fn get_map_argument<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<&'a [Expr<'a>]> {
if_chain! {
if let ExprKind::MethodCall(ref method, _, ref args, _) = expr.kind;
if let ExprKind::MethodCall(method, _, args, _) = expr.kind;
if args.len() == 2 && method.ident.name == sym::map;
let caller_ty = cx.typeck_results().expr_ty(&args[0]);
if is_trait_method(cx, expr, sym::Iterator)
@ -80,7 +80,7 @@ fn get_map_argument<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<&'a
fn is_expr_identity_function(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
match expr.kind {
ExprKind::Closure(_, _, body_id, _, _) => is_body_identity_function(cx, cx.tcx.hir().body(body_id)),
ExprKind::Path(QPath::Resolved(_, ref path)) => match_path(path, &paths::STD_CONVERT_IDENTITY),
ExprKind::Path(QPath::Resolved(_, path)) => match_path(path, &paths::STD_CONVERT_IDENTITY),
_ => false,
}
}
@ -99,12 +99,12 @@ fn is_body_identity_function(cx: &LateContext<'_>, func: &Body<'_>) -> bool {
match body.kind {
ExprKind::Path(QPath::Resolved(None, _)) => match_expr_param(cx, body, params[0].pat),
ExprKind::Ret(Some(ref ret_val)) => match_expr_param(cx, ret_val, params[0].pat),
ExprKind::Block(ref block, _) => {
ExprKind::Ret(Some(ret_val)) => match_expr_param(cx, ret_val, params[0].pat),
ExprKind::Block(block, _) => {
if_chain! {
if block.stmts.len() == 1;
if let StmtKind::Semi(ref expr) | StmtKind::Expr(ref expr) = block.stmts[0].kind;
if let ExprKind::Ret(Some(ref ret_val)) = expr.kind;
if let StmtKind::Semi(expr) | StmtKind::Expr(expr) = block.stmts[0].kind;
if let ExprKind::Ret(Some(ret_val)) = expr.kind;
then {
match_expr_param(cx, ret_val, params[0].pat)
} else {

View file

@ -133,7 +133,7 @@ fn reduce_unit_expression<'a>(cx: &LateContext<'_>, expr: &'a hir::Expr<'_>) ->
// Calls can't be reduced any more
Some(expr.span)
},
hir::ExprKind::Block(ref block, _) => {
hir::ExprKind::Block(block, _) => {
match (block.stmts, block.expr.as_ref()) {
(&[], Some(inner_expr)) => {
// If block only contains an expression,
@ -144,8 +144,8 @@ fn reduce_unit_expression<'a>(cx: &LateContext<'_>, expr: &'a hir::Expr<'_>) ->
// If block only contains statements,
// reduce `{ X; }` to `X` or `X;`
match inner_stmt.kind {
hir::StmtKind::Local(ref local) => Some(local.span),
hir::StmtKind::Expr(ref e) => Some(e.span),
hir::StmtKind::Local(local) => Some(local.span),
hir::StmtKind::Expr(e) => Some(e.span),
hir::StmtKind::Semi(..) => Some(inner_stmt.span),
hir::StmtKind::Item(..) => None,
}
@ -169,12 +169,12 @@ fn unit_closure<'tcx>(
expr: &hir::Expr<'_>,
) -> Option<(&'tcx hir::Param<'tcx>, &'tcx hir::Expr<'tcx>)> {
if_chain! {
if let hir::ExprKind::Closure(_, ref decl, inner_expr_id, _, _) = expr.kind;
if let hir::ExprKind::Closure(_, decl, inner_expr_id, _, _) = expr.kind;
let body = cx.tcx.hir().body(inner_expr_id);
let body_expr = &body.value;
if decl.inputs.len() == 1;
if is_unit_expression(cx, body_expr);
if let Some(binding) = iter_input_pats(&decl, body).next();
if let Some(binding) = iter_input_pats(decl, body).next();
then {
return Some((binding, body_expr));
}
@ -267,7 +267,7 @@ impl<'tcx> LateLintPass<'tcx> for MapUnit {
return;
}
if let hir::StmtKind::Semi(ref expr) = stmt.kind {
if let hir::StmtKind::Semi(expr) = stmt.kind {
if let Some(arglists) = method_chain_args(expr, &["map"]) {
lint_map_unit_fn(cx, stmt, expr, arglists[0]);
}

View file

@ -51,7 +51,7 @@ impl<'tcx> LateLintPass<'tcx> for MatchOnVecItems {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
if_chain! {
if !in_external_macro(cx.sess(), expr.span);
if let ExprKind::Match(ref match_expr, _, MatchSource::Normal) = expr.kind;
if let ExprKind::Match(match_expr, _, MatchSource::Normal) = expr.kind;
if let Some(idx_expr) = is_vec_indexing(cx, match_expr);
if let ExprKind::Index(vec, idx) = idx_expr.kind;
@ -78,7 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for MatchOnVecItems {
fn is_vec_indexing<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx>> {
if_chain! {
if let ExprKind::Index(ref array, ref index) = expr.kind;
if let ExprKind::Index(array, index) = expr.kind;
if is_vector(cx, array);
if !is_full_range(cx, index);

View file

@ -589,7 +589,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches {
lint_match_arms(cx, expr);
}
if let ExprKind::Match(ref ex, ref arms, MatchSource::Normal) = expr.kind {
if let ExprKind::Match(ex, arms, MatchSource::Normal) = expr.kind {
check_single_match(cx, ex, arms, expr);
check_match_bool(cx, ex, arms, expr);
check_overlapping_arms(cx, ex, arms);
@ -604,7 +604,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches {
check_match_single_binding(cx, ex, arms, expr);
}
}
if let ExprKind::Match(ref ex, ref arms, _) = expr.kind {
if let ExprKind::Match(ex, arms, _) = expr.kind {
check_match_ref_pats(cx, ex, arms, expr);
}
}
@ -613,14 +613,14 @@ impl<'tcx> LateLintPass<'tcx> for Matches {
if_chain! {
if !in_external_macro(cx.sess(), local.span);
if !in_macro(local.span);
if let Some(ref expr) = local.init;
if let ExprKind::Match(ref target, ref arms, MatchSource::Normal) = expr.kind;
if let Some(expr) = local.init;
if let ExprKind::Match(target, arms, MatchSource::Normal) = expr.kind;
if arms.len() == 1 && arms[0].guard.is_none();
if let PatKind::TupleStruct(
QPath::Resolved(None, ref variant_name), ref args, _) = arms[0].pat.kind;
QPath::Resolved(None, variant_name), args, _) = arms[0].pat.kind;
if args.len() == 1;
if let PatKind::Binding(_, arg, ..) = strip_pat_refs(&args[0]).kind;
let body = remove_blocks(&arms[0].body);
if let PatKind::Binding(_, arg, ..) = strip_pat_refs(args[0]).kind;
let body = remove_blocks(arms[0].body);
if path_to_local_id(body, arg);
then {
@ -649,7 +649,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches {
if_chain! {
if !in_external_macro(cx.sess(), pat.span);
if !in_macro(pat.span);
if let PatKind::Struct(QPath::Resolved(_, ref path), fields, true) = pat.kind;
if let PatKind::Struct(QPath::Resolved(_, path), fields, true) = pat.kind;
if let Some(def_id) = path.res.opt_def_id();
let ty = cx.tcx.type_of(def_id);
if let ty::Adt(def, _) = ty.kind();
@ -761,7 +761,7 @@ fn report_single_match_single_pattern(
// PartialEq for different reference counts may not exist.
"&".repeat(ref_count_diff),
snippet(cx, arms[0].pat.span, ".."),
expr_block(cx, &arms[0].body, None, "..", Some(expr.span)),
expr_block(cx, arms[0].body, None, "..", Some(expr.span)),
els_str,
);
(msg, sugg)
@ -771,7 +771,7 @@ fn report_single_match_single_pattern(
"if let {} = {} {}{}",
snippet(cx, arms[0].pat.span, ".."),
snippet(cx, ex.span, ".."),
expr_block(cx, &arms[0].body, None, "..", Some(expr.span)),
expr_block(cx, arms[0].body, None, "..", Some(expr.span)),
els_str,
);
(msg, sugg)
@ -809,7 +809,7 @@ fn check_single_match_opt_like(
];
let path = match arms[1].pat.kind {
PatKind::TupleStruct(ref path, ref inner, _) => {
PatKind::TupleStruct(ref path, inner, _) => {
// Contains any non wildcard patterns (e.g., `Err(err)`)?
if !inner.iter().all(is_wild) {
return;
@ -841,7 +841,7 @@ fn check_match_bool(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr:
move |diag| {
if arms.len() == 2 {
// no guards
let exprs = if let PatKind::Lit(ref arm_bool) = arms[0].pat.kind {
let exprs = if let PatKind::Lit(arm_bool) = arms[0].pat.kind {
if let ExprKind::Lit(ref lit) = arm_bool.kind {
match lit.node {
LitKind::Bool(true) => Some((&*arms[0].body, &*arms[1].body)),
@ -917,7 +917,7 @@ fn check_wild_err_arm<'tcx>(cx: &LateContext<'tcx>, ex: &Expr<'tcx>, arms: &[Arm
let ex_ty = cx.typeck_results().expr_ty(ex).peel_refs();
if is_type_diagnostic_item(cx, ex_ty, sym::result_type) {
for arm in arms {
if let PatKind::TupleStruct(ref path, ref inner, _) = arm.pat.kind {
if let PatKind::TupleStruct(ref path, inner, _) = arm.pat.kind {
let path_str = rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_qpath(path, false));
if path_str == "Err" {
let mut matching_wild = inner.iter().any(is_wild);
@ -937,7 +937,7 @@ fn check_wild_err_arm<'tcx>(cx: &LateContext<'tcx>, ex: &Expr<'tcx>, arms: &[Arm
}
if_chain! {
if matching_wild;
if let ExprKind::Block(ref block, _) = arm.body.kind;
if let ExprKind::Block(block, _) = arm.body.kind;
if is_panic_block(block);
then {
// `Err(_)` or `Err(_e)` arm with `panic!` found
@ -1143,9 +1143,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 {
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()
},
(&Some(exp), 0, _) => is_expn_of(exp.span, "panic").is_some() && is_expn_of(exp.span, "unreachable").is_none(),
(&None, 1, Some(stmt)) => {
is_expn_of(stmt.span, "panic").is_some() && is_expn_of(stmt.span, "unreachable").is_none()
},
@ -1156,7 +1154,7 @@ fn is_panic_block(block: &Block<'_>) -> bool {
fn check_match_ref_pats(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) {
if has_only_ref_pats(arms) {
let mut suggs = Vec::with_capacity(arms.len() + 1);
let (title, msg) = if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, ref inner) = ex.kind {
let (title, msg) = if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner) = ex.kind {
let span = ex.span.source_callsite();
suggs.push((span, Sugg::hir_with_macro_callsite(cx, inner, "..").to_string()));
(
@ -1173,7 +1171,7 @@ fn check_match_ref_pats(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], e
};
suggs.extend(arms.iter().filter_map(|a| {
if let PatKind::Ref(ref refp, _) = a.pat.kind {
if let PatKind::Ref(refp, _) = a.pat.kind {
Some((a.pat.span, snippet(cx, refp.span, "..").to_string()))
} else {
None
@ -1242,7 +1240,7 @@ fn check_match_as_ref(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], exp
fn check_wild_in_or_pats(cx: &LateContext<'_>, arms: &[Arm<'_>]) {
for arm in arms {
if let PatKind::Or(ref fields) = arm.pat.kind {
if let PatKind::Or(fields) = arm.pat.kind {
// look for multiple fields in this arm that contains at least one Wild pattern
if fields.len() > 1 && fields.iter().any(is_wild) {
span_lint_and_help(
@ -1308,7 +1306,7 @@ fn find_matches_sugg(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr
// strip potential borrows (#6503), but only if the type is a reference
let mut ex_new = ex;
if let ExprKind::AddrOf(BorrowKind::Ref, .., ex_inner) = ex.kind {
if let ty::Ref(..) = cx.typeck_results().expr_ty(&ex_inner).kind() {
if let ty::Ref(..) = cx.typeck_results().expr_ty(ex_inner).kind() {
ex_new = ex_inner;
}
};
@ -1385,7 +1383,7 @@ fn check_match_single_binding<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[A
let matched_vars = ex.span;
let bind_names = arms[0].pat.span;
let match_body = remove_blocks(&arms[0].body);
let match_body = remove_blocks(arms[0].body);
let mut snippet_body = if match_body.span.from_expansion() {
Sugg::hir_with_macro_callsite(cx, match_body, "..").to_string()
} else {
@ -1396,13 +1394,13 @@ fn check_match_single_binding<'a>(cx: &LateContext<'a>, ex: &Expr<'a>, arms: &[A
match match_body.kind {
ExprKind::Block(block, _) => {
// macro + expr_ty(body) == ()
if block.span.from_expansion() && cx.typeck_results().expr_ty(&match_body).is_unit() {
if block.span.from_expansion() && cx.typeck_results().expr_ty(match_body).is_unit() {
snippet_body.push(';');
}
},
_ => {
// expr_ty(body) == ()
if cx.typeck_results().expr_ty(&match_body).is_unit() {
if cx.typeck_results().expr_ty(match_body).is_unit() {
snippet_body.push(';');
}
},
@ -1502,10 +1500,7 @@ fn opt_parent_let<'a>(cx: &LateContext<'a>, ex: &Expr<'a>) -> Option<&'a Local<'
fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>) -> Vec<SpannedRange<Constant>> {
arms.iter()
.flat_map(|arm| {
if let Arm {
ref pat, guard: None, ..
} = *arm
{
if let Arm { pat, guard: None, .. } = *arm {
if let PatKind::Range(ref lhs, ref rhs, range_end) = pat.kind {
let lhs = match lhs {
Some(lhs) => constant(cx, cx.typeck_results(), lhs)?.0,
@ -1525,7 +1520,7 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>)
});
}
if let PatKind::Lit(ref value) = pat.kind {
if let PatKind::Lit(value) = pat.kind {
let value = constant(cx, cx.typeck_results(), value)?.0;
return Some(SpannedRange {
span: pat.span,
@ -1572,8 +1567,8 @@ fn type_ranges(ranges: &[SpannedRange<Constant>]) -> TypedRanges {
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,
ExprKind::Tup(v) if v.is_empty() => true,
ExprKind::Block(b, _) if b.stmts.is_empty() && b.expr.is_none() => true,
_ => false,
}
}
@ -1586,14 +1581,14 @@ 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> {
if_chain! {
if let PatKind::TupleStruct(ref path, ref pats, _) = arm.pat.kind;
if let PatKind::TupleStruct(ref path, pats, _) = arm.pat.kind;
if pats.len() == 1 && match_qpath(path, &paths::OPTION_SOME);
if let PatKind::Binding(rb, .., ident, _) = pats[0].kind;
if rb == BindingAnnotation::Ref || rb == BindingAnnotation::RefMut;
if let ExprKind::Call(ref e, ref args) = remove_blocks(&arm.body).kind;
if let ExprKind::Call(e, args) = remove_blocks(arm.body).kind;
if let ExprKind::Path(ref some_path) = e.kind;
if match_qpath(some_path, &paths::OPTION_SOME) && args.len() == 1;
if let ExprKind::Path(QPath::Resolved(_, ref path2)) = args[0].kind;
if let ExprKind::Path(QPath::Resolved(_, path2)) = args[0].kind;
if path2.segments.len() == 1 && ident.name == path2.segments[0].ident.name;
then {
return Some(rb)
@ -1685,7 +1680,7 @@ where
(&Kind::End(a, _), &Kind::Start(b, _)) if a != Bound::Included(b) => (),
_ => {
// skip if the range `a` is completely included into the range `b`
if let Ordering::Equal | Ordering::Less = a.cmp(&b) {
if let Ordering::Equal | Ordering::Less = a.cmp(b) {
let kind_a = Kind::End(a.range().node.1, a.range());
let kind_b = Kind::End(b.range().node.1, b.range());
if let Ordering::Equal | Ordering::Greater = kind_a.cmp(&kind_b) {
@ -1737,7 +1732,7 @@ mod redundant_pattern_match {
kind = &inner.kind;
}
let good_method = match kind {
PatKind::TupleStruct(ref path, ref patterns, _) if patterns.len() == 1 => {
PatKind::TupleStruct(ref path, patterns, _) if patterns.len() == 1 => {
if let PatKind::Wild = patterns[0].kind {
if match_qpath(path, &paths::RESULT_OK) {
"is_ok()"
@ -1818,8 +1813,8 @@ mod redundant_pattern_match {
let found_good_method = match node_pair {
(
PatKind::TupleStruct(ref path_left, ref patterns_left, _),
PatKind::TupleStruct(ref path_right, ref patterns_right, _),
PatKind::TupleStruct(ref path_left, patterns_left, _),
PatKind::TupleStruct(ref path_right, patterns_right, _),
) if patterns_left.len() == 1 && patterns_right.len() == 1 => {
if let (PatKind::Wild, PatKind::Wild) = (&patterns_left[0].kind, &patterns_right[0].kind) {
find_good_method_for_match(
@ -1846,8 +1841,8 @@ mod redundant_pattern_match {
None
}
},
(PatKind::TupleStruct(ref path_left, ref patterns, _), PatKind::Path(ref path_right))
| (PatKind::Path(ref path_left), PatKind::TupleStruct(ref path_right, ref patterns, _))
(PatKind::TupleStruct(ref path_left, patterns, _), PatKind::Path(ref path_right))
| (PatKind::Path(ref path_left), PatKind::TupleStruct(ref path_right, patterns, _))
if patterns.len() == 1 =>
{
if let PatKind::Wild = patterns[0].kind {
@ -1969,10 +1964,10 @@ fn test_overlapping() {
/// Implementation of `MATCH_SAME_ARMS`.
fn lint_match_arms<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) {
if let ExprKind::Match(_, ref arms, MatchSource::Normal) = expr.kind {
if let ExprKind::Match(_, arms, MatchSource::Normal) = expr.kind {
let hash = |&(_, arm): &(usize, &Arm<'_>)| -> u64 {
let mut h = SpanlessHash::new(cx);
h.hash_expr(&arm.body);
h.hash_expr(arm.body);
h.finish()
};
@ -2008,7 +2003,7 @@ fn lint_match_arms<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) {
(min_index..=max_index).all(|index| arms[index].guard.is_none())
&& SpanlessEq::new(cx)
.expr_fallback(eq_fallback)
.eq_expr(&lhs.body, &rhs.body)
.eq_expr(lhs.body, rhs.body)
// these checks could be removed to allow unused bindings
&& bindings_eq(lhs.pat, local_map.keys().copied().collect())
&& bindings_eq(rhs.pat, local_map.values().copied().collect())

View file

@ -34,7 +34,7 @@ declare_lint_pass!(MemDiscriminant => [MEM_DISCRIMINANT_NON_ENUM]);
impl<'tcx> LateLintPass<'tcx> for MemDiscriminant {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if_chain! {
if let ExprKind::Call(ref func, ref func_args) = expr.kind;
if let ExprKind::Call(func, func_args) = expr.kind;
// is `mem::discriminant`
if let ExprKind::Path(ref func_qpath) = func.kind;
if let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id();
@ -59,7 +59,7 @@ impl<'tcx> LateLintPass<'tcx> for MemDiscriminant {
let mut derefs_needed = ptr_depth;
let mut cur_expr = param;
while derefs_needed > 0 {
if let ExprKind::AddrOf(BorrowKind::Ref, _, ref inner_expr) = cur_expr.kind {
if let ExprKind::AddrOf(BorrowKind::Ref, _, inner_expr) = cur_expr.kind {
derefs_needed -= 1;
cur_expr = inner_expr;
} else {

View file

@ -28,7 +28,7 @@ declare_lint_pass!(MemForget => [MEM_FORGET]);
impl<'tcx> LateLintPass<'tcx> for MemForget {
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
if let ExprKind::Call(ref path_expr, ref args) = e.kind {
if let ExprKind::Call(path_expr, args) = e.kind {
if let ExprKind::Path(ref qpath) = path_expr.kind {
if let Some(def_id) = cx.qpath_res(qpath, path_expr.hir_id).opt_def_id() {
if match_def_path(cx, def_id, &paths::MEM_FORGET) {

View file

@ -109,14 +109,14 @@ fn check_replace_option_with_none(cx: &LateContext<'_>, src: &Expr<'_>, dest: &E
// argument's type. All that's left is to get
// replacee's path.
let replaced_path = match dest.kind {
ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, ref replaced) => {
if let ExprKind::Path(QPath::Resolved(None, ref replaced_path)) = replaced.kind {
ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, replaced) => {
if let ExprKind::Path(QPath::Resolved(None, replaced_path)) = replaced.kind {
replaced_path
} else {
return;
}
},
ExprKind::Path(QPath::Resolved(None, ref replaced_path)) => replaced_path,
ExprKind::Path(QPath::Resolved(None, replaced_path)) => replaced_path,
_ => return,
};
@ -161,7 +161,7 @@ fn check_replace_with_uninit(cx: &LateContext<'_>, src: &Expr<'_>, dest: &Expr<'
}
if_chain! {
if let ExprKind::Call(ref repl_func, ref repl_args) = src.kind;
if let ExprKind::Call(repl_func, repl_args) = src.kind;
if repl_args.is_empty();
if let ExprKind::Path(ref repl_func_qpath) = repl_func.kind;
if let Some(repl_def_id) = cx.qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id();
@ -214,7 +214,7 @@ fn is_default_equivalent_ctor(cx: &LateContext<'_>, def_id: DefId, path: &QPath<
.iter()
.any(|symbol| is_diagnostic_assoc_item(cx, def_id, *symbol))
{
if let QPath::TypeRelative(_, ref method) = path {
if let QPath::TypeRelative(_, method) = path {
if method.ident.name == sym::new {
return true;
}
@ -226,7 +226,7 @@ fn is_default_equivalent_ctor(cx: &LateContext<'_>, def_id: DefId, path: &QPath<
fn check_replace_with_default(cx: &LateContext<'_>, src: &Expr<'_>, dest: &Expr<'_>, expr_span: Span) {
if_chain! {
if let ExprKind::Call(ref repl_func, _) = src.kind;
if let ExprKind::Call(repl_func, _) = src.kind;
if !in_external_macro(cx.tcx.sess, expr_span);
if let ExprKind::Path(ref repl_func_qpath) = repl_func.kind;
if let Some(repl_def_id) = cx.qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id();
@ -273,11 +273,11 @@ impl<'tcx> LateLintPass<'tcx> for MemReplace {
fn check_expr(&mut self, cx: &LateContext<'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;
if let ExprKind::Call(func, func_args) = expr.kind;
if let ExprKind::Path(ref func_qpath) = func.kind;
if let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id();
if match_def_path(cx, def_id, &paths::MEM_REPLACE);
if let [dest, src] = &**func_args;
if let [dest, src] = func_args;
then {
check_replace_option_with_none(cx, src, dest, expr.span);
check_replace_with_uninit(cx, src, dest, expr.span);

View file

@ -71,7 +71,7 @@ pub(crate) trait BindInsteadOfMap {
closure_args_span: Span,
) -> bool {
if_chain! {
if let hir::ExprKind::Call(ref some_expr, [inner_expr]) = closure_expr.kind;
if let hir::ExprKind::Call(some_expr, [inner_expr]) = closure_expr.kind;
if let hir::ExprKind::Path(QPath::Resolved(_, path)) = some_expr.kind;
if Self::is_variant(cx, path.res);
if !contains_return(inner_expr);
@ -107,7 +107,7 @@ pub(crate) trait BindInsteadOfMap {
let can_sugg: bool = find_all_ret_expressions(cx, closure_expr, |ret_expr| {
if_chain! {
if !in_macro(ret_expr.span);
if let hir::ExprKind::Call(ref func_path, [arg]) = ret_expr.kind;
if let hir::ExprKind::Call(func_path, [arg]) = ret_expr.kind;
if let hir::ExprKind::Path(QPath::Resolved(_, path)) = func_path.kind;
if Self::is_variant(cx, path.res);
if !contains_return(arg);

View file

@ -19,7 +19,7 @@ pub(super) fn check(
) -> bool {
if_chain! {
if let Some(args) = method_chain_args(info.chain, chain_methods);
if let hir::ExprKind::Call(ref fun, ref arg_char) = info.other.kind;
if let hir::ExprKind::Call(fun, arg_char) = info.other.kind;
if arg_char.len() == 1;
if let hir::ExprKind::Path(ref qpath) = fun.kind;
if let Some(segment) = single_segment_path(qpath);

View file

@ -100,9 +100,9 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, method_span: Spa
applicability: &mut Applicability,
) -> Vec<String> {
if_chain! {
if let hir::ExprKind::AddrOf(hir::BorrowKind::Ref, _, ref format_arg) = a.kind;
if let hir::ExprKind::Match(ref format_arg_expr, _, _) = format_arg.kind;
if let hir::ExprKind::Tup(ref format_arg_expr_tup) = format_arg_expr.kind;
if let hir::ExprKind::AddrOf(hir::BorrowKind::Ref, _, format_arg) = a.kind;
if let hir::ExprKind::Match(format_arg_expr, _, _) = format_arg.kind;
if let hir::ExprKind::Tup(format_arg_expr_tup) = format_arg_expr.kind;
then {
format_arg_expr_tup
@ -155,7 +155,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, method_span: Spa
if block.stmts.len() == 1;
if let hir::StmtKind::Local(local) = &block.stmts[0].kind;
if let Some(arg_root) = &local.init;
if let hir::ExprKind::Call(ref inner_fun, ref inner_args) = arg_root.kind;
if let hir::ExprKind::Call(inner_fun, inner_args) = arg_root.kind;
if is_expn_of(inner_fun.span, "format").is_some() && inner_args.len() == 1;
if let hir::ExprKind::Call(_, format_args) = &inner_args[0].kind;
then {

View file

@ -19,7 +19,7 @@ use super::OPTION_FILTER_MAP;
fn is_method<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, method_name: Symbol) -> bool {
match &expr.kind {
hir::ExprKind::Path(QPath::TypeRelative(_, ref mname)) => mname.ident.name == method_name,
hir::ExprKind::Path(QPath::TypeRelative(_, mname)) => mname.ident.name == method_name,
hir::ExprKind::Path(QPath::Resolved(_, segments)) => {
segments.segments.last().unwrap().ident.name == method_name
},
@ -28,7 +28,7 @@ fn is_method<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, method_name: Sy
let closure_expr = remove_blocks(&body.value);
let arg_id = body.params[0].pat.hir_id;
match closure_expr.kind {
hir::ExprKind::MethodCall(hir::PathSegment { ident, .. }, _, ref args, _) => {
hir::ExprKind::MethodCall(hir::PathSegment { ident, .. }, _, args, _) => {
if_chain! {
if ident.name == method_name;
if let hir::ExprKind::Path(path) = &args[0].kind;
@ -61,7 +61,7 @@ fn lint_filter_some_map_unwrap(
methods_span: Span,
) {
let iterator = is_trait_method(cx, expr, sym::Iterator);
let option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&filter_recv), sym::option_type);
let option = is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(filter_recv), sym::option_type);
if (iterator || option) && is_option_filter_map(cx, filter_arg, map_arg) {
let msg = "`filter` for `Some` followed by `unwrap`";
let help = "consider using `flatten` instead";

View file

@ -35,7 +35,7 @@ pub(super) fn check<'tcx>(
let body = cx.tcx.hir().body(*body_id);
if let hir::PatKind::Binding(_, _, binding_ident, _) = body.params[0].pat.kind;
if let hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) = body.value.kind;
if let hir::ExprKind::Path(hir::QPath::Resolved(_, path)) = body.value.kind;
if path.segments.len() == 1;
if path.segments[0].ident.name == binding_ident.name;

View file

@ -13,7 +13,7 @@ use clippy_utils::is_diagnostic_assoc_item;
pub fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, trait_diagnostic: Symbol) {
if_chain! {
if let ExprKind::MethodCall(method_path, _, [arg], _) = &expr.kind;
let return_type = cx.typeck_results().expr_ty(&expr);
let return_type = cx.typeck_results().expr_ty(expr);
let input_type = cx.typeck_results().expr_ty(arg).peel_refs();
if let Some(expr_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id);
if let Some(ty_name) = input_type.ty_adt_def().map(|adt_def| cx.tcx.item_name(adt_def.did));

View file

@ -27,7 +27,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, cal
if derefs_to_slice(cx, caller_expr, cx.typeck_results().expr_ty(caller_expr)).is_some() {
// caller is a Slice
if_chain! {
if let hir::ExprKind::Index(ref caller_var, ref index_expr) = &caller_expr.kind;
if let hir::ExprKind::Index(caller_var, index_expr) = &caller_expr.kind;
if let Some(higher::Range { start: Some(start_expr), end: None, limits: ast::RangeLimits::HalfOpen })
= higher::range(index_expr);
if let hir::ExprKind::Lit(ref start_lit) = &start_expr.kind;

View file

@ -1740,10 +1740,10 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
check_methods(cx, expr, self.msrv.as_ref());
match expr.kind {
hir::ExprKind::Call(ref func, ref args) => {
hir::ExprKind::Call(func, args) => {
from_iter_instead_of_collect::check(cx, expr, args, &func.kind);
},
hir::ExprKind::MethodCall(ref method_call, ref method_span, ref args, _) => {
hir::ExprKind::MethodCall(method_call, ref method_span, args, _) => {
or_fun_call::check(cx, expr, *method_span, &method_call.ident.as_str(), args);
expect_fun_call::check(cx, expr, *method_span, &method_call.ident.as_str(), args);
clone_on_copy::check(cx, expr, method_call.ident.name, args);
@ -1753,9 +1753,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
into_iter_on_ref::check(cx, expr, *method_span, method_call.ident.name, args);
single_char_pattern::check(cx, expr, method_call.ident.name, args);
},
hir::ExprKind::Binary(op, ref lhs, ref rhs)
if op.node == hir::BinOpKind::Eq || op.node == hir::BinOpKind::Ne =>
{
hir::ExprKind::Binary(op, lhs, rhs) if op.node == hir::BinOpKind::Eq || op.node == hir::BinOpKind::Ne => {
let mut info = BinaryExprInfo {
expr,
chain: lhs,
@ -1763,7 +1761,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
eq: op.node == hir::BinOpKind::Eq,
};
lint_binary_expr_with_method_call(cx, &mut info);
}
},
_ => (),
}
}
@ -1781,7 +1779,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
let implements_trait = matches!(item.kind, hir::ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }));
if_chain! {
if let hir::ImplItemKind::Fn(ref sig, id) = impl_item.kind;
if let Some(first_arg) = iter_input_pats(&sig.decl, cx.tcx.hir().body(id)).next();
if let Some(first_arg) = iter_input_pats(sig.decl, cx.tcx.hir().body(id)).next();
let method_sig = cx.tcx.fn_sig(impl_item.def_id);
let method_sig = cx.tcx.erase_late_bound_regions(method_sig);
@ -1801,7 +1799,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
method_config.output_type.matches(&sig.decl.output) &&
method_config.self_kind.matches(cx, self_ty, first_arg_ty) &&
fn_header_equals(method_config.fn_header, sig.header) &&
method_config.lifetime_param_cond(&impl_item)
method_config.lifetime_param_cond(impl_item)
{
span_lint_and_help(
cx,
@ -2272,10 +2270,10 @@ impl OutType {
let is_unit = |ty: &hir::Ty<'_>| matches!(ty.kind, hir::TyKind::Tup(&[]));
match (self, ty) {
(Self::Unit, &hir::FnRetTy::DefaultReturn(_)) => true,
(Self::Unit, &hir::FnRetTy::Return(ref ty)) if is_unit(ty) => true,
(Self::Bool, &hir::FnRetTy::Return(ref ty)) if is_bool(ty) => true,
(Self::Any, &hir::FnRetTy::Return(ref ty)) if !is_unit(ty) => true,
(Self::Ref, &hir::FnRetTy::Return(ref ty)) => matches!(ty.kind, hir::TyKind::Rptr(_, _)),
(Self::Unit, &hir::FnRetTy::Return(ty)) if is_unit(ty) => true,
(Self::Bool, &hir::FnRetTy::Return(ty)) if is_bool(ty) => true,
(Self::Any, &hir::FnRetTy::Return(ty)) if !is_unit(ty) => true,
(Self::Ref, &hir::FnRetTy::Return(ty)) => matches!(ty.kind, hir::TyKind::Rptr(_, _)),
_ => false,
}
}

View file

@ -77,10 +77,10 @@ pub(super) fn check<'tcx>(
}
}
},
hir::ExprKind::AddrOf(hir::BorrowKind::Ref, m, ref inner) if same_mutability(m) => {
hir::ExprKind::AddrOf(hir::BorrowKind::Ref, m, inner) if same_mutability(m) => {
if_chain! {
if let hir::ExprKind::Unary(hir::UnOp::Deref, ref inner1) = inner.kind;
if let hir::ExprKind::Unary(hir::UnOp::Deref, ref inner2) = inner1.kind;
if let hir::ExprKind::Unary(hir::UnOp::Deref, inner1) = inner.kind;
if let hir::ExprKind::Unary(hir::UnOp::Deref, inner2) = inner1.kind;
then {
path_to_local_id(inner2, closure_body.params[0].pat.hir_id)
} else {

View file

@ -86,7 +86,7 @@ pub(super) fn check<'tcx>(
(&paths::RESULT, true, &["or", "unwrap_or"], "else"),
];
if let hir::ExprKind::MethodCall(ref path, _, ref args, _) = &arg.kind {
if let hir::ExprKind::MethodCall(path, _, args, _) = &arg.kind {
if path.ident.as_str() == "len" {
let ty = cx.typeck_results().expr_ty(&args[0]).peel_refs();
@ -105,7 +105,7 @@ pub(super) fn check<'tcx>(
if KNOW_TYPES.iter().any(|k| k.2.contains(&name));
if is_lazyness_candidate(cx, arg);
if !contains_return(&arg);
if !contains_return(arg);
let self_ty = cx.typeck_results().expr_ty(self_expr);
@ -158,7 +158,7 @@ pub(super) fn check<'tcx>(
if args.len() == 2 {
match args[1].kind {
hir::ExprKind::Call(ref fun, ref or_args) => {
hir::ExprKind::Call(fun, or_args) => {
let or_has_args = !or_args.is_empty();
if !check_unwrap_or_default(cx, name, fun, &args[0], &args[1], or_has_args, expr.span) {
let fun_span = if or_has_args { None } else { Some(fun.span) };

View file

@ -45,7 +45,7 @@ pub(super) fn check<'tcx>(
then {
if let hir::PatKind::Ref(..) = closure_arg.pat.kind {
Some(search_snippet.replacen('&', "", 1))
} else if let PatKind::Binding(_, _, ident, _) = strip_pat_refs(&closure_arg.pat).kind {
} else if let PatKind::Binding(_, _, ident, _) = strip_pat_refs(closure_arg.pat).kind {
let name = &*ident.name.as_str();
Some(search_snippet.replace(&format!("*{}", name), name))
} else {
@ -108,8 +108,8 @@ pub(super) fn check<'tcx>(
}
};
if_chain! {
if is_string_or_str_slice(&search_recv);
if is_string_or_str_slice(&search_arg);
if is_string_or_str_slice(search_recv);
if is_string_or_str_slice(search_arg);
then {
let msg = format!("called `{}()` after calling `find()` on a string", option_check_method);
match option_check_method {

View file

@ -10,7 +10,7 @@ use super::UNINIT_ASSUMED_INIT;
/// lint for `MaybeUninit::uninit().assume_init()` (we already have the latter)
pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) {
if_chain! {
if let hir::ExprKind::Call(ref callee, ref args) = recv.kind;
if let hir::ExprKind::Call(callee, args) = recv.kind;
if args.is_empty();
if let hir::ExprKind::Path(ref path) = callee.kind;
if match_qpath(path, &paths::MEM_MAYBEUNINIT_UNINIT);
@ -28,9 +28,9 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr
fn is_maybe_uninit_ty_valid(cx: &LateContext<'_>, ty: Ty<'_>) -> bool {
match ty.kind() {
ty::Array(ref component, _) => is_maybe_uninit_ty_valid(cx, component),
ty::Tuple(ref types) => types.types().all(|ty| is_maybe_uninit_ty_valid(cx, ty)),
ty::Adt(ref adt, _) => match_def_path(cx, adt.did, &paths::MEM_MAYBEUNINIT),
ty::Array(component, _) => is_maybe_uninit_ty_valid(cx, component),
ty::Tuple(types) => types.types().all(|ty| is_maybe_uninit_ty_valid(cx, ty)),
ty::Adt(adt, _) => match_def_path(cx, adt.did, &paths::MEM_MAYBEUNINIT),
_ => false,
}
}

View file

@ -20,9 +20,9 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Expr<
let mutates_arg =
mutated_variables(&body.value, cx).map_or(true, |used_mutably| used_mutably.contains(&arg_id));
let (mut found_mapping, mut found_filtering) = check_expression(&cx, arg_id, &body.value);
let (mut found_mapping, mut found_filtering) = check_expression(cx, arg_id, &body.value);
let mut return_visitor = ReturnVisitor::new(&cx, arg_id);
let mut return_visitor = ReturnVisitor::new(cx, arg_id);
return_visitor.visit_expr(&body.value);
found_mapping |= return_visitor.found_mapping;
found_filtering |= return_visitor.found_filtering;
@ -52,7 +52,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Expr<
// returns (found_mapping, found_filtering)
fn check_expression<'tcx>(cx: &LateContext<'tcx>, arg_id: hir::HirId, expr: &'tcx hir::Expr<'_>) -> (bool, bool) {
match &expr.kind {
hir::ExprKind::Call(ref func, ref args) => {
hir::ExprKind::Call(func, args) => {
if let hir::ExprKind::Path(ref path) = func.kind {
if match_qpath(path, &paths::OPTION_SOME) {
if path_to_local_id(&args[0], arg_id) {
@ -65,22 +65,22 @@ fn check_expression<'tcx>(cx: &LateContext<'tcx>, arg_id: hir::HirId, expr: &'tc
}
(true, true)
},
hir::ExprKind::Block(ref block, _) => block
hir::ExprKind::Block(block, _) => block
.expr
.as_ref()
.map_or((false, false), |expr| check_expression(cx, arg_id, &expr)),
.map_or((false, false), |expr| check_expression(cx, arg_id, expr)),
hir::ExprKind::Match(_, arms, _) => {
let mut found_mapping = false;
let mut found_filtering = false;
for arm in *arms {
let (m, f) = check_expression(cx, arg_id, &arm.body);
let (m, f) = check_expression(cx, arg_id, arm.body);
found_mapping |= m;
found_filtering |= f;
}
(found_mapping, found_filtering)
},
// There must be an else_arm or there will be a type error
hir::ExprKind::If(_, ref if_arm, Some(ref else_arm)) => {
hir::ExprKind::If(_, if_arm, Some(else_arm)) => {
let if_check = check_expression(cx, arg_id, if_arm);
let else_check = check_expression(cx, arg_id, else_arm);
(if_check.0 | else_check.0, if_check.1 | else_check.1)

View file

@ -34,13 +34,13 @@ pub(super) fn check(
let closure_expr = remove_blocks(&closure_body.value);
// Check if the closure body is of the form `acc <op> some_expr(x)`
if let hir::ExprKind::Binary(ref bin_op, ref left_expr, ref right_expr) = closure_expr.kind;
if let hir::ExprKind::Binary(ref bin_op, left_expr, right_expr) = closure_expr.kind;
if bin_op.node == op;
// Extract the names of the two arguments to the closure
if let [param_a, param_b] = closure_body.params;
if let PatKind::Binding(_, first_arg_id, ..) = strip_pat_refs(&param_a.pat).kind;
if let PatKind::Binding(_, second_arg_id, second_arg_ident, _) = strip_pat_refs(&param_b.pat).kind;
if let PatKind::Binding(_, first_arg_id, ..) = strip_pat_refs(param_a.pat).kind;
if let PatKind::Binding(_, second_arg_id, second_arg_ident, _) = strip_pat_refs(param_b.pat).kind;
if path_to_local_id(left_expr, first_arg_id);
if replacement_has_args || path_to_local_id(right_expr, second_arg_id);

View file

@ -26,7 +26,7 @@ pub(super) fn derefs_to_slice<'tcx>(
}
}
if let hir::ExprKind::MethodCall(ref path, _, ref args, _) = expr.kind {
if let hir::ExprKind::MethodCall(path, _, args, _) = expr.kind {
if path.ident.name == sym::iter && may_slice(cx, cx.typeck_results().expr_ty(&args[0])) {
Some(&args[0])
} else {

View file

@ -8,7 +8,7 @@ use super::ZST_OFFSET;
pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) {
if_chain! {
if let ty::RawPtr(ty::TypeAndMut { ref ty, .. }) = cx.typeck_results().expr_ty(recv).kind();
if let ty::RawPtr(ty::TypeAndMut { ty, .. }) = cx.typeck_results().expr_ty(recv).kind();
if let Ok(layout) = cx.tcx.layout_of(cx.param_env.and(ty));
if layout.is_zst();
then {

View file

@ -67,7 +67,7 @@ enum MinMax {
fn min_max<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<(MinMax, Constant, &'a Expr<'a>)> {
match expr.kind {
ExprKind::Call(ref path, ref args) => {
ExprKind::Call(path, args) => {
if let ExprKind::Path(ref qpath) = path.kind {
cx.typeck_results()
.qpath_res(qpath, path.hir_id)
@ -85,7 +85,7 @@ fn min_max<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<(MinMax, Cons
None
}
},
ExprKind::MethodCall(ref path, _, ref args, _) => {
ExprKind::MethodCall(path, _, args, _) => {
if_chain! {
if let [obj, _] = args;
if cx.typeck_results().expr_ty(obj).is_floating_point() || match_trait_method(cx, expr, &paths::ORD);

View file

@ -304,9 +304,9 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints {
fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) {
if_chain! {
if !in_external_macro(cx.tcx.sess, stmt.span);
if let StmtKind::Local(ref local) = stmt.kind;
if let StmtKind::Local(local) = stmt.kind;
if let PatKind::Binding(an, .., name, None) = local.pat.kind;
if let Some(ref init) = local.init;
if let Some(init) = local.init;
if !higher::is_from_for_desugar(local);
if an == BindingAnnotation::Ref || an == BindingAnnotation::RefMut;
then {
@ -322,7 +322,7 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints {
} else {
("", sugg_init.addr())
};
let tyopt = if let Some(ref ty) = local.ty {
let tyopt = if let Some(ty) = local.ty {
format!(": &{mutopt}{ty}", mutopt=mutopt, ty=snippet(cx, ty.span, ".."))
} else {
String::new()
@ -350,8 +350,8 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints {
}
};
if_chain! {
if let StmtKind::Semi(ref expr) = stmt.kind;
if let ExprKind::Binary(ref binop, ref a, ref b) = expr.kind;
if let StmtKind::Semi(expr) = stmt.kind;
if let ExprKind::Binary(ref binop, a, b) = expr.kind;
if binop.node == BinOpKind::And || binop.node == BinOpKind::Or;
if let Some(sugg) = Sugg::hir_opt(cx, a);
then {
@ -378,11 +378,11 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
match expr.kind {
ExprKind::Cast(ref e, ref ty) => {
ExprKind::Cast(e, ty) => {
check_cast(cx, expr.span, e, ty);
return;
},
ExprKind::Binary(ref cmp, ref left, ref right) => {
ExprKind::Binary(ref cmp, left, right) => {
check_binary(cx, expr, cmp, left, right);
return;
},
@ -501,12 +501,12 @@ fn is_allowed<'tcx>(cx: &LateContext<'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 {
// The negation of a signum is still a signum
if let ExprKind::Unary(UnOp::Neg, ref child_expr) = expr.kind {
return is_signum(cx, &child_expr);
if let ExprKind::Unary(UnOp::Neg, child_expr) = expr.kind {
return is_signum(cx, child_expr);
}
if_chain! {
if let ExprKind::MethodCall(ref method_name, _, ref expressions, _) = expr.kind;
if let ExprKind::MethodCall(method_name, _, expressions, _) = expr.kind;
if sym!(signum) == method_name.ident.name;
// Check that the receiver of the signum() is a float (expressions[0] is the receiver of
// the method call)
@ -552,7 +552,7 @@ fn check_to_owned(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left:
}
let (arg_ty, snip) = match expr.kind {
ExprKind::MethodCall(.., ref args, _) if args.len() == 1 => {
ExprKind::MethodCall(.., args, _) if args.len() == 1 => {
if_chain!(
if let Some(expr_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id);
if is_diagnostic_assoc_item(cx, expr_def_id, sym::ToString)
@ -564,7 +564,7 @@ fn check_to_owned(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left:
}
)
},
ExprKind::Call(ref path, ref v) if v.len() == 1 => {
ExprKind::Call(path, v) if v.len() == 1 => {
if let ExprKind::Path(ref path) = path.kind {
if match_qpath(path, &["String", "from_str"]) || match_qpath(path, &["String", "from"]) {
(cx.typeck_results().expr_ty(&v[0]), snippet(cx, v[0].span, ".."))
@ -649,7 +649,7 @@ fn check_to_owned(cx: &LateContext<'_>, expr: &Expr<'_>, other: &Expr<'_>, left:
/// of what it means for an expression to be "used".
fn is_used(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
get_parent_expr(cx, expr).map_or(true, |parent| match parent.kind {
ExprKind::Assign(_, ref rhs, _) | ExprKind::AssignOp(_, _, ref rhs) => SpanlessEq::new(cx).eq_expr(rhs, expr),
ExprKind::Assign(_, rhs, _) | ExprKind::AssignOp(_, _, rhs) => SpanlessEq::new(cx).eq_expr(rhs, expr),
_ => is_used(cx, parent),
})
}

View file

@ -138,7 +138,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn {
let mir = cx.tcx.optimized_mir(def_id);
if let Err((span, err)) = is_min_const_fn(cx.tcx, &mir) {
if let Err((span, err)) = is_min_const_fn(cx.tcx, mir) {
if rustc_mir::const_eval::is_min_const_fn(cx.tcx, def_id.to_def_id()) {
cx.tcx.sess.span_err(span, &err);
}

View file

@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
let attrs = cx.tcx.hir().attrs(it.hir_id());
check_missing_inline_attrs(cx, attrs, it.span, desc);
},
hir::ItemKind::Trait(ref _is_auto, ref _unsafe, ref _generics, ref _bounds, trait_items) => {
hir::ItemKind::Trait(ref _is_auto, ref _unsafe, ref _generics, _bounds, trait_items) => {
// note: we need to check if the trait is exported so we can't use
// `LateLintPass::check_trait_item` here.
for tit in trait_items {

View file

@ -58,21 +58,21 @@ declare_lint_pass!(MutableKeyType => [ MUTABLE_KEY_TYPE ]);
impl<'tcx> LateLintPass<'tcx> for MutableKeyType {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
if let hir::ItemKind::Fn(ref sig, ..) = item.kind {
check_sig(cx, item.hir_id(), &sig.decl);
check_sig(cx, item.hir_id(), sig.decl);
}
}
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'tcx>) {
if let hir::ImplItemKind::Fn(ref sig, ..) = item.kind {
if trait_ref_of_method(cx, item.hir_id()).is_none() {
check_sig(cx, item.hir_id(), &sig.decl);
check_sig(cx, item.hir_id(), sig.decl);
}
}
}
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'tcx>) {
if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind {
check_sig(cx, item.hir_id(), &sig.decl);
check_sig(cx, item.hir_id(), sig.decl);
}
}

Some files were not shown because too many files have changed in this diff Show more