@@ -23,19 +23,32 @@ pub(super) fn check(
23
23
if let Some ( last) = last_path_segment ( qpath) . args
24
24
// Get the _ part of Vec<_>
25
25
&& let Some ( GenericArg :: Type ( ty) ) = last. args . first ( )
26
+ // extract allocator from the Vec for later
27
+ && let vec_alloc_ty = last. args . get ( 1 )
26
28
// ty is now _ at this point
27
29
&& let TyKind :: Path ( ref ty_qpath) = ty. kind
28
30
&& let res = cx. qpath_res ( ty_qpath, ty. hir_id )
29
31
&& let Some ( def_id) = res. opt_def_id ( )
30
32
&& Some ( def_id) == cx. tcx . lang_items ( ) . owned_box ( )
31
33
// At this point, we know ty is Box<T>, now get T
32
34
&& let Some ( last) = last_path_segment ( ty_qpath) . args
35
+ // extract allocator from thr Box for later
33
36
&& let Some ( GenericArg :: Type ( boxed_ty) ) = last. args . first ( )
37
+ && let boxed_alloc_ty = last. args . get ( 1 )
34
38
&& let ty_ty = hir_ty_to_ty ( cx. tcx , boxed_ty)
35
39
&& !ty_ty. has_escaping_bound_vars ( )
36
40
&& ty_ty. is_sized ( cx. tcx , cx. param_env )
37
41
&& let Ok ( ty_ty_size) = cx. layout_of ( ty_ty) . map ( |l| l. size . bytes ( ) )
38
42
&& ty_ty_size < box_size_threshold
43
+ // https://github.com/rust-lang/rust-clippy/issues/7114
44
+ // this code also does not consider that Global can be explicitly
45
+ // defined (yet) as in Vec<_, Global> so a very slight false negative edge case
46
+ && match ( vec_alloc_ty, boxed_alloc_ty) {
47
+ ( None , None ) => true ,
48
+ ( Some ( GenericArg :: Type ( l) ) , Some ( GenericArg :: Type ( r) ) ) =>
49
+ hir_ty_to_ty ( cx. tcx , l) == hir_ty_to_ty ( cx. tcx , r) ,
50
+ _ => false
51
+ }
39
52
{
40
53
span_lint_and_sugg (
41
54
cx,
@@ -53,4 +66,4 @@ pub(super) fn check(
53
66
} else {
54
67
false
55
68
}
56
- }
69
+ }
0 commit comments