I'm curious to understand the rules for cargo check
and rust analyzer to report unused functions. It seems inconsistent to me, but probably I'm missing something. Here's what I see.
While learning Rust I copied some modules from a previous project to a new one and indeed some utility functions are not used in the new project. Here are two examples:
The Region::new
function is never used except for unit tests, and I see no complaints about it being unused.
-
Implementation: src/region.rs · 5b9868f9bc32163a7b4646f5c346429565dc9677 · Tad Lispy / Bevy Lyon Playground · GitLab
-
Use in a test e.g. on lines 165-170
At the same time, the TouchPoints::get
is also never used except for unit tests, but tools are complaining about it:
-
Implementation: src/touch.rs · 5b9868f9bc32163a7b4646f5c346429565dc9677 · Tad Lispy / Bevy Lyon Playground · GitLab
-
Use in a test e.g. on line 154
Here's complete output from cargo check:
$ cargo check
Checking bevy-lyon-playground v0.1.0 (/home/tad/Projects/bevy-lyon-playground)
warning: associated function `get` is never used
--> src/touch.rs:19:12
|
19 | pub fn get(&self, identifier: i64) -> Option<&TouchPoint> {
| ^^^
|
= note: `#[warn(dead_code)]` on by default
warning: `bevy-lyon-playground` (bin "bevy-lyon-playground") generated 1 warning
Finished dev [unoptimized + debuginfo] target(s) in 0.31s
The two functions are both public and implemented for a public struct. What makes cargo complain about one of them but not the other?