@@ -39,6 +39,11 @@ pub mod m1 {
3939}
4040```
4141
42+ Lint attributes can override the level specified from a previous attribute, as
43+ long as the level does not attempt to change a forbidden lint. Previous
44+ attributes are those from a higher level in the syntax tree, or from a
45+ previous attribute on the same entity as listed in left-to-right source order.
46+
4247This example shows how one can use ` allow ` and ` warn ` to toggle a particular
4348check on and off:
4449
@@ -74,6 +79,49 @@ pub mod m3 {
7479}
7580```
7681
82+ > Note: ` rustc ` allows setting lint levels on the
83+ > [ command-line] [ rustc-lint-cli ] , and also supports [ setting
84+ > caps] [ rustc-lint-caps ] on the lints that are reported.
85+
86+ ### Lint groups
87+
88+ Lints may be organized into named groups so that the level of related lints
89+ can be adjusted together. Using a named group is equivalent to listing out the
90+ lints within that group.
91+
92+ ``` rust,compile_fail
93+ // This allows all lints in the "unused" group.
94+ #[allow(unused)]
95+ // This overrides the "unused_must_use" lint from the "unused"
96+ // group to deny.
97+ #[deny(unused_must_use)]
98+ fn example() {
99+ // This does not generate a warning because the "unused_variables"
100+ // lint is in the "unused" group.
101+ let x = 1;
102+ // This generates an error because the result is unused and
103+ // "unused_must_use" is marked as "deny".
104+ std::fs::remove_file("some_file"); // ERROR: unused `Result` that must be used
105+ }
106+ ```
107+
108+ There is a special group named "warnings" which includes all lints at the
109+ "warn" level. The "warnings" group ignores attribute order and applies to all
110+ lints that would otherwise warn within the entity.
111+
112+ ``` rust,compile_fail
113+ # unsafe fn an_unsafe_fn() {}
114+ // The order of these two attributes does not matter.
115+ #[deny(warnings)]
116+ // The unsafe_code lint is normally "allow" by default.
117+ #[warn(unsafe_code)]
118+ fn example_err() {
119+ // This is an error because the `unsafe_code` warning has
120+ // been lifted to "deny".
121+ unsafe { an_unsafe_fn() } // ERROR: usage of `unsafe` block
122+ }
123+ ```
124+
77125### Tool lint attributes
78126
79127Tool lints allows using scoped lints, to ` allow ` , ` warn ` , ` deny ` or ` forbid `
@@ -274,6 +322,8 @@ When used on a function in a trait implementation, the attribute does nothing.
274322[macro definition ]: .. / macros - by - example . md
275323[module ]: .. / items / modules . md
276324[rustc book ]: .. / .. / rustc / lints / index . html
325+ [rustc - lint - caps ]: .. / .. / rustc / lints / levels . html#capping - lints
326+ [rustc - lint - cli ]: .. / .. / rustc / lints / levels . html#via - compiler - flag
277327[rustdoc ]: .. / .. / rustdoc / lints . html
278328[struct field ]: .. / items / structs . md
279329[struct ]: .. / items / structs . md
0 commit comments