Skip to content

Commit

Permalink
Add support for NonSendMut
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGVSV committed Nov 2, 2024
1 parent bf99294 commit 27f9c87
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
12 changes: 8 additions & 4 deletions bevy_lint/src/lints/borrow_of_reborrowable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ use rustc_span::{def_id::LocalDefId, symbol::Ident, Span};
declare_bevy_lint! {
pub BORROW_OF_COMMANDS,
PEDANTIC,
"parameter takes `&mut Commands` instead of a re-borrowed `Commands`",
"parameter takes a mutable reference to `Commands` or `EntityCommands` instead of a re-borrowed instance",
}

declare_bevy_lint! {
pub BORROW_OF_RESOURCE,
PEDANTIC,
"parameter takes `&mut ResMut` instead of a re-borrowed `ResMut`",
"parameter takes a mutable reference to `ResMut` or `NonSendMut` instead of a re-borrowed instance",
}

declare_bevy_lint! {
pub BORROW_OF_QUERY,
PEDANTIC,
"parameter takes `&mut Query` instead of a re-borrowed `Query`",
"parameter takes a mutable reference to `Query` instead of a re-borrowed instance",
}

declare_lint_pass! {
Expand Down Expand Up @@ -149,7 +149,7 @@ enum Reborrowable {
// FilteredResourcesMut,
// Mut,
// MutUntyped,
// NonSendMut,
NonSendMut,
// PtrMut,
Query,
// QueryIterationCursor,
Expand All @@ -166,6 +166,8 @@ impl Reborrowable {
Some(Self::Query)
} else if match_type(cx, ty, &crate::paths::RES_MUT) {
Some(Self::ResMut)
} else if match_type(cx, ty, &crate::paths::NON_SEND_MUT) {
Some(Self::NonSendMut)
} else {
None
}
Expand All @@ -177,6 +179,7 @@ impl Reborrowable {
Self::EntityCommands => BORROW_OF_COMMANDS.lint,
Self::Query => BORROW_OF_QUERY.lint,
Self::ResMut => BORROW_OF_RESOURCE.lint,
Self::NonSendMut => BORROW_OF_RESOURCE.lint,
}
}

Expand All @@ -191,6 +194,7 @@ impl Reborrowable {
Self::EntityCommands => "EntityCommands",
Self::Query => "Query",
Self::ResMut => "ResMut",
Self::NonSendMut => "NonSendMut",
}
}

Expand Down
1 change: 1 addition & 0 deletions bevy_lint/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub const ENTITY_COMMANDS: [&str; 4] = ["bevy_ecs", "system", "commands", "Entit
// Note that this moves to `bevy_ecs::event::base::Event` in 0.15.
pub const EVENT: [&str; 3] = ["bevy_ecs", "event", "Event"];
pub const EVENTS: [&str; 3] = ["bevy_ecs", "event", "Events"];
pub const NON_SEND_MUT: [&str; 3] = ["bevy_ecs", "change_detection", "NonSendMut"];
pub const PLUGIN: [&str; 3] = ["bevy_app", "plugin", "Plugin"];
pub const QUERY: [&str; 4] = ["bevy_ecs", "system", "query", "Query"];
pub const QUERY_STATE: [&str; 4] = ["bevy_ecs", "query", "state", "QueryState"];
Expand Down

0 comments on commit 27f9c87

Please sign in to comment.