Is there a rustc equivalent of -Wall -Werror?

泪湿孤枕 提交于 2019-12-17 20:45:44

问题


First 10 minutes learning rust, I'm given 58 lint options and I'm thinking: gcc has a solution to this. To be clear: I want to enabled all warnings/lints (-Wall) and treat all warnings as hard errors (-Werror).

Something that would go in the .toml file? A workaround?


回答1:


gcc’s -Werror becomes rustc --deny warnings or the crate attribute #![deny(warnings)]. You can also pass the flag through an environment variable: RUSTFLAGS="--deny warnings".

-Wall or -Weverything aren’t really necessary in Rust; most of the sorts of things that would be covered by it are already compilation errors or lints that default to deny or warn. You should understand that the lints are just that: lints. They are matters that are at least slightly, and often very, subjective. The lints that are allow by default should be so—they’re useful tools for specific purposes, but enabling the lot of them simply doesn’t normally make sense. (The box-pointers lint, for example: in a certain type of library you may wish to be able to say “I guarantee this uses no heap memory”, but it’s not something that’s bad.)

rustc is fairly conservative in the lints it includes; for more extensive linting, take a look at Clippy.



来源:https://stackoverflow.com/questions/29814978/is-there-a-rustc-equivalent-of-wall-werror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!