Skip to content

Commit

Permalink
Handle unused_unit lint differently
Browse files Browse the repository at this point in the history
  • Loading branch information
BoxyUwU committed Jul 23, 2021
1 parent 2ed77d7 commit b17f4aa
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 10 deletions.
3 changes: 1 addition & 2 deletions crates/bevy_ecs/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ macro_rules! tuple_impl {
}

#[allow(unused_variables, unused_mut)]
#[allow(clippy::unused_unit)]
unsafe fn from_components(mut func: impl FnMut() -> *mut u8) -> Self {
#[allow(non_snake_case)]
let ($(mut $name,)*) = (
Expand All @@ -93,7 +92,7 @@ macro_rules! tuple_impl {
}
}

all_tuples!(tuple_impl, 0, 15, C);
all_tuples!(tuple_impl, 1, 15, C);

#[derive(Debug, Clone, Copy)]
pub struct BundleId(usize);
Expand Down
48 changes: 43 additions & 5 deletions crates/bevy_ecs/src/query/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,14 +910,55 @@ impl<'w, T: Component> Fetch<'w> for ChangeTrackersFetch<T> {
}
}

impl<'a> Fetch<'a> for () {
type Item = ();
type State = ();

unsafe fn init(_: &World, _: &Self::State, _: u32, _: u32) -> Self {}
fn is_dense(&self) -> bool {
true
}
unsafe fn set_archetype(&mut self, _: &Self::State, _: &Archetype, _: &Tables) {}
unsafe fn set_table(&mut self, _: &Self::State, _: &Table) {}
unsafe fn archetype_fetch(&mut self, _: usize) -> Self::Item {}
unsafe fn table_fetch(&mut self, _: usize) -> Self::Item {}
}

unsafe impl FetchState for () {
fn init(_: &mut World) -> Self {}

fn update_component_access(&self, _: &mut FilteredAccess<ComponentId>) {}

fn update_archetype_component_access(
&self,
_: &Archetype,
_: &mut Access<ArchetypeComponentId>,
) {
}

fn matches_archetype(&self, _: &Archetype) -> bool {
true
}

fn matches_table(&self, _: &Table) -> bool {
true
}
}

impl WorldQuery for () {
type Fetch = ();
type State = ();
}

unsafe impl ReadOnlyFetch for () {}

macro_rules! impl_tuple_fetch {
($(($name: ident, $state: ident)),*) => {
#[allow(non_snake_case)]
impl<'a, $($name: Fetch<'a>),*> Fetch<'a> for ($($name,)*) {
type Item = ($($name::Item,)*);
type State = ($($name::State,)*);

#[allow(clippy::unused_unit)]
unsafe fn init(_world: &World, state: &Self::State, _last_change_tick: u32, _change_tick: u32) -> Self {
let ($($name,)*) = state;
($($name::init(_world, $name, _last_change_tick, _change_tick),)*)
Expand Down Expand Up @@ -945,14 +986,12 @@ macro_rules! impl_tuple_fetch {
}

#[inline]
#[allow(clippy::unused_unit)]
unsafe fn table_fetch(&mut self, _table_row: usize) -> Self::Item {
let ($($name,)*) = self;
($($name.table_fetch(_table_row),)*)
}

#[inline]
#[allow(clippy::unused_unit)]
unsafe fn archetype_fetch(&mut self, _archetype_index: usize) -> Self::Item {
let ($($name,)*) = self;
($($name.archetype_fetch(_archetype_index),)*)
Expand All @@ -961,7 +1000,6 @@ macro_rules! impl_tuple_fetch {

// SAFETY: update_component_access and update_archetype_component_access are called for each item in the tuple
#[allow(non_snake_case)]
#[allow(clippy::unused_unit)]
unsafe impl<$($name: FetchState),*> FetchState for ($($name,)*) {
fn init(_world: &mut World) -> Self {
($($name::init(_world),)*)
Expand Down Expand Up @@ -999,4 +1037,4 @@ macro_rules! impl_tuple_fetch {
};
}

all_tuples!(impl_tuple_fetch, 0, 15, F, S);
all_tuples!(impl_tuple_fetch, 1, 15, F, S);
4 changes: 2 additions & 2 deletions crates/bevy_ecs/src/schedule/stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1999,7 +1999,7 @@ mod tests {
world.insert_resource(0_usize);
let mut stage = SystemStage::single(query_count_system.system());

let entity = world.spawn().insert_bundle(()).id();
let entity = world.spawn().insert_bundle((1_u8, 1_i8)).id();
stage.run(&mut world);
assert_eq!(*world.get_resource::<usize>().unwrap(), 1);

Expand All @@ -2022,7 +2022,7 @@ mod tests {
let mut stage = SystemStage::parallel();
stage.add_system(query_count_system.system());

let entity = world.spawn().insert_bundle(()).id();
let entity = world.spawn().insert_bundle((1_u8, 1_i8)).id();
stage.run(&mut world);
assert_eq!(*world.get_resource::<usize>().unwrap(), 1);

Expand Down
21 changes: 20 additions & 1 deletion crates/bevy_ecs/src/system/system_param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,25 @@ impl<'a> SystemParamFetch<'a> for SystemChangeTickState {
}
}

impl SystemParam for () {
type Fetch = ();
}

unsafe impl ReadOnlySystemParamFetch for () {}

impl<'a> SystemParamFetch<'a> for () {
type Item = ();

unsafe fn get_param(_: &'a mut Self, _: &SystemMeta, _: &'a World, _: u32) -> Self::Item {}
}

unsafe impl SystemParamState for () {
type Config = ();

fn init(_: &mut World, _: &mut SystemMeta, _: Self::Config) -> Self {}
fn default_config() -> Self::Config {}
}

macro_rules! impl_system_param_tuple {
($($param: ident),*) => {
impl<$($param: SystemParam),*> SystemParam for ($($param,)*) {
Expand Down Expand Up @@ -1201,4 +1220,4 @@ macro_rules! impl_system_param_tuple {
};
}

all_tuples!(impl_system_param_tuple, 0, 16, P);
all_tuples!(impl_system_param_tuple, 1, 16, P);

0 comments on commit b17f4aa

Please sign in to comment.