diff --git a/tests/warnings/double_parens.rs b/tests/warnings/double_parens.rs new file mode 100644 index 000000000..ca0522e7c --- /dev/null +++ b/tests/warnings/double_parens.rs @@ -0,0 +1,39 @@ +//! Regression test for clippy::double_parens warnings in cycle macros. +//! +//! This test ensures that tracked functions with no additional inputs (beyond `db`) +//! don't trigger clippy::double_parens warnings when using cycle_initial or cycle_fn. +//! +//! Before the fix in components/salsa-macro-rules/src/unexpected_cycle_recovery.rs, +//! these macros would generate `std::mem::drop(())` which triggered the warning. +//! +//! See: https://github.com/salsa-rs/salsa/issues/1004 + +// This tracked function has no additional inputs beyond `db`. +// With the old code, this would trigger clippy::double_parens warnings in the +// generated `unexpected_cycle_initial` and `unexpected_cycle_recovery` macros. +#[salsa::tracked] +fn simple_tracked_query(_db: &dyn salsa::Database) -> u32 { + 100 +} + +// Tracked function with cycle recovery and no additional inputs. +// The cycle_initial and cycle_fn functions also have no additional inputs beyond `db`, +// which would trigger the clippy warning with the old code. +#[salsa::tracked(cycle_fn=cycle_recover, cycle_initial=initial)] +#[allow(dead_code)] +fn query_with_cycle_support(_db: &dyn salsa::Database) -> u32 { + 200 +} + +fn initial(_db: &dyn salsa::Database) -> u32 { + 0 +} + +fn cycle_recover( + _db: &dyn salsa::Database, + value: &u32, + _count: u32, +) -> salsa::CycleRecoveryAction { + // Just return the value to avoid actual cycling in this test + salsa::CycleRecoveryAction::Fallback(*value) +} diff --git a/tests/warnings/main.rs b/tests/warnings/main.rs index 77438e538..7802a1638 100644 --- a/tests/warnings/main.rs +++ b/tests/warnings/main.rs @@ -2,6 +2,7 @@ #![deny(warnings)] +mod double_parens; mod needless_borrow; mod needless_lifetimes; mod unused_variable_db;