Skip to main content

forbid

Attribute forbid 

Source
Expand description

Emits an error, preventing the compilation from finishing, when a lint check has failed.

A lint set to forbid cannot be overridden by allow or warn. Attempting either will result in a compilation error. Writing #[deny(...)] on the same lint inside a forbid scope is permitted, but has no effect; the lint remains at the forbid level.

This is useful for enforcing strict policies that should not be relaxed anywhere in the codebase. Example:

#![forbid(unsafe_code)]

// This would cause a compilation error if uncommented:
// #[allow(unsafe_code)] // error: cannot override `forbid`

Multiple lints can be set to forbid at once:

#![forbid(unsafe_code, unused)]

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