@@ -51,82 +51,89 @@ impl<'hir> LateLintPass<'hir> for UnnecessaryWith {
51
51
for typ in decl. inputs {
52
52
if let TyKind :: Path ( QPath :: Resolved ( _, path) ) = & typ. kind {
53
53
if bevy_helpers:: path_matches_symbol_path ( ctx, path, bevy_paths:: QUERY ) {
54
- if let Some ( ( world, Some ( filter) ) ) =
55
- bevy_helpers:: get_generics_of_query ( ctx, & typ)
56
- {
57
- check_for_overlap ( ctx, world, filter) ;
58
- }
54
+ check_for_unnecesarry_with ( ctx, & typ) ;
59
55
}
60
56
}
61
57
}
62
58
}
63
59
}
64
60
65
- fn check_for_overlap < ' hir > ( ctx : & LateContext < ' hir > , world : & Ty , filter : & Ty ) {
66
- let mut required_types = Vec :: new ( ) ;
67
- let mut with_types = Vec :: new ( ) ;
61
+ fn check_for_unnecesarry_with < ' hir > ( ctx : & LateContext < ' hir > , query : & ' hir Ty ) {
62
+ if let Some ( ( world, Some ( filter) ) ) = bevy_helpers:: get_generics_of_query ( ctx, query) {
63
+ let mut required_types = Vec :: new ( ) ;
64
+ let mut with_types = Vec :: new ( ) ;
68
65
69
- match & world. kind {
70
- TyKind :: Rptr ( _, mut_type) => {
71
- if let Some ( def_id) = bevy_helpers:: get_def_id_of_referenced_type ( & mut_type) {
72
- required_types. push ( def_id) ;
66
+ match & world. kind {
67
+ TyKind :: Rptr ( _, mut_type) => {
68
+ if let Some ( def_id) = bevy_helpers:: get_def_id_of_referenced_type ( & mut_type) {
69
+ required_types. push ( def_id) ;
70
+ }
73
71
}
74
- }
75
- TyKind :: Tup ( types) => {
76
- for typ in * types {
77
- if let TyKind :: Rptr ( _, mut_type) = & typ. kind {
78
- if let Some ( def_id) = bevy_helpers:: get_def_id_of_referenced_type ( & mut_type) {
79
- required_types. push ( def_id) ;
72
+ TyKind :: Tup ( types) => {
73
+ for typ in * types {
74
+ if let TyKind :: Rptr ( _, mut_type) = & typ. kind {
75
+ if let Some ( def_id) = bevy_helpers:: get_def_id_of_referenced_type ( & mut_type)
76
+ {
77
+ required_types. push ( def_id) ;
78
+ }
80
79
}
81
80
}
82
81
}
82
+ _ => ( ) ,
83
83
}
84
- _ => ( ) ,
85
- }
86
84
87
- match & filter. kind {
88
- TyKind :: Path ( QPath :: Resolved ( _, path) ) => {
89
- if bevy_helpers:: path_matches_symbol_path ( ctx, path, bevy_paths:: OR ) {
90
- with_types. extend ( check_or_filter ( ctx, path) ) ;
91
- }
92
- if bevy_helpers:: path_matches_symbol_path ( ctx, path, bevy_paths:: WITH ) {
93
- if let Some ( def_id) = bevy_helpers:: get_def_id_of_first_generic_arg ( path) {
94
- with_types. push ( ( def_id, filter. span ) ) ;
85
+ match & filter. kind {
86
+ TyKind :: Path ( QPath :: Resolved ( _, path) ) => {
87
+ if bevy_helpers:: path_matches_symbol_path ( ctx, path, bevy_paths:: OR ) {
88
+ with_types. extend ( check_or_filter ( ctx, path) ) ;
95
89
}
96
- }
97
- }
98
- TyKind :: Tup ( types) => {
99
- for typ in * types {
100
- if let TyKind :: Path ( QPath :: Resolved ( _, path) ) = typ. kind {
101
- if bevy_helpers:: path_matches_symbol_path ( ctx, path, bevy_paths:: OR ) {
102
- with_types. extend ( check_or_filter ( ctx, path) ) ;
90
+ if bevy_helpers:: path_matches_symbol_path ( ctx, path, bevy_paths:: WITH ) {
91
+ if let Some ( def_id) = bevy_helpers:: get_def_id_of_first_generic_arg ( path) {
92
+ with_types. push ( ( def_id, filter. span ) ) ;
103
93
}
104
- if bevy_helpers:: path_matches_symbol_path ( ctx, path, bevy_paths:: ADDED )
105
- || bevy_helpers:: path_matches_symbol_path ( ctx, path, bevy_paths:: CHANGED )
106
- {
107
- if let Some ( def_id) = bevy_helpers:: get_def_id_of_first_generic_arg ( path) {
108
- required_types. push ( def_id) ;
94
+ }
95
+ }
96
+ TyKind :: Tup ( types) => {
97
+ for typ in * types {
98
+ if let TyKind :: Path ( QPath :: Resolved ( _, path) ) = typ. kind {
99
+ if bevy_helpers:: path_matches_symbol_path ( ctx, path, bevy_paths:: OR ) {
100
+ with_types. extend ( check_or_filter ( ctx, path) ) ;
109
101
}
110
- }
111
- if bevy_helpers:: path_matches_symbol_path ( ctx, path, bevy_paths:: WITH ) {
112
- if let Some ( def_id) = bevy_helpers:: get_def_id_of_first_generic_arg ( path) {
113
- with_types. push ( ( def_id, typ. span ) ) ;
102
+ if bevy_helpers:: path_matches_symbol_path ( ctx, path, bevy_paths:: ADDED )
103
+ || bevy_helpers:: path_matches_symbol_path (
104
+ ctx,
105
+ path,
106
+ bevy_paths:: CHANGED ,
107
+ )
108
+ {
109
+ if let Some ( def_id) =
110
+ bevy_helpers:: get_def_id_of_first_generic_arg ( path)
111
+ {
112
+ required_types. push ( def_id) ;
113
+ }
114
+ }
115
+ if bevy_helpers:: path_matches_symbol_path ( ctx, path, bevy_paths:: WITH ) {
116
+ if let Some ( def_id) =
117
+ bevy_helpers:: get_def_id_of_first_generic_arg ( path)
118
+ {
119
+ with_types. push ( ( def_id, typ. span ) ) ;
120
+ }
114
121
}
115
122
}
116
123
}
117
124
}
125
+ _ => ( ) ,
118
126
}
119
- _ => ( ) ,
120
- }
121
127
122
- for with_type in with_types {
123
- if required_types. contains ( & with_type. 0 ) {
124
- span_lint (
125
- ctx,
126
- UNNECESSARY_WITH ,
127
- with_type. 1 ,
128
- "Unnecessary `With` Filter" ,
129
- ) ;
128
+ for with_type in with_types {
129
+ if required_types. contains ( & with_type. 0 ) {
130
+ span_lint (
131
+ ctx,
132
+ UNNECESSARY_WITH ,
133
+ with_type. 1 ,
134
+ "Unnecessary `With` Filter" ,
135
+ ) ;
136
+ }
130
137
}
131
138
}
132
139
}
0 commit comments