Skip to content

Commit 3746ea0

Browse files
committed
Add double_parens regression test for tracked function without arguments
1 parent 8b0831f commit 3746ea0

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

tests/warnings/double_parens.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//! Regression test for clippy::double_parens warnings in cycle macros.
2+
//!
3+
//! This test ensures that tracked functions with no additional inputs (beyond `db`)
4+
//! don't trigger clippy::double_parens warnings when using cycle_initial or cycle_fn.
5+
//!
6+
//! Before the fix in components/salsa-macro-rules/src/unexpected_cycle_recovery.rs,
7+
//! these macros would generate `std::mem::drop(())` which triggered the warning.
8+
//!
9+
//! See: https://github.com/salsa-rs/salsa/issues/1004
10+
11+
// This tracked function has no additional inputs beyond `db`.
12+
// With the old code, this would trigger clippy::double_parens warnings in the
13+
// generated `unexpected_cycle_initial` and `unexpected_cycle_recovery` macros.
14+
#[salsa::tracked]
15+
fn simple_tracked_query(_db: &dyn salsa::Database) -> u32 {
16+
100
17+
}
18+
19+
// Tracked function with cycle recovery and no additional inputs.
20+
// The cycle_initial and cycle_fn functions also have no additional inputs beyond `db`,
21+
// which would trigger the clippy warning with the old code.
22+
#[salsa::tracked(cycle_fn=cycle_recover, cycle_initial=initial)]
23+
fn query_with_cycle_support(_db: &dyn salsa::Database) -> u32 {
24+
200
25+
}
26+
27+
fn initial(_db: &dyn salsa::Database) -> u32 {
28+
0
29+
}
30+
31+
fn cycle_recover(
32+
_db: &dyn salsa::Database,
33+
value: &u32,
34+
_count: u32,
35+
) -> salsa::CycleRecoveryAction<u32> {
36+
// Just return the value to avoid actual cycling in this test
37+
salsa::CycleRecoveryAction::Fallback(*value)
38+
}

tests/warnings/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
#![deny(warnings)]
44

5+
mod double_parens;
56
mod needless_borrow;
67
mod needless_lifetimes;
78
mod unused_variable_db;

0 commit comments

Comments
 (0)