Skip to content

Commit 1f6a429

Browse files
committed
Add support for EntityCommands
1 parent 6a70b5a commit 1f6a429

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

bevy_lint/src/lints/borrow_of_reborrowable.rs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,28 @@ impl<'tcx> LateLintPass<'tcx> for BorrowOfReborrowable {
134134
#[derive(Debug)]
135135
enum Reborrowable {
136136
Commands,
137+
// Deferred,
138+
// DeferredWorld,
139+
EntityCommands,
140+
// EntityMut,
141+
// EntityMutExcept,
142+
// FilteredEntityMut,
143+
// FilteredResourcesMut,
144+
// Mut,
145+
// MutUntyped,
146+
// NonSendMut,
147+
// PtrMut,
137148
Query,
149+
// QueryIterationCursor,
150+
// ResMut,
138151
}
139152

140153
impl Reborrowable {
141154
fn try_from_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<Self> {
142155
if match_type(cx, ty, &crate::paths::COMMANDS) {
143156
Some(Self::Commands)
157+
} else if match_type(cx, ty, &crate::paths::ENTITY_COMMANDS) {
158+
Some(Self::EntityCommands)
144159
} else if match_type(cx, ty, &crate::paths::QUERY) {
145160
Some(Self::Query)
146161
} else {
@@ -151,30 +166,31 @@ impl Reborrowable {
151166
fn lint(&self) -> &'static Lint {
152167
match self {
153168
Self::Commands => BORROW_OF_COMMANDS.lint,
169+
Self::EntityCommands => BORROW_OF_COMMANDS.lint,
154170
Self::Query => BORROW_OF_QUERY.lint,
155171
}
156172
}
157173

158-
fn message(&self) -> &'static str {
159-
match self {
160-
Self::Commands => BORROW_OF_COMMANDS.lint.desc,
161-
Self::Query => BORROW_OF_QUERY.lint.desc,
162-
}
174+
fn message(&self) -> String {
175+
let name = self.name();
176+
format!("parameter takes `&mut {name}` instead of a re-borrowed `{name}`",)
163177
}
164178

165179
fn name(&self) -> &'static str {
166180
match self {
167181
Self::Commands => "Commands",
182+
Self::EntityCommands => "EntityCommands",
168183
Self::Query => "Query",
169184
}
170185
}
171186

172187
fn help(&self) -> String {
173-
format!("use `{}` instead", self.name())
188+
let name = self.name();
189+
format!("use `{name}` instead")
174190
}
175191

176192
fn suggest(&self, ident: Ident, ty: String) -> String {
177-
format!("mut {}: {}", ident, ty)
193+
format!("mut {ident}: {ty}")
178194
}
179195
}
180196

bevy_lint/src/paths.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
pub const APP: [&str; 3] = ["bevy_app", "app", "App"];
1010
pub const COMMANDS: [&str; 4] = ["bevy_ecs", "system", "commands", "Commands"];
1111
pub const COMPONENT: [&str; 3] = ["bevy_ecs", "component", "Component"];
12+
pub const ENTITY_COMMANDS: [&str; 4] = ["bevy_ecs", "system", "commands", "EntityCommands"];
1213
// Note that this moves to `bevy_ecs::event::base::Event` in 0.15.
1314
pub const EVENT: [&str; 3] = ["bevy_ecs", "event", "Event"];
1415
pub const EVENTS: [&str; 3] = ["bevy_ecs", "event", "Events"];

0 commit comments

Comments
 (0)