Skip to content

Commit

Permalink
Fix BUNDLE_WITH_INCOMPLETE_TRANSFORMS linting components
Browse files Browse the repository at this point in the history
  • Loading branch information
MinerSebas committed May 8, 2024
1 parent 23c09ac commit 46dc410
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/bevy_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] = &[
Expand Down
16 changes: 15 additions & 1 deletion src/bundle_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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(),
Expand All @@ -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;

Expand Down
6 changes: 6 additions & 0 deletions ui/bundle_lints/bundle_with_incomplete_transforms.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(dead_code)]
use std::marker::PhantomData;

use bevy::{
Expand Down Expand Up @@ -50,6 +51,11 @@ struct ComplexBundleWithoutTransform {
b: B,
}

#[derive(Component)]
struct ComponentWithTransform {
a: Transform,
}

fn main() {
// Nothing to test here at runtime.
}

0 comments on commit 46dc410

Please sign in to comment.