From 46dc4109fe22e1663e12873bcf556e69db354989 Mon Sep 17 00:00:00 2001 From: MinerSebas Date: Wed, 8 May 2024 15:34:08 +0200 Subject: [PATCH] Fix BUNDLE_WITH_INCOMPLETE_TRANSFORMS linting components --- src/bevy_paths.rs | 1 + src/bundle_lints.rs | 16 +++++++++++++++- .../bundle_with_incomplete_transforms.rs | 6 ++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/bevy_paths.rs b/src/bevy_paths.rs index 3105aba..c431306 100644 --- a/src/bevy_paths.rs +++ b/src/bevy_paths.rs @@ -6,6 +6,7 @@ pub const WITHOUT: &[&str; 4] = &["bevy_ecs", "query", "filter", "Without"]; pub const QUERY: &[&str; 4] = &["bevy_ecs", "system", "query", "Query"]; pub const SYSTEM_PARAM: &[&str; 4] = &["bevy_ecs", "system", "system_param", "SystemParam"]; pub const BUNDLE: &[&str; 3] = &["bevy_ecs", "bundle", "Bundle"]; +pub const COMPONENT: &[&str; 3] = &["bevy_ecs", "component", "Component"]; pub const TRANSFORM: &[&str; 4] = &["bevy_transform", "components", "transform", "Transform"]; pub const GLOBAL_TRANSFORM: &[&str; 4] = &[ diff --git a/src/bundle_lints.rs b/src/bundle_lints.rs index b1ea8e8..ebc82a8 100644 --- a/src/bundle_lints.rs +++ b/src/bundle_lints.rs @@ -8,7 +8,7 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint, declare_lint_pass}; use crate::{ - bevy_paths::{BUNDLE, GLOBAL_TRANSFORM, TRANSFORM}, + bevy_paths::{BUNDLE, COMPONENT, GLOBAL_TRANSFORM, TRANSFORM}, mixed_ty::MixedTy, }; @@ -63,6 +63,10 @@ impl<'tcx> LateLintPass<'tcx> for BundleLintPass { return; }; + let Some(component_def_id) = get_trait_def_id(ctx, COMPONENT) else { + return; + }; + if !implements_trait( ctx, ctx.tcx.type_of(item.owner_id.def_id).skip_binder(), @@ -72,6 +76,16 @@ impl<'tcx> LateLintPass<'tcx> for BundleLintPass { return; } + // Components are also unconditonally Bundles and should not be linted + if implements_trait( + ctx, + ctx.tcx.type_of(item.owner_id.def_id).skip_binder(), + component_def_id, + &[], + ) { + return; + } + let mut contains_transform = false; let mut contains_global_transform = false; diff --git a/ui/bundle_lints/bundle_with_incomplete_transforms.rs b/ui/bundle_lints/bundle_with_incomplete_transforms.rs index b0b5490..92b5d47 100644 --- a/ui/bundle_lints/bundle_with_incomplete_transforms.rs +++ b/ui/bundle_lints/bundle_with_incomplete_transforms.rs @@ -1,3 +1,4 @@ +#![allow(dead_code)] use std::marker::PhantomData; use bevy::{ @@ -50,6 +51,11 @@ struct ComplexBundleWithoutTransform { b: B, } +#[derive(Component)] +struct ComponentWithTransform { + a: Transform, +} + fn main() { // Nothing to test here at runtime. }