Skip to content

Conversation

shoobooshooboo
Copy link
Contributor

@shoobooshooboo shoobooshooboo commented Sep 13, 2025

Objective

Attempts #5386

Solution

Added the must_use attribute to bevy::app::App

Testing

I tested it by linking the library to another cargo package and calling App::new() without using the return value.

(this is my first pr, so i just chose something very easy.)

Copy link
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@alice-i-cecile alice-i-cecile added C-Usability A targeted quality-of-life change that makes Bevy easier to use A-App Bevy apps and plugins D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 13, 2025
@mockersf
Copy link
Member

This doesn't fix #5386

If you add plugins but still don't call .run(), it won't issue a warning

@shoobooshooboo
Copy link
Contributor Author

thanks for the feedback! I'll look into this now

@mockersf
Copy link
Member

The base issue is not really trivial in my opinion. This PR is good and could be merged as is, but it shouldn't say it fixes the issue as that will close it.

You can spend some time to investigate in this PR if you want, or you can edit the description and we can merge this now while you investigate with another PR

@shoobooshooboo
Copy link
Contributor Author

So I found the obvious solution of just marking all of the App functions that return &mut Self as must_use, but I was wondering if this is actually a good solution. The original purpose of giving App the must_use trait was for cases like the following:

App::new()
.add_plugins(DefaultPlugins)
.insert_resource(MyResource::Default())
.run();

The point is to give us a warning if we ever forget the last line. But this doesn't support the other, completely valid use which is more along the lines of

let app = App::new();
app.add_plugins(DefaultPlugins);
app.insert_resource(MyResource::Default());
app.run();

Because in this case, it'll warn us on both of those middle lines if we don't put let _ = before them.
I have an idea for how I could let the user know they forgot to run the app, but it would involve a runtime check so it'd have to be a panic! instead of a warning. My idea also accounts for allowing an app to not run if you so choose. Should I draft up this idea or is a panic! too strict?

@alice-i-cecile
Copy link
Member

alice-i-cecile commented Sep 13, 2025

Hmm, yeah, I don't think we should break the multi-line pattern.

I'm a bit skeptical of the panic idea: I think that it's a lot of complexity and risk to solve a beginner footgun.

Simply marking App as must_use is better than nothing though, so I feel like we should merge this PR.

@mockersf
Copy link
Member

no panic for me: the idea is to warn the user in their IDE, they'll notice soon enough that nothing happens when they run it

@shoobooshooboo
Copy link
Contributor Author

alright, sounds good. I'll edit the description to remove the fix. Thanks for the good feedback!

@mockersf mockersf added this pull request to the merge queue Sep 14, 2025
Merged via the queue into bevyengine:main with commit 3d72fa5 Sep 14, 2025
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-App Bevy apps and plugins C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants