]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #4460 - JohnTitor:fix-inherent-to-string, r=flip1995
authorPhilipp Krones <hello@philkrones.com>
Wed, 28 Aug 2019 11:00:52 +0000 (13:00 +0200)
committerGitHub <noreply@github.com>
Wed, 28 Aug 2019 11:00:52 +0000 (13:00 +0200)
Fix `inherent_to_string` false positive

Fixes #4457

changelog: fixes `inherent_to_string` false positive

13 files changed:
clippy_lints/src/bytecount.rs
clippy_lints/src/escape.rs
clippy_lints/src/eta_reduction.rs
clippy_lints/src/functions.rs
clippy_lints/src/map_clone.rs
clippy_lints/src/map_unit_fn.rs
clippy_lints/src/methods/mod.rs
clippy_lints/src/methods/unnecessary_filter_map.rs
clippy_lints/src/needless_pass_by_value.rs
clippy_lints/src/types.rs
clippy_lints/src/utils/mod.rs
clippy_lints/src/utils/ptr.rs
doc/adding_lints.md

index ab9cf951261748c0a6d816c55a4b08cf9e53b02b..1e1e4317e34ec48687c4c4da5762cfb453013088 100644 (file)
@@ -47,8 +47,8 @@ fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr) {
             then {
                 let body = cx.tcx.hir().body(body_id);
                 if_chain! {
-                    if body.arguments.len() == 1;
-                    if let Some(argname) = get_pat_name(&body.arguments[0].pat);
+                    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.node;
                     if op.node == BinOpKind::Eq;
                     if match_type(cx,
index c37efbd6e49dafe17f6a6072781f850c91c2247e..e174cdfb86033f92095752bcc83bb53de3dabc7d 100644 (file)
@@ -108,7 +108,7 @@ fn is_argument(map: &hir::map::Map<'_>, id: HirId) -> bool {
     }
 
     match map.find(map.get_parent_node(id)) {
-        Some(Node::Arg(_)) => true,
+        Some(Node::Param(_)) => true,
         _ => false,
     }
 }
index e4fcd271bbcbc57f6704f2fd25730f17c2992dbb..485a29ed3d89c80e77874965065a7278ee493a0b 100644 (file)
@@ -202,7 +202,10 @@ fn get_type_name(cx: &LateContext<'_, '_>, ty: Ty<'_>) -> String {
     }
 }
 
-fn compare_inputs(closure_inputs: &mut dyn Iterator<Item = &Arg>, call_args: &mut dyn Iterator<Item = &Expr>) -> bool {
+fn compare_inputs(
+    closure_inputs: &mut dyn Iterator<Item = &Param>,
+    call_args: &mut dyn Iterator<Item = &Expr>,
+) -> bool {
     for (closure_input, function_arg) in closure_inputs.zip(call_args) {
         if let PatKind::Binding(_, _, ident, _) = closure_input.pat.node {
             // XXXManishearth Should I be checking the binding mode here?
index 9772a603ba0379dcbbdb2988b72a3bf082850ec2..e009d28db68509cbcfb6317e8968c72dd5487eb5 100644 (file)
@@ -280,7 +280,7 @@ fn check_raw_ptr(
     }
 }
 
-fn raw_ptr_arg(arg: &hir::Arg, ty: &hir::Ty) -> Option<hir::HirId> {
+fn raw_ptr_arg(arg: &hir::Param, ty: &hir::Ty) -> Option<hir::HirId> {
     if let (&hir::PatKind::Binding(_, id, _, _), &hir::TyKind::Ptr(_)) = (&arg.pat.node, &ty.node) {
         Some(id)
     } else {
index 09c1f4b3c97986f38b0250dd1a56cacb5119a8e9..5c44346aa6df549ef180e19b447ca2d82fc4f7db 100644 (file)
@@ -57,7 +57,7 @@ fn check_expr(&mut self, cx: &LateContext<'_, '_>, e: &hir::Expr) {
             let closure_body = cx.tcx.hir().body(body_id);
             let closure_expr = remove_blocks(&closure_body.value);
             then {
-                match closure_body.arguments[0].pat.node {
+                match closure_body.params[0].pat.node {
                     hir::PatKind::Ref(ref inner, _) => if let hir::PatKind::Binding(
                         hir::BindingAnnotation::Unannotated, .., name, None
                     ) = inner.node {
index 7d46478a6fd3a652e32e3415e2a42e7dd271d528..0df14c2664aefadd814112099896ab245d55f406 100644 (file)
@@ -161,7 +161,10 @@ fn reduce_unit_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a hir::Expr) ->
     }
 }
 
-fn unit_closure<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'a hir::Expr) -> Option<(&'tcx hir::Arg, &'a hir::Expr)> {
+fn unit_closure<'a, 'tcx>(
+    cx: &LateContext<'a, 'tcx>,
+    expr: &'a hir::Expr,
+) -> Option<(&'tcx hir::Param, &'a hir::Expr)> {
     if let hir::ExprKind::Closure(_, ref decl, inner_expr_id, _, _) = expr.node {
         let body = cx.tcx.hir().body(inner_expr_id);
         let body_expr = &body.value;
index cc22d3b9865fb0f3a8abdc34c0a75e35b24bd2ee..81a8e69220c168f2ed2dcad66f88cdd073913ce3 100644 (file)
@@ -1732,8 +1732,8 @@ fn check_fold_with_op(
             if bin_op.node == op;
 
             // Extract the names of the two arguments to the closure
-            if let Some(first_arg_ident) = get_arg_name(&closure_body.arguments[0].pat);
-            if let Some(second_arg_ident) = get_arg_name(&closure_body.arguments[1].pat);
+            if let Some(first_arg_ident) = get_arg_name(&closure_body.params[0].pat);
+            if let Some(second_arg_ident) = get_arg_name(&closure_body.params[1].pat);
 
             if match_var(&*left_expr, first_arg_ident);
             if replacement_has_args || match_var(&*right_expr, second_arg_ident);
@@ -2345,7 +2345,7 @@ fn lint_flat_map_identity<'a, 'tcx>(
             if let hir::ExprKind::Closure(_, _, body_id, _, _) = arg_node;
             let body = cx.tcx.hir().body(*body_id);
 
-            if let hir::PatKind::Binding(_, _, binding_ident, _) = body.arguments[0].pat.node;
+            if let hir::PatKind::Binding(_, _, binding_ident, _) = body.params[0].pat.node;
             if let hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) = body.value.node;
 
             if path.segments.len() == 1;
@@ -2390,7 +2390,7 @@ fn lint_search_is_some<'a, 'tcx>(
                 if search_method == "find";
                 if let hir::ExprKind::Closure(_, _, body_id, ..) = search_args[1].node;
                 let closure_body = cx.tcx.hir().body(body_id);
-                if let Some(closure_arg) = closure_body.arguments.get(0);
+                if let Some(closure_arg) = closure_body.params.get(0);
                 if let hir::PatKind::Ref(..) = closure_arg.pat.node;
                 then {
                     Some(search_snippet.replacen('&', "", 1))
index a28e9b1e3079bb2e6d71cc5ac2acb147b1000627..1d562566fdf881e7d43f41f997188b09133a4f0d 100644 (file)
@@ -17,7 +17,7 @@ pub(super) fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr, args: &[hir::Expr
 
     if let hir::ExprKind::Closure(_, _, body_id, ..) = args[1].node {
         let body = cx.tcx.hir().body(body_id);
-        let arg_id = body.arguments[0].pat.hir_id;
+        let arg_id = body.params[0].pat.hir_id;
         let mutates_arg = match mutated_variables(&body.value, cx) {
             Some(used_mutably) => used_mutably.contains(&arg_id),
             None => true,
index f09fb22f82ade2dfa7432027121de8891204922a..d3ca5cb539a1be08c58168b37af489bdbfdeca50 100644 (file)
@@ -152,7 +152,7 @@ fn check_fn(
         let fn_sig = cx.tcx.fn_sig(fn_def_id);
         let fn_sig = cx.tcx.erase_late_bound_regions(&fn_sig);
 
-        for (idx, ((input, &ty), arg)) in decl.inputs.iter().zip(fn_sig.inputs()).zip(&body.arguments).enumerate() {
+        for (idx, ((input, &ty), arg)) in decl.inputs.iter().zip(fn_sig.inputs()).zip(&body.params).enumerate() {
             // All spans generated from a proc-macro invocation are the same...
             if span == input.span {
                 return;
index 24eba166c7b147cbd73f0e7c0d375870d58a2154..28d337d3cd67c1d46e36fb535dc9b8a2441d86a1 100644 (file)
@@ -2056,7 +2056,7 @@ fn suggestion<'a, 'tcx>(
                             continue;
                         }
                         let generics_suggestion_span = generics.span.substitute_dummy({
-                            let pos = snippet_opt(cx, item.span.until(body.arguments[0].pat.span))
+                            let pos = snippet_opt(cx, item.span.until(body.params[0].pat.span))
                                 .and_then(|snip| {
                                     let i = snip.find("fn")?;
                                     Some(item.span.lo() + BytePos((i + (&snip[i..]).find('(')?) as u32))
index 408deb1b402d2be483da4c6622a8407e8ea1da8d..8fb45899653c0d3d1a740d5f5ff871be42af7a1d 100644 (file)
@@ -835,7 +835,7 @@ pub fn remove_blocks(expr: &Expr) -> &Expr {
     }
 }
 
-pub fn is_self(slf: &Arg) -> bool {
+pub fn is_self(slf: &Param) -> bool {
     if let PatKind::Binding(.., name, _) = slf.pat.node {
         name.name == kw::SelfLower
     } else {
@@ -855,8 +855,8 @@ pub fn is_self_ty(slf: &hir::Ty) -> bool {
     false
 }
 
-pub fn iter_input_pats<'tcx>(decl: &FnDecl, body: &'tcx Body) -> impl Iterator<Item = &'tcx Arg> {
-    (0..decl.inputs.len()).map(move |i| &body.arguments[i])
+pub fn iter_input_pats<'tcx>(decl: &FnDecl, body: &'tcx Body) -> impl Iterator<Item = &'tcx Param> {
+    (0..decl.inputs.len()).map(move |i| &body.params[i])
 }
 
 /// Checks if a given expression is a match expression expanded from the `?`
index e378ef0c0a90403950abef0c2aff7c2a79af5fa2..be7bd0d21f69cb4b8ab12ad90b4a4a6497e42016 100644 (file)
@@ -13,7 +13,7 @@ pub fn get_spans(
     replacements: &[(&'static str, &'static str)],
 ) -> Option<Vec<(Span, Cow<'static, str>)>> {
     if let Some(body) = opt_body_id.map(|id| cx.tcx.hir().body(id)) {
-        get_binding_name(&body.arguments[idx]).map_or_else(
+        get_binding_name(&body.params[idx]).map_or_else(
             || Some(vec![]),
             |name| extract_clone_suggestions(cx, name, replacements, body),
         )
@@ -80,6 +80,6 @@ fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
     }
 }
 
-fn get_binding_name(arg: &Arg) -> Option<Name> {
+fn get_binding_name(arg: &Param) -> Option<Name> {
     get_pat_name(&arg.pat)
 }
index c9816911a828ab27b0c4dce4d7ff24a491e762ea..1fb26c66d9fbb8ef78b40c17c277b7e483b232ba 100644 (file)
@@ -86,6 +86,8 @@ test. That allows us to check if the output is turning into what we want.
 
 Once we are satisfied with the output, we need to run
 `tests/ui/update-all-references.sh` to update the `.stderr` file for our lint.
+Please note that, we should run `TESTNAME=ui/foo_functions cargo uitest`
+every time before running `tests/ui/update-all-references.sh`.
 Running `TESTNAME=ui/foo_functions cargo uitest` should pass then. When we
 commit our lint, we need to commit the generated `.stderr` files, too.