1

Every time I come back to rust I am baffled by how the warnings for unused code work, they're transitive! Even if function f is called from function g, f will still be considered unused if g is unused.

I'm sure this is very useful behavior for some circumstances but I find myself missing warnings for unused code found in the linters for other programming languages. When searching I found this post which perfectly describes my sentiment. To me warnings for dead code are important to identify work to do next and possible bugs, but the useful warnings are buried in a sea of spammy warnings of transitively unused code, not actually unused code.

Are there any configuration options or other tools I can use for identifying "real" unused code? Or am I looking at this in the wrong way?

I searched google trying to find previous relevant discussions or solutions and didn't find anything other than the previously mentioned post.

  • Not really an answer but developing the other way round with bunch of `todo!()`s in places not yet implemented avoids that problem alltogether, i.e. first write the code that uses a function, then write the function. Alternatively splitting into a library that exports a bunch of functionality and a binary that eventually uses it also cirumvents the problem, `pub fn` are never unused. – cafce25 Sep 02 '23 at 11:49
  • Thanks for the tips @cafce25! I definitely use `todo!` quite a bit but I guess I "go from both directions" since I still wind up with functions that haven't been "hooked up" to anything yet. Making everything `pub` seems similar to allowing dead code everywhere. I do want warnings on unused code, I just want to find the root cause. – withstanding_crepe Sep 02 '23 at 11:56

0 Answers0