Guide new users to add use super::*;
to mod test
.
#10559
Labels
C-feature-request
Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Command-init
Command-new
Problem
cargo init --lib
produces a src/lib.rs file contaning this:When I was first learning Rust, I'd start with this code, and add a new function, and a unit test, like this:
But, this doesn't compile:
So first, this in itself is a mild papercut—the seemingly obvious thing didn't work. But next, if I would follow rustc's suggestions, or let IDEs fix this for me, I'd eventually end up with a big pile of
use
s, as I write more code and add tests for it. This would add more papercuts: clutter, and a focal point for merge conflicts.It would almost always be better for me to use
use super::*
inside themod tests
, because once that's added, it avoids these papercuts from then on. So the feature request is: can we do more to guide users touse super::*;
?The relevant documentation does recommend using
use super::*;
, but when I was learning Rust, I didn't read that section because I knew what an "assert" was from other languages and didn't think I needed to read that whole section in the docs, so I missed theuse super::*;
advice within.As a historical note, these papercuts contributed to my forming a habit of writing unit tests without
mod tests
, which is what prompted the discussion which led to #10531.Proposed Solution
Adding
use super::*;
to the current code would get an unused-import warning. So one option would be to add it, but commented out, like this:Notes
No response
The text was updated successfully, but these errors were encountered: