]> git.lizzy.rs Git - rust.git/commitdiff
Box `ExprKind::{Closure,MethodCall}`, and `QSelf` in expressions, types, and patterns.
authorNicholas Nethercote <n.nethercote@gmail.com>
Thu, 8 Sep 2022 00:52:51 +0000 (10:52 +1000)
committerNicholas Nethercote <n.nethercote@gmail.com>
Thu, 17 Nov 2022 02:45:59 +0000 (13:45 +1100)
clippy_lints/src/double_parens.rs
clippy_lints/src/option_env_unwrap.rs
clippy_lints/src/precedence.rs
clippy_lints/src/redundant_closure_call.rs
clippy_lints/src/suspicious_operation_groupings.rs
clippy_lints/src/unnested_or_patterns.rs
clippy_lints/src/unused_rounding.rs
clippy_utils/src/ast_utils.rs

index 0f1d701865e7d711bbf8ae1bdb949c31d5214611..29425b2e5541791db6c485d904a38981abda173b 100644 (file)
@@ -61,10 +61,10 @@ fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
                     }
                 }
             },
-            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);
                     }
                 }
             },
index d9ee031c9f9756ffe11968f79499cd56b0277bca..377bddeaa5feabccaa30f4a6e759baf33b152741 100644 (file)
@@ -1,7 +1,7 @@
 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;
@@ -37,8 +37,8 @@
 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 {
index bee4a33fb4a019b7dcb9d91fb48c38243431cc40..057b7e30642ec5bc0edd134d913bef1ec8c537e4 100644 (file)
@@ -1,7 +1,7 @@
 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};
@@ -110,11 +110,11 @@ fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
             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;
             }
 
index 74eea6de4bbeff43d30c92d83a8553c73d6cfab9..4cbe9597c5393eee7221480dbb487aa6d863ce76 100644 (file)
@@ -69,10 +69,10 @@ fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) {
         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,
@@ -80,13 +80,13 @@ fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) {
                         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();
                                     }
 
index eef9bdc78494002515ec1e615bc726062eaaf1bd..78e83880e1a6121020f0d6e0d724fee457fe46e0 100644 (file)
@@ -580,7 +580,7 @@ fn ident_difference_expr_with_base_location(
         | (Await(_), Await(_))
         | (Async(_, _, _), Async(_, _, _))
         | (Block(_, _), Block(_, _))
-        | (Closure(_, _, _, _, _, _, _), Closure(_, _, _, _, _, _, _))
+        | (Closure(_), Closure(_))
         | (Match(_, _), Match(_, _))
         | (Loop(_, _), Loop(_, _))
         | (ForLoop(_, _, _, _), ForLoop(_, _, _, _))
@@ -593,7 +593,7 @@ fn ident_difference_expr_with_base_location(
         | (Unary(_, _), Unary(_, _))
         | (Binary(_, _, _), Binary(_, _, _))
         | (Tup(_), Tup(_))
-        | (MethodCall(_, _, _, _), MethodCall(_, _, _, _))
+        | (MethodCall(_), MethodCall(_))
         | (Call(_, _), Call(_, _))
         | (ConstBlock(_), ConstBlock(_))
         | (Array(_), Array(_))
index b305dae76084c3e698263f59701c83698ca470db..bb6fb38e9690e32a3e472c49f1462bc38fa28d1b 100644 (file)
@@ -292,7 +292,7 @@ fn transform_with_focus_on_idx(alternatives: &mut Vec<P<Pat>>, focus_idx: usize)
 /// 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,
index 3c1998d0237d989cf9180e4ec8a345468737a3c6..5ab351bc29ca0b8b1ba653287f1933cc70d99217 100644 (file)
@@ -1,5 +1,5 @@
 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};
@@ -30,8 +30,8 @@
 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() {
index 73d1ba727c82108a95d7db8e375b653b774c3b17..23aed4b5ba2f40f2c675009c338736431a5fdd1e 100644 (file)
@@ -75,11 +75,11 @@ pub fn eq_field_pat(l: &PatField, r: &PatField) -> bool {
         && 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,
@@ -147,8 +147,11 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool {
         (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),
@@ -170,7 +173,26 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool {
         (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()