1
1
use crate :: utils:: { last_path_segment, match_def_path, paths, snippet, span_lint_and_sugg} ;
2
- use rustc_hir:: { GenericArg , Local , Mutability , TyKind } ;
2
+ use rustc_hir:: { GenericArg , Local , Mutability , Ty , TyKind } ;
3
3
use rustc_lint:: { LateContext , LateLintPass } ;
4
4
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
5
5
@@ -34,12 +34,20 @@ declare_lint_pass!(RefOptionRef => [REF_OPTION_REF]);
34
34
35
35
impl < ' tcx > LateLintPass < ' tcx > for RefOptionRef {
36
36
fn check_local ( & mut self , cx : & LateContext < ' tcx > , local : & ' tcx Local < ' _ > ) {
37
+
38
+ if let Some ( ref ty) = local. ty {
39
+ self . check_ref_option_ref ( cx, ty) ;
40
+ }
41
+ }
42
+ }
43
+
44
+ impl RefOptionRef {
45
+ fn check_ref_option_ref ( & self , cx : & LateContext < ' tcx > , ty : & ' tcx Ty < ' tcx > ) {
37
46
if_chain ! {
38
- if let Some ( ref ty) = local. ty;
39
47
if let TyKind :: Rptr ( _, ref mut_ty) = ty. kind;
40
48
if mut_ty. mutbl == Mutability :: Not ;
41
49
if let TyKind :: Path ( ref qpath) = & mut_ty. ty. kind ;
42
- if let Some ( def_id) = cx. typeck_results( ) . qpath_res( qpath, local . hir_id) . opt_def_id( ) ;
50
+ if let Some ( def_id) = cx. typeck_results( ) . qpath_res( qpath, ty . hir_id) . opt_def_id( ) ;
43
51
if match_def_path( cx, def_id, & paths:: OPTION ) ;
44
52
if let Some ( ref params) = last_path_segment( qpath) . args ;
45
53
if !params. parenthesized;
@@ -57,9 +65,9 @@ impl<'tcx> LateLintPass<'tcx> for RefOptionRef {
57
65
"since & implements Copy trait, &Option<&T> can be simplifyied into Option<&T>" ,
58
66
"try" ,
59
67
format!( "Option<{}>" , & snippet( cx, inner_ty. span, ".." ) ) ,
60
- Applicability :: MachineApplicable ,
68
+ Applicability :: Unspecified ,
61
69
) ;
62
70
}
63
71
}
64
72
}
65
- }
73
+ }
0 commit comments