}
}
},
- ExprKind::MethodCall(_, _, ref params, _) => {
- if let [ref param] = params[..] {
- if let ExprKind::Paren(_) = param.kind {
- span_lint(cx, DOUBLE_PARENS, param.span, msg);
+ ExprKind::MethodCall(ref call) => {
+ if let [ref arg] = call.args[..] {
+ if let ExprKind::Paren(_) = arg.kind {
+ span_lint(cx, DOUBLE_PARENS, arg.span, msg);
}
}
},
use clippy_utils::diagnostics::span_lint_and_help;
use clippy_utils::is_direct_expn_of;
use if_chain::if_chain;
-use rustc_ast::ast::{Expr, ExprKind};
+use rustc_ast::ast::{Expr, ExprKind, MethodCall};
use rustc_lint::{EarlyContext, EarlyLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::sym;
impl EarlyLintPass for OptionEnvUnwrap {
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
if_chain! {
- if let ExprKind::MethodCall(path_segment, receiver, _, _) = &expr.kind;
- if matches!(path_segment.ident.name, sym::expect | sym::unwrap);
+ if let ExprKind::MethodCall(box MethodCall { seg, receiver, .. }) = &expr.kind;
+ if matches!(seg.ident.name, sym::expect | sym::unwrap);
if let ExprKind::Call(caller, _) = &receiver.kind;
if is_direct_expn_of(caller.span, "option_env").is_some();
then {
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::snippet_with_applicability;
use if_chain::if_chain;
-use rustc_ast::ast::{BinOpKind, Expr, ExprKind, UnOp};
+use rustc_ast::ast::{BinOpKind, Expr, ExprKind, MethodCall, UnOp};
use rustc_ast::token;
use rustc_errors::Applicability;
use rustc_lint::{EarlyContext, EarlyLintPass};
let mut arg = operand;
let mut all_odd = true;
- while let ExprKind::MethodCall(path_segment, receiver, _, _) = &arg.kind {
- let path_segment_str = path_segment.ident.name.as_str();
+ while let ExprKind::MethodCall(box MethodCall { seg, receiver, .. }) = &arg.kind {
+ let seg_str = seg.ident.name.as_str();
all_odd &= ALLOWED_ODD_FUNCTIONS
.iter()
- .any(|odd_function| **odd_function == *path_segment_str);
+ .any(|odd_function| **odd_function == *seg_str);
arg = receiver;
}
if_chain! {
if let ast::ExprKind::Call(ref paren, _) = expr.kind;
if let ast::ExprKind::Paren(ref closure) = paren.kind;
- if let ast::ExprKind::Closure(_, _, ref r#async, _, ref decl, ref block, _) = closure.kind;
+ if let ast::ExprKind::Closure(box ast::Closure { ref asyncness, ref fn_decl, ref body, .. }) = closure.kind;
then {
let mut visitor = ReturnVisitor::new();
- visitor.visit_expr(block);
+ visitor.visit_expr(body);
if !visitor.found_return {
span_lint_and_then(
cx,
expr.span,
"try not to call a closure in the expression where it is declared",
|diag| {
- if decl.inputs.is_empty() {
+ if fn_decl.inputs.is_empty() {
let app = Applicability::MachineApplicable;
- let mut hint = Sugg::ast(cx, block, "..");
+ let mut hint = Sugg::ast(cx, body, "..");
- if r#async.is_async() {
+ if asyncness.is_async() {
// `async x` is a syntax error, so it becomes `async { x }`
- if !matches!(block.kind, ast::ExprKind::Block(_, _)) {
+ if !matches!(body.kind, ast::ExprKind::Block(_, _)) {
hint = hint.blockify();
}
| (Await(_), Await(_))
| (Async(_, _, _), Async(_, _, _))
| (Block(_, _), Block(_, _))
- | (Closure(_, _, _, _, _, _, _), Closure(_, _, _, _, _, _, _))
+ | (Closure(_), Closure(_))
| (Match(_, _), Match(_, _))
| (Loop(_, _), Loop(_, _))
| (ForLoop(_, _, _, _), ForLoop(_, _, _, _))
| (Unary(_, _), Unary(_, _))
| (Binary(_, _, _), Binary(_, _, _))
| (Tup(_), Tup(_))
- | (MethodCall(_, _, _, _), MethodCall(_, _, _, _))
+ | (MethodCall(_), MethodCall(_))
| (Call(_, _), Call(_, _))
| (ConstBlock(_), ConstBlock(_))
| (Array(_), Array(_))
/// So when we fixate on some `ident_k: pat_k`, we try to find `ident_k` in the other pattern
/// and check that all `fp_i` where `i ∈ ((0...n) \ k)` between two patterns are equal.
fn extend_with_struct_pat(
- qself1: &Option<ast::QSelf>,
+ qself1: &Option<P<ast::QSelf>>,
path1: &ast::Path,
fps1: &mut [ast::PatField],
rest1: bool,
use clippy_utils::diagnostics::span_lint_and_sugg;
-use rustc_ast::ast::{Expr, ExprKind};
+use rustc_ast::ast::{Expr, ExprKind, MethodCall};
use rustc_errors::Applicability;
use rustc_lint::{EarlyContext, EarlyLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
declare_lint_pass!(UnusedRounding => [UNUSED_ROUNDING]);
fn is_useless_rounding(expr: &Expr) -> Option<(&str, String)> {
- if let ExprKind::MethodCall(name_ident, receiver, _, _) = &expr.kind
- && let method_name = name_ident.ident.name.as_str()
+ if let ExprKind::MethodCall(box MethodCall { seg, receiver, .. }) = &expr.kind
+ && let method_name = seg.ident.name.as_str()
&& (method_name == "ceil" || method_name == "round" || method_name == "floor")
&& let ExprKind::Lit(token_lit) = &receiver.kind
&& token_lit.is_semantic_float() {
&& over(&l.attrs, &r.attrs, eq_attr)
}
-pub fn eq_qself(l: &QSelf, r: &QSelf) -> bool {
+pub fn eq_qself(l: &P<QSelf>, r: &P<QSelf>) -> bool {
l.position == r.position && eq_ty(&l.ty, &r.ty)
}
-pub fn eq_maybe_qself(l: &Option<QSelf>, r: &Option<QSelf>) -> bool {
+pub fn eq_maybe_qself(l: &Option<P<QSelf>>, r: &Option<P<QSelf>>) -> bool {
match (l, r) {
(Some(l), Some(r)) => eq_qself(l, r),
(None, None) => true,
(Array(l), Array(r)) | (Tup(l), Tup(r)) => over(l, r, |l, r| eq_expr(l, r)),
(Repeat(le, ls), Repeat(re, rs)) => eq_expr(le, re) && eq_expr(&ls.value, &rs.value),
(Call(lc, la), Call(rc, ra)) => eq_expr(lc, rc) && over(la, ra, |l, r| eq_expr(l, r)),
- (MethodCall(lc, ls, la, _), MethodCall(rc, rs, ra, _)) => {
- eq_path_seg(lc, rc) && eq_expr(ls, rs) && over(la, ra, |l, r| eq_expr(l, r))
+ (
+ MethodCall(box ast::MethodCall { seg: ls, receiver: lr, args: la, .. }),
+ MethodCall(box ast::MethodCall { seg: rs, receiver: rr, args: ra, .. })
+ ) => {
+ eq_path_seg(ls, rs) && eq_expr(lr, rr) && over(la, ra, |l, r| eq_expr(l, r))
},
(Binary(lo, ll, lr), Binary(ro, rl, rr)) => lo.node == ro.node && eq_expr(ll, rl) && eq_expr(lr, rr),
(Unary(lo, l), Unary(ro, r)) => mem::discriminant(lo) == mem::discriminant(ro) && eq_expr(l, r),
(AssignOp(lo, lp, lv), AssignOp(ro, rp, rv)) => lo.node == ro.node && eq_expr(lp, rp) && eq_expr(lv, rv),
(Field(lp, lf), Field(rp, rf)) => eq_id(*lf, *rf) && eq_expr(lp, rp),
(Match(ls, la), Match(rs, ra)) => eq_expr(ls, rs) && over(la, ra, eq_arm),
- (Closure(lb, lc, la, lm, lf, le, _), Closure(rb, rc, ra, rm, rf, re, _)) => {
+ (
+ Closure(box ast::Closure {
+ binder: lb,
+ capture_clause: lc,
+ asyncness: la,
+ movability: lm,
+ fn_decl: lf,
+ body: le,
+ ..
+ }),
+ Closure(box ast::Closure {
+ binder: rb,
+ capture_clause: rc,
+ asyncness: ra,
+ movability: rm,
+ fn_decl: rf,
+ body: re,
+ ..
+ })
+ ) => {
eq_closure_binder(lb, rb)
&& lc == rc
&& la.is_async() == ra.is_async()