-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add lint: &mut Commands
function argument
#127
Comments
TIL about reborrow 👀 |
Working on this now! |
I think if we're going to standardize on this via a lint, it would make sense to extend it to all re-borrwable types, including (in 0.15):
Additionally, as raised by @tim-blackbird here, there are some cases where this doesn't make sense. Specifically, immutable references. In some cases, it makes more sense for a helper to take Therefore, we should probably only apply this lint where we are mutably borrowing the type. |
Looks like we'd also need to decide how to handle the |
Do all To my understanding, As an aside, you should be able to determine if a reference is mutable or not using |
Yeah I just wanted to explicitly call it out |
But yeah before I go any further with my implementation, are we at all concerned about not being able to return references using a reborrowed instance? // `EntityCommands<'1>` contains `Commands<'1, '1>`, which is why this example doesn't
// separate the `'w` and `'s` lifetimes. Though any configuration of lifetimes seems
// to result in similar issues.
fn helper<'a, 'b: 'a>(mut commands: Commands<'b, 'b>) -> EntityCommands<'a> {
commands.spawn_empty()
}
The same goes for other types like Do we see this as a reason not to add the lint? Or are these just considered exceptions to the lint? Or perhaps should the lint attempt to check if using a reborrowed parameter would result in the function's return not being possible? I'm not immediately sure how to check that. Anyways, yeah curious to hear others' thoughts on this particular problem. |
I think the lint is still generally useful, so we should definitely keep it, but it should never warn on code that cannot be fixed. For this case, if you cannot guarantee the user will be able to fix the lint, it should not be emitted in the first place. It's much less annoying for a lint to miss a few lintable pieces of code than for a lint to warn on too many pieces of code. To draw this to a conclusion, though, it's ok for the lint to have a few bugs in it! We're both still learning, so it's fine if there's an unaccounted edge case that slips through. Hopefully users will be able to test the linter enough to iron them out. :) |
Makes sense. This is the approach I tried to take in my PR. The goal is that we skip over these "impossible" cases. |
Quoting @ItsDoot in bevyengine/bevy#15657:
We can write a lint that would warn against taking
&mut Commands
in a function! It would probably be in the pedantic category, though.The text was updated successfully, but these errors were encountered: