Skip to content

Commit 7bc39f3

Browse files
committed
format and fix examples
1 parent cb90674 commit 7bc39f3

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

clippy_lints/src/iter_over_hash_type.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use clippy_utils::paths::{HASHMAP_KEYS, HASHMAP_VALUES, HASHSET_ITER_TY};
2-
use clippy_utils::{diagnostics::span_lint, match_def_path};
1+
use clippy_utils::diagnostics::span_lint;
32
use clippy_utils::higher::ForLoop;
3+
use clippy_utils::match_def_path;
4+
use clippy_utils::paths::{HASHMAP_KEYS, HASHMAP_VALUES, HASHSET_ITER_TY};
45
use clippy_utils::ty::is_type_diagnostic_item;
56
use rustc_lint::{LateContext, LateLintPass};
67
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -18,16 +19,16 @@ declare_clippy_lint! {
1819
///
1920
/// ### Example
2021
/// ```no_run
21-
/// let my_map = new Hashmap<i32, String>();
22+
/// let my_map = std::collections::HashMap::<i32, String>::new();
2223
/// for (key, value) in my_map { /* ... */ }
2324
/// ```
2425
/// Use instead:
2526
/// ```no_run
26-
/// let my_map = new Hashmap<i32, String>();
27-
/// let mut keys = my_map.keys().clone().collect::<Vec<_>();
27+
/// let my_map = std::collections::HashMap::<i32, String>::new();
28+
/// let mut keys = my_map.keys().clone().collect::<Vec<_>>();
2829
/// keys.sort();
2930
/// for key in keys {
30-
/// let value = &my_map[value];
31+
/// let value = &my_map[key];
3132
/// }
3233
/// ```
3334
#[clippy::version = "1.75.0"]
@@ -45,10 +46,10 @@ impl LateLintPass<'_> for IterOverHashType {
4546
&& let ty = cx.typeck_results().expr_ty(for_loop.arg).peel_refs()
4647
&& let Some(adt) = ty.ty_adt_def()
4748
&& let did = adt.did()
48-
&& (match_def_path(cx, did, &HASHMAP_KEYS)
49+
&& (match_def_path(cx, did, &HASHMAP_KEYS)
4950
|| match_def_path(cx, did, &HASHMAP_VALUES)
5051
|| match_def_path(cx, did, &HASHSET_ITER_TY)
51-
|| is_type_diagnostic_item(cx, ty, sym::HashMap)
52+
|| is_type_diagnostic_item(cx, ty, sym::HashMap)
5253
|| is_type_diagnostic_item(cx, ty, sym::HashSet))
5354
{
5455
span_lint(
@@ -60,4 +61,3 @@ impl LateLintPass<'_> for IterOverHashType {
6061
};
6162
}
6263
}
63-

0 commit comments

Comments
 (0)