@@ -2,14 +2,14 @@ use clippy_config::msrvs::{self, Msrv};
2
2
use clippy_config:: Conf ;
3
3
use clippy_utils:: diagnostics:: span_lint_and_sugg;
4
4
use clippy_utils:: source:: snippet;
5
- use clippy_utils:: ty:: { is_type_diagnostic_item , is_type_lang_item} ;
5
+ use clippy_utils:: ty:: { get_type_diagnostic_name , is_type_lang_item} ;
6
6
use clippy_utils:: { match_def_path, paths, SpanlessEq } ;
7
7
use rustc_errors:: Applicability ;
8
8
use rustc_hir as hir;
9
9
use rustc_hir:: def_id:: DefId ;
10
10
use rustc_hir:: ExprKind :: Assign ;
11
11
use rustc_lint:: { LateContext , LateLintPass } ;
12
- use rustc_session:: { impl_lint_pass, RustcVersion } ;
12
+ use rustc_session:: impl_lint_pass;
13
13
use rustc_span:: symbol:: sym;
14
14
use rustc_span:: Span ;
15
15
@@ -20,16 +20,6 @@ const ACCEPTABLE_METHODS: [&[&str]; 5] = [
20
20
& paths:: SLICE_INTO ,
21
21
& paths:: VEC_DEQUE_ITER ,
22
22
] ;
23
- const ACCEPTABLE_TYPES : [ ( rustc_span:: Symbol , Option < RustcVersion > ) ; 7 ] = [
24
- ( sym:: BinaryHeap , Some ( msrvs:: BINARY_HEAP_RETAIN ) ) ,
25
- ( sym:: BTreeSet , Some ( msrvs:: BTREE_SET_RETAIN ) ) ,
26
- ( sym:: BTreeMap , Some ( msrvs:: BTREE_MAP_RETAIN ) ) ,
27
- ( sym:: HashSet , Some ( msrvs:: HASH_SET_RETAIN ) ) ,
28
- ( sym:: HashMap , Some ( msrvs:: HASH_MAP_RETAIN ) ) ,
29
- ( sym:: Vec , None ) ,
30
- ( sym:: VecDeque , None ) ,
31
- ] ;
32
- const MAP_TYPES : [ rustc_span:: Symbol ; 2 ] = [ sym:: BTreeMap , sym:: HashMap ] ;
33
23
34
24
declare_clippy_lint ! {
35
25
/// ### What it does
@@ -264,16 +254,22 @@ fn match_acceptable_def_path(cx: &LateContext<'_>, collect_def_id: DefId) -> boo
264
254
}
265
255
266
256
fn match_acceptable_type ( cx : & LateContext < ' _ > , expr : & hir:: Expr < ' _ > , msrv : & Msrv ) -> bool {
267
- let expr_ty = cx. typeck_results ( ) . expr_ty ( expr) . peel_refs ( ) ;
268
- ACCEPTABLE_TYPES . iter ( ) . any ( |( ty, acceptable_msrv) | {
269
- is_type_diagnostic_item ( cx, expr_ty, * ty)
270
- && acceptable_msrv. map_or ( true , |acceptable_msrv| msrv. meets ( acceptable_msrv) )
271
- } )
257
+ let ty = cx. typeck_results ( ) . expr_ty ( expr) . peel_refs ( ) ;
258
+ let required = match get_type_diagnostic_name ( cx, ty) {
259
+ Some ( sym:: BinaryHeap ) => msrvs:: BINARY_HEAP_RETAIN ,
260
+ Some ( sym:: BTreeSet ) => msrvs:: BTREE_SET_RETAIN ,
261
+ Some ( sym:: BTreeMap ) => msrvs:: BTREE_MAP_RETAIN ,
262
+ Some ( sym:: HashSet ) => msrvs:: HASH_SET_RETAIN ,
263
+ Some ( sym:: HashMap ) => msrvs:: HASH_MAP_RETAIN ,
264
+ Some ( sym:: Vec | sym:: VecDeque ) => return true ,
265
+ _ => return false ,
266
+ } ;
267
+ msrv. meets ( required)
272
268
}
273
269
274
270
fn match_map_type ( cx : & LateContext < ' _ > , expr : & hir:: Expr < ' _ > ) -> bool {
275
- let expr_ty = cx. typeck_results ( ) . expr_ty ( expr) . peel_refs ( ) ;
276
- MAP_TYPES . iter ( ) . any ( |ty| is_type_diagnostic_item ( cx, expr_ty , * ty ) )
271
+ let ty = cx. typeck_results ( ) . expr_ty ( expr) . peel_refs ( ) ;
272
+ matches ! ( get_type_diagnostic_name ( cx, ty ) , Some ( sym :: BTreeMap | sym :: HashMap ) )
277
273
}
278
274
279
275
fn make_span_lint_and_sugg ( cx : & LateContext < ' _ > , span : Span , sugg : String ) {
0 commit comments