# Objective > Rust 1.81 released the #[expect(...)] attribute, which works like #[allow(...)] but throws a warning if the lint isn't raised. This is preferred to #[allow(...)] because it tells us when it can be removed. - Adopts the parts of #15118 that are complete, and updates the branch so it can be merged. - There were a few conflicts, let me know if I misjudged any of 'em. Alice's [recommendation](https://github.com/bevyengine/bevy/issues/15059#issuecomment-2349263900) seems well-taken, let's do this crate by crate now that @BD103 has done the lion's share of this! (Relates to, but doesn't yet completely finish #15059.) Crates this _doesn't_ cover: - bevy_input - bevy_gilrs - bevy_window - bevy_winit - bevy_state - bevy_render - bevy_picking - bevy_core_pipeline - bevy_sprite - bevy_text - bevy_pbr - bevy_ui - bevy_gltf - bevy_gizmos - bevy_dev_tools - bevy_internal - bevy_dylib --------- Co-authored-by: BD103 <59022059+BD103@users.noreply.github.com> Co-authored-by: Ben Frankel <ben.frankel7@gmail.com> Co-authored-by: Antony <antony.m.3012@gmail.com>
102 lines
3.5 KiB
Rust
102 lines
3.5 KiB
Rust
// FIXME(15321): solve CI failures, then replace with `#![expect()]`.
|
|
#![allow(missing_docs, reason = "Not all docs are written yet, see #3492.")]
|
|
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
|
|
|
mod as_bind_group;
|
|
mod extract_component;
|
|
mod extract_resource;
|
|
|
|
use bevy_macro_utils::{derive_label, BevyManifest};
|
|
use proc_macro::TokenStream;
|
|
use quote::format_ident;
|
|
use syn::{parse_macro_input, DeriveInput};
|
|
|
|
pub(crate) fn bevy_render_path() -> syn::Path {
|
|
BevyManifest::default()
|
|
.maybe_get_path("bevy_render")
|
|
// NOTE: If the derivation is within bevy_render, then we need to return 'crate'
|
|
.unwrap_or_else(|| BevyManifest::parse_str("crate"))
|
|
}
|
|
|
|
#[proc_macro_derive(ExtractResource)]
|
|
pub fn derive_extract_resource(input: TokenStream) -> TokenStream {
|
|
extract_resource::derive_extract_resource(input)
|
|
}
|
|
|
|
/// Implements `ExtractComponent` trait for a component.
|
|
/// The component must implement [`Clone`].
|
|
/// The component will be extracted into the render world via cloning.
|
|
/// Note that this only enables extraction of the component, it does not execute the extraction.
|
|
/// See `ExtractComponentPlugin` to actually perform the extraction.
|
|
///
|
|
/// If you only want to extract a component conditionally, you may use the `extract_component_filter` attribute.
|
|
///
|
|
/// # Example
|
|
///
|
|
/// ```no_compile
|
|
/// use bevy_ecs::component::Component;
|
|
/// use bevy_render_macros::ExtractComponent;
|
|
///
|
|
/// #[derive(Component, Clone, ExtractComponent)]
|
|
/// #[extract_component_filter(With<Camera>)]
|
|
/// pub struct Foo {
|
|
/// pub should_foo: bool,
|
|
/// }
|
|
///
|
|
/// // Without a filter (unconditional).
|
|
/// #[derive(Component, Clone, ExtractComponent)]
|
|
/// pub struct Bar {
|
|
/// pub should_bar: bool,
|
|
/// }
|
|
/// ```
|
|
#[proc_macro_derive(ExtractComponent, attributes(extract_component_filter))]
|
|
pub fn derive_extract_component(input: TokenStream) -> TokenStream {
|
|
extract_component::derive_extract_component(input)
|
|
}
|
|
|
|
#[proc_macro_derive(
|
|
AsBindGroup,
|
|
attributes(uniform, storage_texture, texture, sampler, bind_group_data, storage)
|
|
)]
|
|
pub fn derive_as_bind_group(input: TokenStream) -> TokenStream {
|
|
let input = parse_macro_input!(input as DeriveInput);
|
|
|
|
as_bind_group::derive_as_bind_group(input).unwrap_or_else(|err| err.to_compile_error().into())
|
|
}
|
|
|
|
/// Derive macro generating an impl of the trait `RenderLabel`.
|
|
///
|
|
/// This does not work for unions.
|
|
#[proc_macro_derive(RenderLabel)]
|
|
pub fn derive_render_label(input: TokenStream) -> TokenStream {
|
|
let input = parse_macro_input!(input as DeriveInput);
|
|
let mut trait_path = bevy_render_path();
|
|
trait_path
|
|
.segments
|
|
.push(format_ident!("render_graph").into());
|
|
let mut dyn_eq_path = trait_path.clone();
|
|
trait_path
|
|
.segments
|
|
.push(format_ident!("RenderLabel").into());
|
|
dyn_eq_path.segments.push(format_ident!("DynEq").into());
|
|
derive_label(input, "RenderLabel", &trait_path, &dyn_eq_path)
|
|
}
|
|
|
|
/// Derive macro generating an impl of the trait `RenderSubGraph`.
|
|
///
|
|
/// This does not work for unions.
|
|
#[proc_macro_derive(RenderSubGraph)]
|
|
pub fn derive_render_sub_graph(input: TokenStream) -> TokenStream {
|
|
let input = parse_macro_input!(input as DeriveInput);
|
|
let mut trait_path = bevy_render_path();
|
|
trait_path
|
|
.segments
|
|
.push(format_ident!("render_graph").into());
|
|
let mut dyn_eq_path = trait_path.clone();
|
|
trait_path
|
|
.segments
|
|
.push(format_ident!("RenderSubGraph").into());
|
|
dyn_eq_path.segments.push(format_ident!("DynEq").into());
|
|
derive_label(input, "RenderSubGraph", &trait_path, &dyn_eq_path)
|
|
}
|