diff --git a/components/salsa-macro-rules/src/unexpected_cycle_recovery.rs b/components/salsa-macro-rules/src/unexpected_cycle_recovery.rs index 8d56d54f3..4df525e22 100644 --- a/components/salsa-macro-rules/src/unexpected_cycle_recovery.rs +++ b/components/salsa-macro-rules/src/unexpected_cycle_recovery.rs @@ -5,7 +5,7 @@ macro_rules! unexpected_cycle_recovery { ($db:ident, $value:ident, $count:ident, $($other_inputs:ident),*) => {{ std::mem::drop($db); - std::mem::drop(($($other_inputs,)*)); + $(std::mem::drop($other_inputs);)* panic!("cannot recover from cycle") }}; } @@ -14,7 +14,7 @@ macro_rules! unexpected_cycle_recovery { macro_rules! unexpected_cycle_initial { ($db:ident, $($other_inputs:ident),*) => {{ std::mem::drop($db); - std::mem::drop(($($other_inputs,)*)); + $(std::mem::drop($other_inputs);)* panic!("no cycle initial value") }}; } diff --git a/tests/warnings/double_parens.rs b/tests/warnings/double_parens.rs new file mode 100644 index 000000000..21f8239f2 --- /dev/null +++ b/tests/warnings/double_parens.rs @@ -0,0 +1,47 @@ +//! 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)] +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) +} + +#[test_log::test] +fn test_no_clippy_warnings_for_no_input_functions() { + let db = salsa::DatabaseImpl::default(); + + // These functions should compile without clippy::double_parens warnings + assert_eq!(simple_tracked_query(&db), 100); + assert_eq!(query_with_cycle_support(&db), 200); +} 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;