Skip to content

Commit 1b9edbe

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

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

tests/warnings/double_parens.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
#[allow(dead_code)]
24+
fn query_with_cycle_support(_db: &dyn salsa::Database) -> u32 {
25+
200
26+
}
27+
28+
fn initial(_db: &dyn salsa::Database) -> u32 {
29+
0
30+
}
31+
32+
fn cycle_recover(
33+
_db: &dyn salsa::Database,
34+
value: &u32,
35+
_count: u32,
36+
) -> salsa::CycleRecoveryAction<u32> {
37+
// Just return the value to avoid actual cycling in this test
38+
salsa::CycleRecoveryAction::Fallback(*value)
39+
}

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)