Skip to content

Commit

Permalink
feat: cache 'bevy' symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
DaAlbrecht committed Dec 1, 2024
1 parent 8d8b851 commit 02c9e73
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
20 changes: 16 additions & 4 deletions bevy_lint/src/lints/duplicate_bevy_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
//! errors and type incompatibilities.
use crate::declare_bevy_lint;
use clippy_utils::{diagnostics::span_lint, find_crates};
use clippy_utils::{diagnostics::span_lint, find_crates, sym};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::declare_lint_pass;
use rustc_session::impl_lint_pass;
use rustc_span::Symbol;

declare_bevy_lint! {
Expand All @@ -17,13 +17,25 @@ declare_bevy_lint! {
"duplicate bevy dependencies",
}

declare_lint_pass! {
pub(crate) struct DuplicateBevyDependencies {
bevy_symbol: Symbol,
}

impl Default for DuplicateBevyDependencies {
fn default() -> Self {
Self {
bevy_symbol: sym!(bevy),
}
}
}

impl_lint_pass! {
DuplicateBevyDependencies => [DUPLICATE_BEVY_DEPENDENCIES.lint]
}

impl<'tcx> LateLintPass<'tcx> for DuplicateBevyDependencies {
fn check_crate(&mut self, cx: &LateContext<'tcx>) {
let bevy_crates = find_crates(cx.tcx, Symbol::intern("bevy"));
let bevy_crates = find_crates(cx.tcx, self.bevy_symbol);

if bevy_crates.len() > 1 {
let span = cx.tcx.def_span(bevy_crates[1].def_id());
Expand Down
4 changes: 3 additions & 1 deletion bevy_lint/src/lints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ pub(crate) fn register_passes(store: &mut LintStore) {
store.register_late_pass(|_| Box::new(panicking_methods::PanickingMethods));
store.register_late_pass(|_| Box::new(plugin_not_ending_in_plugin::PluginNotEndingInPlugin));
store.register_late_pass(|_| Box::new(zst_query::ZstQuery));
store.register_late_pass(|_| Box::new(duplicate_bevy_dependencies::DuplicateBevyDependencies));
store.register_late_pass(|_| {
Box::new(duplicate_bevy_dependencies::DuplicateBevyDependencies::default())
});
}

0 comments on commit 02c9e73

Please sign in to comment.