]> git.lizzy.rs Git - rust.git/commitdiff
Fix adjacent code
authorSamuel Moelius <sam@moeli.us>
Wed, 12 Oct 2022 08:34:39 +0000 (04:34 -0400)
committerSamuel Moelius <sam@moeli.us>
Tue, 20 Dec 2022 10:12:13 +0000 (05:12 -0500)
27 files changed:
clippy_lints/src/casts/cast_slice_different_sizes.rs
clippy_lints/src/format_args.rs
clippy_lints/src/large_enum_variant.rs
clippy_lints/src/len_zero.rs
clippy_lints/src/lib.rs
clippy_lints/src/loops/explicit_counter_loop.rs
clippy_lints/src/manual_async_fn.rs
clippy_lints/src/manual_strip.rs
clippy_lints/src/methods/inefficient_to_string.rs
clippy_lints/src/methods/iter_skip_next.rs
clippy_lints/src/methods/option_map_unwrap_or.rs
clippy_lints/src/methods/str_splitn.rs
clippy_lints/src/methods/unnecessary_lazy_eval.rs
clippy_lints/src/needless_late_init.rs
clippy_lints/src/octal_escapes.rs
clippy_lints/src/operators/misrefactored_assign_op.rs
clippy_lints/src/same_name_method.rs
clippy_lints/src/swap.rs
clippy_lints/src/transmute/transmute_undefined_repr.rs
clippy_lints/src/transmute/transmutes_expressible_as_ptr_casts.rs
clippy_lints/src/transmute/useless_transmute.rs
clippy_lints/src/types/redundant_allocation.rs
clippy_lints/src/unit_types/unit_arg.rs
clippy_lints/src/write.rs
clippy_utils/src/diagnostics.rs
tests/ui/manual_retain.fixed
tests/ui/manual_retain.rs

index e862f13e69fc7059011014ad82f3310e8666ea73..c8e54d7b8e0c350446c0fe0f0eee6ac0e221fe38 100644 (file)
@@ -54,7 +54,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, msrv: &Msrv
 
                         diag.span_suggestion(
                             expr.span,
-                            &format!("replace with `ptr::slice_from_raw_parts{mutbl_fn_str}`"),
+                            format!("replace with `ptr::slice_from_raw_parts{mutbl_fn_str}`"),
                             sugg,
                             rustc_errors::Applicability::HasPlaceholders,
                         );
index 62284235dbfec2de08bc11c87c2161a6ec23e95e..9891955a4efe8a11ca49e2d157429f5ab29f2c22 100644 (file)
@@ -377,7 +377,7 @@ fn check_format_in_format_args(cx: &LateContext<'_>, call_site: Span, name: Symb
         call_site,
         &format!("`format!` in `{name}!` args"),
         |diag| {
-            diag.help(&format!(
+            diag.help(format!(
                 "combine the `format!(..)` arguments with the outer `{name}!(..)` call"
             ));
             diag.help("or consider changing `format!` to `format_args!`");
index b18456ee523401759104bbb383178e7d87b5cb5c..b8d4abdbb781acacba0f3910ff55526347ea8b9c 100644 (file)
@@ -111,7 +111,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &Item<'tcx>) {
                         );
                         diag.span_label(
                             def.variants[variants_size[1].ind].span,
-                            &if variants_size[1].fields_size.is_empty() {
+                            if variants_size[1].fields_size.is_empty() {
                                 "the second-largest variant carries no data at all".to_owned()
                             } else {
                                 format!(
index e88d1764a24896a23d168a5b01c2d908e851e804..9eba46756299c57bc178a48fc92b65a4af99fc38 100644 (file)
@@ -361,7 +361,7 @@ fn check_for_is_empty<'tcx>(
             db.span_note(span, "`is_empty` defined here");
         }
         if let Some(self_kind) = self_kind {
-            db.note(&output.expected_sig(self_kind));
+            db.note(output.expected_sig(self_kind));
         }
     });
 }
index 7f7d73339e4523cf3c069b8c4496b9ec7d9f4e65..f95b9538cef38685c2615b0343a6eba09bc1522a 100644 (file)
@@ -335,7 +335,7 @@ pub fn read_conf(sess: &Session, path: &io::Result<Option<PathBuf>>) -> Conf {
         Ok(Some(path)) => path,
         Ok(None) => return Conf::default(),
         Err(error) => {
-            sess.struct_err(&format!("error finding Clippy's configuration file: {error}"))
+            sess.struct_err(format!("error finding Clippy's configuration file: {error}"))
                 .emit();
             return Conf::default();
         },
index 14f2234813277c7c5ae4226278798c26548aa012..1953ee8a717525a9ab3ac883bc0def758fa5875b 100644 (file)
@@ -77,7 +77,7 @@ pub(super) fn check<'tcx>(
                                 applicability,
                             );
 
-                            diag.note(&format!(
+                            diag.note(format!(
                                 "`{name}` is of type `{int_name}`, making it ineligible for `Iterator::enumerate`"
                             ));
                         },
index 075ecbe7eded37340c1b36db85654ea7996588dc..af7c0563555792bfabba1cf1776cf44abaf66225 100644 (file)
@@ -76,7 +76,7 @@ fn check_fn(
                                 let help = format!("make the function `async` and {ret_sugg}");
                                 diag.span_suggestion(
                                     header_span,
-                                    &help,
+                                    help,
                                     format!("async {}{ret_snip}", &header_snip[..ret_pos]),
                                     Applicability::MachineApplicable
                                 );
index de166b9765f4194b6ff22e909c8a370c3200146d..c795c1d9a16c321b9a9260df72206653d8516558 100644 (file)
@@ -109,7 +109,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
 
                     let test_span = expr.span.until(then.span);
                     span_lint_and_then(cx, MANUAL_STRIP, strippings[0], &format!("stripping a {kind_word} manually"), |diag| {
-                        diag.span_note(test_span, &format!("the {kind_word} was tested here"));
+                        diag.span_note(test_span, format!("the {kind_word} was tested here"));
                         multispan_sugg(
                             diag,
                             &format!("try using the `strip_{kind_word}` method"),
index 5c620d0271601fb575f7c9fcfdb5c29a2bae1004..122088f4857cd5925b37b8c744fecaf34b3578ed 100644 (file)
@@ -36,7 +36,7 @@ pub fn check(
                 expr.span,
                 &format!("calling `to_string` on `{arg_ty}`"),
                 |diag| {
-                    diag.help(&format!(
+                    diag.help(format!(
                         "`{self_ty}` implements `ToString` through a slower blanket impl, but `{deref_self_ty}` has a fast specialization of `ToString`"
                     ));
                     let mut applicability = Applicability::MachineApplicable;
index beb772100affcb1e5f1351c413c0a656b0baeae7..279175e20c37fcd5126f908a4cd32ba4663e4a04 100644 (file)
@@ -29,7 +29,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr
                         application = Applicability::Unspecified;
                         diag.span_help(
                             pat.span,
-                            &format!("for this change `{}` has to be mutable", snippet(cx, pat.span, "..")),
+                            format!("for this change `{}` has to be mutable", snippet(cx, pat.span, "..")),
                         );
                     }
                 }
index 910ee14855e234d21507ff2ef01eb25061461bbb..4c6328481e438817cf82f843466ff3f406dc456f 100644 (file)
@@ -84,7 +84,7 @@ pub(super) fn check<'tcx>(
                 suggestion.push((map_arg_span.with_hi(map_arg_span.lo()), format!("{unwrap_snippet}, ")));
             }
 
-            diag.multipart_suggestion(&format!("use `{suggest}` instead"), suggestion, applicability);
+            diag.multipart_suggestion(format!("use `{suggest}` instead"), suggestion, applicability);
         });
     }
 }
index 3c01ce1fecd3a28a161625b72d63331405ff852a..d00708e828eaeb791391a8797bd6980d8e36399a 100644 (file)
@@ -167,7 +167,7 @@ fn check_manual_split_once_indirect(
             };
             diag.span_suggestion_verbose(
                 local.span,
-                &format!("try `{r}split_once`"),
+                format!("try `{r}split_once`"),
                 format!("let ({lhs}, {rhs}) = {self_snip}.{r}split_once({pat_snip}){unwrap};"),
                 app,
             );
index 0e73459ad65f7a258e91b6ee8ccd5ff50d7d4ded..47e2e744112c5a1dc89d29c1d27d0033a9edf3bf 100644 (file)
@@ -62,7 +62,7 @@ pub(super) fn check<'tcx>(
                     span_lint_and_then(cx, UNNECESSARY_LAZY_EVALUATIONS, expr.span, msg, |diag| {
                         diag.span_suggestion(
                             span,
-                            &format!("use `{simplify_using}(..)` instead"),
+                            format!("use `{simplify_using}(..)` instead"),
                             format!("{simplify_using}({})", snippet(cx, body_expr.span, "..")),
                             applicability,
                         );
index 67debe7e08af6008c7ddf474c37a3c7a59e02614..5a9387b34cc1931a68adf7ae5f3fa013e3d72592 100644 (file)
@@ -284,7 +284,7 @@ fn check<'tcx>(
 
                     diag.span_suggestion(
                         assign.lhs_span,
-                        &format!("declare `{binding_name}` here"),
+                        format!("declare `{binding_name}` here"),
                         let_snippet,
                         Applicability::MachineApplicable,
                     );
@@ -304,7 +304,7 @@ fn check<'tcx>(
 
                     diag.span_suggestion_verbose(
                         usage.stmt.span.shrink_to_lo(),
-                        &format!("declare `{binding_name}` here"),
+                        format!("declare `{binding_name}` here"),
                         format!("{let_snippet} = "),
                         applicability,
                     );
@@ -335,7 +335,7 @@ fn check<'tcx>(
 
                     diag.span_suggestion_verbose(
                         usage.stmt.span.shrink_to_lo(),
-                        &format!("declare `{binding_name}` here"),
+                        format!("declare `{binding_name}` here"),
                         format!("{let_snippet} = "),
                         applicability,
                     );
index ae0a41db918a3447067342479161c62939e71e9e..7376ab0c846d954c7c3c39e75b177a83e5f4ff82 100644 (file)
@@ -125,7 +125,7 @@ fn check_lit(cx: &EarlyContext<'_>, lit: &Lit, span: Span, is_string: bool) {
             if is_string { "string" } else { "byte string" }
         ),
         |diag| {
-            diag.help(&format!(
+            diag.help(format!(
                 "octal escapes are not supported, `\\0` is always a null {}",
                 if is_string { "character" } else { "byte" }
             ));
@@ -139,7 +139,7 @@ fn check_lit(cx: &EarlyContext<'_>, lit: &Lit, span: Span, is_string: bool) {
             // suggestion 2: unambiguous null byte
             diag.span_suggestion(
                 span,
-                &format!(
+                format!(
                     "if the null {} is intended, disambiguate using",
                     if is_string { "character" } else { "byte" }
                 ),
index ae805147f07a20155444857085a60eb120f604fe..015f6c14e7612f2c724711b9fed7f8786c433f02 100644 (file)
@@ -50,7 +50,7 @@ fn lint_misrefactored_assign_op(
                 let long = format!("{snip_a} = {}", sugg::make_binop(op.into(), a, r));
                 diag.span_suggestion(
                     expr.span,
-                    &format!(
+                    format!(
                         "did you mean `{snip_a} = {snip_a} {} {snip_r}` or `{long}`? Consider replacing it with",
                         op.as_str()
                     ),
index 91326558cd8dc824e200f4b4e727f40d77acbd71..f35bfb0b4ed884c01f8a1641e8a0e71e31c783f1 100644 (file)
@@ -108,7 +108,7 @@ fn check_crate_post(&mut self, cx: &LateContext<'tcx>) {
                                     |diag| {
                                         diag.span_note(
                                             trait_method_span,
-                                            &format!("existing `{method_name}` defined here"),
+                                            format!("existing `{method_name}` defined here"),
                                         );
                                     },
                                 );
@@ -151,7 +151,7 @@ fn check_crate_post(&mut self, cx: &LateContext<'tcx>) {
                                         // iterate on trait_spans?
                                         diag.span_note(
                                             trait_spans[0],
-                                            &format!("existing `{method_name}` defined here"),
+                                            format!("existing `{method_name}` defined here"),
                                         );
                                     },
                                 );
index c374529d1ea9f5abc9fd54bf49a36163c47463e7..17e9cc5f6b7c7a7d72a5fd73fed5f043c366708d 100644 (file)
@@ -132,7 +132,7 @@ fn generate_swap_warning(cx: &LateContext<'_>, e1: &Expr<'_>, e2: &Expr<'_>, spa
                 applicability,
             );
             if !is_xor_based {
-                diag.note(&format!("or maybe you should use `{sugg}::mem::replace`?"));
+                diag.note(format!("or maybe you should use `{sugg}::mem::replace`?"));
             }
         },
     );
@@ -214,7 +214,7 @@ fn check_suspicious_swap(cx: &LateContext<'_>, block: &Block<'_>) {
                                 Applicability::MaybeIncorrect,
                             );
                             diag.note(
-                                &format!("or maybe you should use `{sugg}::mem::replace`?")
+                                format!("or maybe you should use `{sugg}::mem::replace`?")
                             );
                         }
                     });
index 34642f4b122f22f097df02fada46a66a69129192..af0242348ac295facaeff4a24e661b6c8863e3e6 100644 (file)
@@ -77,7 +77,7 @@ pub(super) fn check<'tcx>(
                     &format!("transmute from `{from_ty_orig}` which has an undefined layout"),
                     |diag| {
                         if from_ty_orig.peel_refs() != from_ty.peel_refs() {
-                            diag.note(&format!("the contained type `{from_ty}` has an undefined layout"));
+                            diag.note(format!("the contained type `{from_ty}` has an undefined layout"));
                         }
                     },
                 );
@@ -91,7 +91,7 @@ pub(super) fn check<'tcx>(
                     &format!("transmute to `{to_ty_orig}` which has an undefined layout"),
                     |diag| {
                         if to_ty_orig.peel_refs() != to_ty.peel_refs() {
-                            diag.note(&format!("the contained type `{to_ty}` has an undefined layout"));
+                            diag.note(format!("the contained type `{to_ty}` has an undefined layout"));
                         }
                     },
                 );
@@ -119,16 +119,16 @@ pub(super) fn check<'tcx>(
                     ),
                     |diag| {
                         if let Some(same_adt_did) = same_adt_did {
-                            diag.note(&format!(
+                            diag.note(format!(
                                 "two instances of the same generic type (`{}`) may have different layouts",
                                 cx.tcx.item_name(same_adt_did)
                             ));
                         } else {
                             if from_ty_orig.peel_refs() != from_ty {
-                                diag.note(&format!("the contained type `{from_ty}` has an undefined layout"));
+                                diag.note(format!("the contained type `{from_ty}` has an undefined layout"));
                             }
                             if to_ty_orig.peel_refs() != to_ty {
-                                diag.note(&format!("the contained type `{to_ty}` has an undefined layout"));
+                                diag.note(format!("the contained type `{to_ty}` has an undefined layout"));
                             }
                         }
                     },
@@ -146,7 +146,7 @@ pub(super) fn check<'tcx>(
                     &format!("transmute from `{from_ty_orig}` which has an undefined layout"),
                     |diag| {
                         if from_ty_orig.peel_refs() != from_ty {
-                            diag.note(&format!("the contained type `{from_ty}` has an undefined layout"));
+                            diag.note(format!("the contained type `{from_ty}` has an undefined layout"));
                         }
                     },
                 );
@@ -163,7 +163,7 @@ pub(super) fn check<'tcx>(
                     &format!("transmute into `{to_ty_orig}` which has an undefined layout"),
                     |diag| {
                         if to_ty_orig.peel_refs() != to_ty {
-                            diag.note(&format!("the contained type `{to_ty}` has an undefined layout"));
+                            diag.note(format!("the contained type `{to_ty}` has an undefined layout"));
                         }
                     },
                 );
index 6b444922a7cc755b7907a28a12617dc6eacb2ede..b79d4e915a2718b70ae063b686aa7ad66918ddd0 100644 (file)
@@ -24,7 +24,7 @@ pub(super) fn check<'tcx>(
             &format!("transmute from `{from_ty}` to `{to_ty}` which could be expressed as a pointer cast instead"),
             |diag| {
                 if let Some(arg) = sugg::Sugg::hir_opt(cx, arg) {
-                    let sugg = arg.as_ty(&to_ty.to_string()).to_string();
+                    let sugg = arg.as_ty(to_ty.to_string()).to_string();
                     diag.span_suggestion(e.span, "try", sugg, Applicability::MachineApplicable);
                 }
             },
index f919bbd5afca3f823c9458c815ae7f8fab5e9fbe..871c3fadbba71b84f7c1d18364f44fb40fb9293f 100644 (file)
@@ -61,7 +61,7 @@ pub(super) fn check<'tcx>(
                 "transmute from an integer to a pointer",
                 |diag| {
                     if let Some(arg) = sugg::Sugg::hir_opt(cx, arg) {
-                        diag.span_suggestion(e.span, "try", arg.as_ty(&to_ty.to_string()), Applicability::Unspecified);
+                        diag.span_suggestion(e.span, "try", arg.as_ty(to_ty.to_string()), Applicability::Unspecified);
                     }
                 },
             );
index fae5385ffc848dc3d09805baac4d749f3fc5dfc4..f9b9a66b5fa461b17e2e99dd41da1dfd8192ccaf 100644 (file)
@@ -31,7 +31,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_
             &format!("usage of `{outer_sym}<{generic_snippet}>`"),
             |diag| {
                 diag.span_suggestion(hir_ty.span, "try", format!("{generic_snippet}"), applicability);
-                diag.note(&format!(
+                diag.note(format!(
                     "`{generic_snippet}` is already a pointer, `{outer_sym}<{generic_snippet}>` allocates a pointer on the heap"
                 ));
             },
@@ -78,7 +78,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_
                     format!("{outer_sym}<{generic_snippet}>"),
                     applicability,
                 );
-                diag.note(&format!(
+                diag.note(format!(
                     "`{inner_sym}<{generic_snippet}>` is already on the heap, `{outer_sym}<{inner_sym}<{generic_snippet}>>` makes an extra allocation"
                 ));
             },
@@ -91,10 +91,10 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_
             hir_ty.span,
             &format!("usage of `{outer_sym}<{inner_sym}<{generic_snippet}>>`"),
             |diag| {
-                diag.note(&format!(
+                diag.note(format!(
                     "`{inner_sym}<{generic_snippet}>` is already on the heap, `{outer_sym}<{inner_sym}<{generic_snippet}>>` makes an extra allocation"
                 ));
-                diag.help(&format!(
+                diag.help(format!(
                     "consider using just `{outer_sym}<{generic_snippet}>` or `{inner_sym}<{generic_snippet}>`"
                 ));
             },
index f6d3fb00f4ee5220926e4ffe3c261fc1d9a4a42f..ef9f740f7047c08b00c022b2ca6c74c7e7ab162d 100644 (file)
@@ -129,7 +129,7 @@ fn lint_unit_args(cx: &LateContext<'_>, expr: &Expr<'_>, args_to_recover: &[&Exp
 
                 if arg_snippets_without_empty_blocks.is_empty() {
                     db.multipart_suggestion(
-                        &format!("use {singular}unit literal{plural} instead"),
+                        format!("use {singular}unit literal{plural} instead"),
                         args_to_recover
                             .iter()
                             .map(|arg| (arg.span, "()".to_string()))
@@ -142,7 +142,7 @@ fn lint_unit_args(cx: &LateContext<'_>, expr: &Expr<'_>, args_to_recover: &[&Exp
                     let it_or_them = if plural { "them" } else { "it" };
                     db.span_suggestion(
                         expr.span,
-                        &format!(
+                        format!(
                             "{or}move the expression{empty_or_s} in front of the call and replace {it_or_them} with the unit literal `()`"
                         ),
                         sugg,
index 6b321765bc082d8c1912bd1413e9dfdbee71e059..df3350388817ed9ca3765d3bd6c1a45882611353 100644 (file)
@@ -377,7 +377,7 @@ fn check_newline(cx: &LateContext<'_>, format_args: &FormatArgsExpn<'_>, macro_c
                     // print!("\n"), write!(f, "\n")
 
                     diag.multipart_suggestion(
-                        &format!("use `{name}ln!` instead"),
+                        format!("use `{name}ln!` instead"),
                         vec![(name_span, format!("{name}ln")), (format_string_span, String::new())],
                         Applicability::MachineApplicable,
                     );
@@ -388,7 +388,7 @@ fn check_newline(cx: &LateContext<'_>, format_args: &FormatArgsExpn<'_>, macro_c
                     let newline_span = format_string_span.with_lo(hi - BytePos(3)).with_hi(hi - BytePos(1));
 
                     diag.multipart_suggestion(
-                        &format!("use `{name}ln!` instead"),
+                        format!("use `{name}ln!` instead"),
                         vec![(name_span, format!("{name}ln")), (newline_span, String::new())],
                         Applicability::MachineApplicable,
                     );
index 16b160b6fd27ef688b888d8e9fbd9cee5d2da35b..812f6fe71a0a0c7faf9efd8b002055072082dafb 100644 (file)
@@ -17,7 +17,7 @@
 fn docs_link(diag: &mut Diagnostic, lint: &'static Lint) {
     if env::var("CLIPPY_DISABLE_DOCS_LINKS").is_err() {
         if let Some(lint) = lint.name_lower().strip_prefix("clippy::") {
-            diag.help(&format!(
+            diag.help(format!(
                 "for further information visit https://rust-lang.github.io/rust-clippy/{}/index.html#{lint}",
                 &option_env!("RUST_RELEASE_NUM").map_or("master".to_string(), |n| {
                     // extract just major + minor version and ignore patch versions
index e5ae3cf3e5033295b16936b7f71fac65269834f7..8f25fea678f19df58aded7d4add8a5f288e7e32e 100644 (file)
@@ -1,6 +1,6 @@
 // run-rustfix
 #![warn(clippy::manual_retain)]
-#![allow(unused)]
+#![allow(unused, clippy::redundant_clone)]
 use std::collections::BTreeMap;
 use std::collections::BTreeSet;
 use std::collections::BinaryHeap;
index 1021f15edd1ea9c579aa8ceff38c17f12eb22414..e6b3995a689b3d077b22da927959d31f59389a9a 100644 (file)
@@ -1,6 +1,6 @@
 // run-rustfix
 #![warn(clippy::manual_retain)]
-#![allow(unused)]
+#![allow(unused, clippy::redundant_clone)]
 use std::collections::BTreeMap;
 use std::collections::BTreeSet;
 use std::collections::BinaryHeap;