Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a rustc equivalent of -Wall -Werror?

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?

like image 865
Ian Kelling Avatar asked Apr 23 '15 06:04

Ian Kelling


People also ask

Is Rust just as fast as C?

Rust incorporates a memory ownership model enforced at a compile time. Since this model involves zero runtime overhead, programs written in Rust are not only memory-safe but also fast, leading to performance comparable to C and C++.

What is Rust most similar to?

Rust is a statically-typed programming language designed for performance and safety, especially safe concurrency and memory management. Its syntax is similar to that of C++.

Is Rust like C or C++?

Rust is syntactically similar to C++, but it provides increased speed and better memory safety. Rust is a more innovative system-level language in terms of safer memory management because it does not allow dangling pointers or null pointers.

Is Rust safer than C?

These two programming languages have many similarities. But there is one thing which definitely divides them: safety. Rust is a more secure option than C++—a potential error causes code rejection. Rust is “safe-by-default”.


1 Answers

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.

like image 160
Chris Morgan Avatar answered Oct 04 '22 01:10

Chris Morgan