-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Can we stop rustc --test warning of an unused main()? #12327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Perhaps it would be better to disable all warnings by default in test mode. Some people use tests as a "poor man's REPL", and warnings are just noise there. |
The dead_code lint is really helpful for indicating tests that are missing their |
👍 for ignoring unused main. I agree keeping other dead code warning is defiantly a good idea, but warning about |
+1 to specifically ignoring |
On a related note, ignoring main seems to ignore things when compiled with |
:+ for ignoring main |
I'm interested in sheparding a patch like this, if anyone wants to give it a shot. |
@steveklabnik I've made a first try to fix this. This tentative fix is not valid but I already got failed tests that I'm investigating. |
Starting with a _ is intended to supress warnings, yeah |
@Siosm, NB. it is purely a warning/conventions thing, it just controls the lints, it doesn't have any effect on what is accessible externally or anything like that (that's the |
@huonw Ok. Is this documented somewhere? So far I can not find any mention of it in the reference or in the guide. |
This issue appears to also affect the Emacs Flycheck mode for Rust. Emacs users will get Flycheck warnings saying main() is dead code. Arguably it's a bug in their end (is it?), but it's another data point to suggest it's unexpected behaviour. |
In addition to being a solid library, the chess package should also end up as a decent command line program with a playable game. This is possible because a package can be a library as well as a binary. Because the main function isn't tested, and may be difficult to test, using submodules is a pain, because they show up as unused imports. The main function as well shows up as an unused function when testing. Since main is such a special case, there is an open issue to make the test runner not show that warning. rust-lang/rust#12327 For the time being though, I've done as the OP of that issue said he does: putting #[cfg(not(test))] before the main function so that the linter ignores it.
It'd be also a good idea to not just use #[cfg(not(test))] on main, since that'll cause spurious import not used errors on functions that are just imported for use in main. |
This fixes #18 by including std::thread The dead code warning is not fixable and related to rust bug #12327 rust-lang/rust#12327
@tbelaire Using |
🎊 |
Remove `allow` since rust-lang/rust#12327 is fixed
…jonas-schievink internal: Rename `Expr::Lambda` to `Expr::Closure` They're never really called "Lambda"s in Rust, so let's call them "Closures" consistently.
I have put
#[cfg(not(test))]
onmain
a couple of times (though perhaps#[allow(dead_code)]
would be better) and I have just observed another person doing it. Would it be reasonable to make the dead code lint permitmain
to be unused?The text was updated successfully, but these errors were encountered: