TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
forbid attribute is a compiler directive in Rust that sets the severity level of a specified lint or lint group to a fatal error while simultaneously preventing that level from being overridden. It is the strictest lint level available in the Rust compiler (rustc). Unlike the deny attribute, which also turns lints into errors, forbid establishes an immutable state for the lint within the lexical scope and item hierarchy; once applied, the specified lint cannot be downgraded in any nested scopes.
Syntax
The attribute can be applied as an inner attribute (affecting the entire enclosing crate or module) or an outer attribute (affecting a specific item, statement, or expression, and its descendants). Multiple lints can be passed as a comma-separated list.Manifest Configuration (Cargo.toml)
As of Rust 1.74, the idiomatic method for configuring global lint levels is through the[lints] table in the Cargo.toml manifest. This applies the forbid level across the entire crate without requiring source code attributes or command-line flags.
Command-Line Configuration
Theforbid level can also be applied globally during compilation using the command-line interface. This is achieved by passing the -F or --forbid flag directly to rustc or through Cargo.
Compiler Behavior and Mechanics
Whenrustc processes a forbid directive, it enforces two strict rules:
- Compilation Failure: Any code violating the forbidden lint will emit a compiler error, ensuring the build ultimately fails. The compiler does not halt immediately upon encountering the violation; it continues analyzing the code to report as many errors as possible in the current compilation phase before terminating.
- Override Rejection: Any attempt to redefine the lint level using
#[allow(...)],#[warn(...)], or#[deny(...)]further down the item hierarchy will trigger anE0453compiler error (“allow/warn/deny overruled by outer forbid”).
Mechanical Demonstration
The following code illustrates the mechanical difference between a standard lint violation and an illegal override attempt under aforbid directive:
Interaction with Lint Groups
Whenforbid is applied to a lint group (e.g., rust_2018_idioms or clippy::all), the immutability applies to every individual lint contained within that group. Attempting to allow a specific, single lint that belongs to a forbidden group will result in the same E0453 override error.
Master Rust with Deep Grasping Methodology!Learn More





