@@ -111,6 +111,17 @@ fn is_redundant_in_func_call<'tcx>(
111
111
false
112
112
}
113
113
114
+ fn extract_primty < ' tcx > ( ty_kind : & hir:: TyKind < ' tcx > ) -> Option < hir:: PrimTy > {
115
+ if let hir:: TyKind :: Path ( ty_path) = ty_kind
116
+ && let hir:: QPath :: Resolved ( _, resolved_path_ty) = ty_path
117
+ && let hir:: def:: Res :: PrimTy ( primty) = resolved_path_ty. res
118
+ {
119
+ Some ( primty)
120
+ } else {
121
+ None
122
+ }
123
+ }
124
+
114
125
impl LateLintPass < ' _ > for RedundantTypeAnnotations {
115
126
fn check_local < ' tcx > ( & mut self , cx : & LateContext < ' tcx > , local : & ' tcx rustc_hir:: Local < ' tcx > ) {
116
127
// type annotation part
@@ -144,14 +155,10 @@ impl LateLintPass<'_> for RedundantTypeAnnotations {
144
155
// When the initialization is a path for example u32::MAX
145
156
hir:: ExprKind :: Path ( init_path) => {
146
157
// TODO: check for non primty
147
- if let hir:: TyKind :: Path ( ty_path) = & ty. kind
148
- && let hir:: QPath :: Resolved ( _, resolved_path_ty) = ty_path
149
- && let hir:: def:: Res :: PrimTy ( primty) = resolved_path_ty. res
158
+ if let Some ( primty) = extract_primty ( & ty. kind )
150
159
151
160
&& let hir:: QPath :: TypeRelative ( init_ty, _) = init_path
152
- && let hir:: TyKind :: Path ( init_ty_path) = & init_ty. kind
153
- && let hir:: QPath :: Resolved ( _, resolved_init_ty_path) = init_ty_path
154
- && let hir:: def:: Res :: PrimTy ( primty_init) = resolved_init_ty_path. res
161
+ && let Some ( primty_init) = extract_primty ( & init_ty. kind )
155
162
156
163
&& primty == primty_init
157
164
{
0 commit comments