@@ -111,6 +111,17 @@ fn is_redundant_in_func_call<'tcx>(
111111 false
112112}
113113
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+
114125impl LateLintPass < ' _ > for RedundantTypeAnnotations {
115126 fn check_local < ' tcx > ( & mut self , cx : & LateContext < ' tcx > , local : & ' tcx rustc_hir:: Local < ' tcx > ) {
116127 // type annotation part
@@ -144,14 +155,10 @@ impl LateLintPass<'_> for RedundantTypeAnnotations {
144155 // When the initialization is a path for example u32::MAX
145156 hir:: ExprKind :: Path ( init_path) => {
146157 // 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 )
150159
151160 && 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 )
155162
156163 && primty == primty_init
157164 {
0 commit comments