-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
85 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//! This tests the `borrow_of_reborrowable` lint, specifically when triggered on the `ResMut` type. | ||
#![feature(register_tool)] | ||
#![register_tool(bevy)] | ||
#![deny(bevy::borrow_of_resource)] | ||
|
||
use bevy::prelude::*; | ||
|
||
#[derive(Resource)] | ||
struct Data(String); | ||
|
||
// OK: Lint does not apply to immutable references | ||
fn immutable_reference(_res: &ResMut<Data>) { | ||
// ... | ||
} | ||
|
||
//~| HELP: use `ResMut` instead | ||
//~v ERROR: parameter takes `&mut ResMut` instead of a re-borrowed `ResMut` | ||
fn mutable_reference(_res: &mut ResMut<Data>) { | ||
// ... | ||
} | ||
|
||
//~| HELP: use `ResMut` instead | ||
//~v ERROR: parameter takes `&mut ResMut` instead of a re-borrowed `ResMut` | ||
fn mutable_reference_return<'a>(_res: &'a mut ResMut<Data>) -> usize { | ||
123 | ||
} | ||
|
||
// OK: Lint does not apply when return type relies on reference lifetime | ||
fn mutable_reference_bounded_return<'a>(res: &'a mut ResMut<Data>) -> &'a mut String { | ||
&mut res.0 | ||
} | ||
|
||
// OK: Lint does not apply when return type relies on reference lifetime | ||
fn mutable_reference_bounded_return_complex<'a>( | ||
res: &'a mut ResMut<Data>, | ||
) -> Vec<(usize, &'a mut String)> { | ||
vec![(1, &mut res.0)] | ||
} | ||
|
||
fn main() { | ||
fn some_system(mut res: ResMut<Data>) { | ||
immutable_reference(&res); | ||
mutable_reference(&mut res); | ||
_ = mutable_reference_return(&mut res); | ||
_ = mutable_reference_bounded_return(&mut res); | ||
_ = mutable_reference_bounded_return_complex(&mut res); | ||
} | ||
|
||
App::new().add_systems(Update, some_system).run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
error: parameter takes `&mut ResMut` instead of a re-borrowed `ResMut` | ||
--> tests/ui/borrow_of_reborrowable/resource.rs:19:22 | ||
| | ||
19 | fn mutable_reference(_res: &mut ResMut<Data>) { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: use `ResMut` instead: `mut _res: bevy::prelude::ResMut<'_, Data>` | ||
| | ||
note: the lint level is defined here | ||
--> tests/ui/borrow_of_reborrowable/resource.rs:5:9 | ||
| | ||
5 | #![deny(bevy::borrow_of_resource)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: parameter takes `&mut ResMut` instead of a re-borrowed `ResMut` | ||
--> tests/ui/borrow_of_reborrowable/resource.rs:25:33 | ||
| | ||
25 | fn mutable_reference_return<'a>(_res: &'a mut ResMut<Data>) -> usize { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `ResMut` instead: `mut _res: bevy::prelude::ResMut<'_, Data>` | ||
|
||
error: aborting due to 2 previous errors | ||
|