Skip to content

Commit

Permalink
Add track_caller to App::add_plugins (#9174)
Browse files Browse the repository at this point in the history
# Objective

Currently the panic message if a duplicate plugin is added isn't really
helpful or at least can be made more useful if it includes the location
where the plugin was added a second time.

## Solution

Add `track_caller` to `add_plugins` and it's called dependencies.
  • Loading branch information
MrGunflame authored Jul 23, 2023
1 parent bc8e274 commit 453bd05
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,7 @@ impl App {
/// Panics if one of the plugins was already added to the application.
///
/// [`PluginGroup`]:super::PluginGroup
#[track_caller]
pub fn add_plugins<M>(&mut self, plugins: impl Plugins<M>) -> &mut Self {
plugins.add_to_app(self);
self
Expand Down
3 changes: 3 additions & 0 deletions crates/bevy_app/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ mod sealed {
pub struct PluginsTupleMarker;

impl<P: Plugin> Plugins<PluginMarker> for P {
#[track_caller]
fn add_to_app(self, app: &mut App) {
if let Err(AppError::DuplicatePlugin { plugin_name }) =
app.add_boxed_plugin(Box::new(self))
Expand All @@ -101,6 +102,7 @@ mod sealed {
}

impl<P: PluginGroup> Plugins<PluginGroupMarker> for P {
#[track_caller]
fn add_to_app(self, app: &mut App) {
self.build().finish(app);
}
Expand All @@ -113,6 +115,7 @@ mod sealed {
$($plugins: Plugins<$param>),*
{
#[allow(non_snake_case, unused_variables)]
#[track_caller]
fn add_to_app(self, app: &mut App) {
let ($($plugins,)*) = self;
$($plugins.add_to_app(app);)*
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_app/src/plugin_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ impl PluginGroupBuilder {
/// # Panics
///
/// Panics if one of the plugin in the group was already added to the application.
#[track_caller]
pub fn finish(mut self, app: &mut App) {
for ty in &self.order {
if let Some(entry) = self.plugins.remove(ty) {
Expand Down

0 comments on commit 453bd05

Please sign in to comment.