about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJacherr <jwc2002@outlook.com>2023-11-11 00:21:35 +0000
committerJacherr <jwc2002@outlook.com>2023-11-11 00:59:05 +0000
commit7bc39f3af855868705b697888383ce00eb6d1bf4 (patch)
tree785ed50afa692ca2975c9e140fe1f1a1996ef4a9
parentcb90674aed9ec7b6c7bb471d2ec8cc3b36745b79 (diff)
downloadrust-7bc39f3af855868705b697888383ce00eb6d1bf4.tar.gz
rust-7bc39f3af855868705b697888383ce00eb6d1bf4.zip
format and fix examples
-rw-r--r--clippy_lints/src/iter_over_hash_type.rs18
1 files changed, 9 insertions, 9 deletions
diff --git a/clippy_lints/src/iter_over_hash_type.rs b/clippy_lints/src/iter_over_hash_type.rs
index 554790ac61b..607d8e5fc28 100644
--- a/clippy_lints/src/iter_over_hash_type.rs
+++ b/clippy_lints/src/iter_over_hash_type.rs
@@ -1,6 +1,7 @@
-use clippy_utils::paths::{HASHMAP_KEYS, HASHMAP_VALUES, HASHSET_ITER_TY};
-use clippy_utils::{diagnostics::span_lint, match_def_path};
+use clippy_utils::diagnostics::span_lint;
 use clippy_utils::higher::ForLoop;
+use clippy_utils::match_def_path;
+use clippy_utils::paths::{HASHMAP_KEYS, HASHMAP_VALUES, HASHSET_ITER_TY};
 use clippy_utils::ty::is_type_diagnostic_item;
 use rustc_lint::{LateContext, LateLintPass};
 use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -18,16 +19,16 @@ declare_clippy_lint! {
     ///
     /// ### Example
     /// ```no_run
-    ///     let my_map = new Hashmap<i32, String>();
+    ///     let my_map = std::collections::HashMap::<i32, String>::new();
     ///     for (key, value) in my_map { /* ... */ }
     /// ```
     /// Use instead:
     /// ```no_run
-    ///     let my_map = new Hashmap<i32, String>();
-    ///     let mut keys = my_map.keys().clone().collect::<Vec<_>();
+    ///     let my_map = std::collections::HashMap::<i32, String>::new();
+    ///     let mut keys = my_map.keys().clone().collect::<Vec<_>>();
     ///     keys.sort();
     ///     for key in keys {
-    ///         let value = &my_map[value];
+    ///         let value = &my_map[key];
     ///     }
     /// ```
     #[clippy::version = "1.75.0"]
@@ -45,10 +46,10 @@ impl LateLintPass<'_> for IterOverHashType {
             && let ty = cx.typeck_results().expr_ty(for_loop.arg).peel_refs()
             && let Some(adt) = ty.ty_adt_def()
             && let did = adt.did()
-            && (match_def_path(cx, did, &HASHMAP_KEYS) 
+            && (match_def_path(cx, did, &HASHMAP_KEYS)
                 || match_def_path(cx, did, &HASHMAP_VALUES)
                 || match_def_path(cx, did, &HASHSET_ITER_TY)
-                || is_type_diagnostic_item(cx, ty, sym::HashMap) 
+                || is_type_diagnostic_item(cx, ty, sym::HashMap)
                 || is_type_diagnostic_item(cx, ty, sym::HashSet))
         {
             span_lint(
@@ -60,4 +61,3 @@ impl LateLintPass<'_> for IterOverHashType {
         };
     }
 }
-