Skip to content

Commit ba04cc2

Browse files
committed
Refactor Further
1 parent 59d9aa3 commit ba04cc2

File tree

1 file changed

+61
-54
lines changed

1 file changed

+61
-54
lines changed

crates/bevy_lint/src/unnecessary_with.rs

Lines changed: 61 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -51,82 +51,89 @@ impl<'hir> LateLintPass<'hir> for UnnecessaryWith {
5151
for typ in decl.inputs {
5252
if let TyKind::Path(QPath::Resolved(_, path)) = &typ.kind {
5353
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);
5955
}
6056
}
6157
}
6258
}
6359
}
6460

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();
6865

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+
}
7371
}
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+
}
8079
}
8180
}
8281
}
82+
_ => (),
8383
}
84-
_ => (),
85-
}
8684

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));
9589
}
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));
10393
}
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));
109101
}
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+
}
114121
}
115122
}
116123
}
117124
}
125+
_ => (),
118126
}
119-
_ => (),
120-
}
121127

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+
}
130137
}
131138
}
132139
}

0 commit comments

Comments
 (0)