Skip to main content

deny

Attribute deny 

Source
Expand description

Emits an error, preventing the compilation from finishing, when a lint check has failed. This is useful for enforcing rules or preventing certain patterns:

#[deny(unused)]
fn foo() {
    let x = 42; // Emits an error because x is unused.
}

deny can be overridden by allow, warn, and forbid:

#![deny(unused)]

#[allow(unused)] // We override the `deny` for this function.
fn foo() {
    let x = 42; // No lint emitted even though `x` is unused.
}

Multiple lints can also be set to deny at once:

#![deny(unused_imports, unused_variables)]
use std::collections::*;

fn main() {
    let mut x = 10;
}

The lint checks supported by rustc can be found via rustc -W help, along with their default settings and are documented in the rustc book.

For more information, see the Reference on the deny attribute.