Skip to main content

warn

Attribute warn 

Source
Expand description

Emits a warning during compilation when a lint check failed.

Unlike deny or forbid, warn does not produce a hard error: the compilation continues, but the compiler emits a warning message. warn can be overridden by allow, deny, and forbid.

Example:

#![allow(unused)]

#[warn(unused)] // We override the allowed `unused` lint.
fn foo() {
    // This lint warns by default even without #[warn(unused)] being explicitly set
    let x = 42; // warning: unused variable `x`
}

Many lints, including unused, are already set to warn by default so this attribute is mainly useful for lints that are normally allow by default.

Multiple lints can be set to warn at once:

#[warn(unused_mut, unused_variables)]
fn main() {
    let mut x = 42;
}

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 warn attribute.