Skip to content

Commit

Permalink
Do It
Browse files Browse the repository at this point in the history
  • Loading branch information
BoxyUwU committed Oct 24, 2022
1 parent 45e5eb1 commit 32d4125
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 310 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_core_pipeline/src/core_2d/camera_2d.rs
Expand Up @@ -19,7 +19,7 @@ impl ExtractComponent for Camera2d {
type Query = &'static Self;
type Filter = With<Camera>;

fn extract_component(item: QueryItem<Self::Query>) -> Self {
fn extract_component(item: QueryItem<'_, Self::Query>) -> Self {
item.clone()
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_core_pipeline/src/core_3d/camera_3d.rs
Expand Up @@ -51,7 +51,7 @@ impl ExtractComponent for Camera3d {
type Query = &'static Self;
type Filter = With<Camera>;

fn extract_component(item: QueryItem<Self::Query>) -> Self {
fn extract_component(item: QueryItem<'_, Self::Query>) -> Self {
item.clone()
}
}
Expand Down
35 changes: 15 additions & 20 deletions crates/bevy_ecs/macros/src/fetch.rs
Expand Up @@ -182,34 +182,29 @@ pub fn derive_world_query_impl(ast: DeriveInput) -> TokenStream {
#derive_macro_call
#[automatically_derived]
#visibility struct #item_struct_name #user_impl_generics_with_world #user_where_clauses_with_world {
#(#(#field_attrs)* #field_visibilities #field_idents: <#field_types as #path::query::WorldQueryGats<'__w>>::Item,)*
#(#(#field_attrs)* #field_visibilities #field_idents: <#field_types as #path::query::WorldQuery>::Item<'__w>,)*
#(#(#ignored_field_attrs)* #ignored_field_visibilities #ignored_field_idents: #ignored_field_types,)*
}

#[derive(Clone)]
#[doc(hidden)]
#visibility struct #fetch_struct_name #user_impl_generics_with_world #user_where_clauses_with_world {
#(#field_idents: <#field_types as #path::query::WorldQueryGats<'__w>>::Fetch,)*
#(#field_idents: <#field_types as #path::query::WorldQuery>::Fetch<'__w>,)*
#(#ignored_field_idents: #ignored_field_types,)*
}

// SAFETY: `update_component_access` and `update_archetype_component_access` are called on every field

impl #user_impl_generics_with_world #path::query::WorldQueryGats<'__w>
for #struct_name #user_ty_generics #user_where_clauses {
type Item = #item_struct_name #user_ty_generics_with_world;
type Fetch = #fetch_struct_name #user_ty_generics_with_world;
}

unsafe impl #user_impl_generics #path::query::WorldQuery
for #struct_name #user_ty_generics #user_where_clauses {

type Item<'__w> = #item_struct_name #user_ty_generics_with_world;
type Fetch<'__w> = #fetch_struct_name #user_ty_generics_with_world;
type ReadOnly = #read_only_struct_name #user_ty_generics;
type State = #state_struct_name #user_ty_generics;

fn shrink<'__wlong: '__wshort, '__wshort>(
item: <#struct_name #user_ty_generics as #path::query::WorldQueryGats<'__wlong>>::Item
) -> <#struct_name #user_ty_generics as #path::query::WorldQueryGats<'__wshort>>::Item {
item: <#struct_name #user_ty_generics as #path::query::WorldQuery>::Item<'__wlong>
) -> <#struct_name #user_ty_generics as #path::query::WorldQuery>::Item<'__wshort> {
#item_struct_name {
#(
#field_idents: <#field_types>::shrink(item.#field_idents),
Expand All @@ -225,7 +220,7 @@ pub fn derive_world_query_impl(ast: DeriveInput) -> TokenStream {
state: &Self::State,
_last_change_tick: u32,
_change_tick: u32
) -> <Self as #path::query::WorldQueryGats<'__w>>::Fetch {
) -> <Self as #path::query::WorldQuery>::Fetch<'__w> {
#fetch_struct_name {
#(#field_idents:
<#field_types>::init_fetch(
Expand All @@ -246,7 +241,7 @@ pub fn derive_world_query_impl(ast: DeriveInput) -> TokenStream {
/// SAFETY: we call `set_archetype` for each member that implements `Fetch`
#[inline]
unsafe fn set_archetype<'__w>(
_fetch: &mut <Self as #path::query::WorldQueryGats<'__w>>::Fetch,
_fetch: &mut <Self as #path::query::WorldQuery>::Fetch<'__w>,
_state: &Self::State,
_archetype: &'__w #path::archetype::Archetype,
_tables: &'__w #path::storage::Tables
Expand All @@ -257,7 +252,7 @@ pub fn derive_world_query_impl(ast: DeriveInput) -> TokenStream {
/// SAFETY: we call `set_table` for each member that implements `Fetch`
#[inline]
unsafe fn set_table<'__w>(
_fetch: &mut <Self as #path::query::WorldQueryGats<'__w>>::Fetch,
_fetch: &mut <Self as #path::query::WorldQuery>::Fetch<'__w>,
_state: &Self::State,
_table: &'__w #path::storage::Table
) {
Expand All @@ -267,9 +262,9 @@ pub fn derive_world_query_impl(ast: DeriveInput) -> TokenStream {
/// SAFETY: we call `table_fetch` for each member that implements `Fetch`.
#[inline]
unsafe fn table_fetch<'__w>(
_fetch: &mut <Self as #path::query::WorldQueryGats<'__w>>::Fetch,
_fetch: &mut <Self as #path::query::WorldQuery>::Fetch<'__w>,
_table_row: usize
) -> <Self as #path::query::WorldQueryGats<'__w>>::Item {
) -> <Self as #path::query::WorldQuery>::Item<'__w> {
Self::Item {
#(#field_idents: <#field_types>::table_fetch(&mut _fetch.#field_idents, _table_row),)*
#(#ignored_field_idents: Default::default(),)*
Expand All @@ -279,9 +274,9 @@ pub fn derive_world_query_impl(ast: DeriveInput) -> TokenStream {
/// SAFETY: we call `archetype_fetch` for each member that implements `Fetch`.
#[inline]
unsafe fn archetype_fetch<'__w>(
_fetch: &mut <Self as #path::query::WorldQueryGats<'__w>>::Fetch,
_fetch: &mut <Self as #path::query::WorldQuery>::Fetch<'__w>,
_archetype_index: usize
) -> <Self as #path::query::WorldQueryGats<'__w>>::Item {
) -> <Self as #path::query::WorldQuery>::Item<'__w> {
Self::Item {
#(#field_idents: <#field_types>::archetype_fetch(&mut _fetch.#field_idents, _archetype_index),)*
#(#ignored_field_idents: Default::default(),)*
Expand All @@ -290,13 +285,13 @@ pub fn derive_world_query_impl(ast: DeriveInput) -> TokenStream {

#[allow(unused_variables)]
#[inline]
unsafe fn table_filter_fetch<'__w>(_fetch: &mut <Self as #path::query::WorldQueryGats<'__w>>::Fetch, _table_row: usize) -> bool {
unsafe fn table_filter_fetch<'__w>(_fetch: &mut <Self as #path::query::WorldQuery>::Fetch<'__w>, _table_row: usize) -> bool {
true #(&& <#field_types>::table_filter_fetch(&mut _fetch.#field_idents, _table_row))*
}

#[allow(unused_variables)]
#[inline]
unsafe fn archetype_filter_fetch<'__w>(_fetch: &mut <Self as #path::query::WorldQueryGats<'__w>>::Fetch, _archetype_index: usize) -> bool {
unsafe fn archetype_filter_fetch<'__w>(_fetch: &mut <Self as #path::query::WorldQuery>::Fetch<'__w>, _archetype_index: usize) -> bool {
true #(&& <#field_types>::archetype_filter_fetch(&mut _fetch.#field_idents, _archetype_index))*
}

Expand Down

0 comments on commit 32d4125

Please sign in to comment.