@@ -20,30 +20,23 @@ pub(super) fn check<'tcx>(
20
20
if_chain ! {
21
21
if let Some ( method_id) = cx. typeck_results( ) . type_dependent_def_id( expr. hir_id) ;
22
22
if let Some ( impl_id) = cx. tcx. impl_of_method( method_id) ;
23
- if cx. tcx. type_of( impl_id) . instantiate_identity( ) . is_slice ( ) ;
23
+ let identity = cx. tcx. type_of( impl_id) . instantiate_identity( ) ;
24
24
if let hir:: ExprKind :: Lit ( Spanned { node: LitKind :: Int ( 0 , _) , .. } ) = arg. kind;
25
25
then {
26
- let mut app = Applicability :: MachineApplicable ;
27
- let slice_name = snippet_with_applicability( cx, recv. span, ".." , & mut app) ;
28
- span_lint_and_sugg(
29
- cx,
30
- GET_FIRST ,
31
- expr. span,
32
- & format!( "accessing first element with `{slice_name}.get(0)`" ) ,
33
- "try" ,
34
- format!( "{slice_name}.first()" ) ,
35
- app,
36
- ) ;
37
- }
38
- }
39
-
40
- if_chain ! {
41
- if let Some ( method_id) = cx. typeck_results( ) . type_dependent_def_id( expr. hir_id) ;
42
- if let Some ( impl_id) = cx. tcx. impl_of_method( method_id) ;
43
- if is_type_diagnostic_item( cx, cx. tcx. type_of( impl_id) . instantiate_identity( ) , sym:: VecDeque ) ;
44
- if let hir:: ExprKind :: Lit ( Spanned { node: LitKind :: Int ( 0 , _) , .. } ) = arg. kind;
45
- then {
46
- let mut app = Applicability :: MachineApplicable ;
26
+ if identity. is_slice( ) {
27
+ let mut app = Applicability :: MachineApplicable ;
28
+ let slice_name = snippet_with_applicability( cx, recv. span, ".." , & mut app) ;
29
+ span_lint_and_sugg(
30
+ cx,
31
+ GET_FIRST ,
32
+ expr. span,
33
+ & format!( "accessing first element with `{slice_name}.get(0)`" ) ,
34
+ "try" ,
35
+ format!( "{slice_name}.first()" ) ,
36
+ app,
37
+ ) ;
38
+ } else if is_type_diagnostic_item( cx, identity, sym:: VecDeque ) {
39
+ let mut app = Applicability :: MachineApplicable ;
47
40
let slice_name = snippet_with_applicability( cx, recv. span, ".." , & mut app) ;
48
41
span_lint_and_sugg(
49
42
cx,
@@ -54,6 +47,7 @@ pub(super) fn check<'tcx>(
54
47
format!( "{slice_name}.front()" ) ,
55
48
app,
56
49
) ;
50
+ }
57
51
}
58
52
}
59
53
}
0 commit comments