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;
3
2
use clippy_utils:: higher:: ForLoop ;
3
+ use clippy_utils:: match_def_path;
4
+ use clippy_utils:: paths:: { HASHMAP_KEYS , HASHMAP_VALUES , HASHSET_ITER_TY } ;
4
5
use clippy_utils:: ty:: is_type_diagnostic_item;
5
6
use rustc_lint:: { LateContext , LateLintPass } ;
6
7
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
@@ -18,16 +19,16 @@ declare_clippy_lint! {
18
19
///
19
20
/// ### Example
20
21
/// ```no_run
21
- /// let my_map = new Hashmap <i32, String>();
22
+ /// let my_map = std::collections::HashMap:: <i32, String>::new ();
22
23
/// for (key, value) in my_map { /* ... */ }
23
24
/// ```
24
25
/// Use instead:
25
26
/// ```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<_>> ();
28
29
/// keys.sort();
29
30
/// for key in keys {
30
- /// let value = &my_map[value ];
31
+ /// let value = &my_map[key ];
31
32
/// }
32
33
/// ```
33
34
#[ clippy:: version = "1.75.0" ]
@@ -45,10 +46,10 @@ impl LateLintPass<'_> for IterOverHashType {
45
46
&& let ty = cx. typeck_results ( ) . expr_ty ( for_loop. arg ) . peel_refs ( )
46
47
&& let Some ( adt) = ty. ty_adt_def ( )
47
48
&& let did = adt. did ( )
48
- && ( match_def_path ( cx, did, & HASHMAP_KEYS )
49
+ && ( match_def_path ( cx, did, & HASHMAP_KEYS )
49
50
|| match_def_path ( cx, did, & HASHMAP_VALUES )
50
51
|| 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 )
52
53
|| is_type_diagnostic_item ( cx, ty, sym:: HashSet ) )
53
54
{
54
55
span_lint (
@@ -60,4 +61,3 @@ impl LateLintPass<'_> for IterOverHashType {
60
61
} ;
61
62
}
62
63
}
63
-
0 commit comments