@@ -15,14 +15,13 @@ For any lint check `C`:
1515
1616* ` allow(C) ` overrides the check for ` C ` so that violations will go
1717 unreported,
18+ * ` warn(C) ` warns about violations of ` C ` but continues compilation.
1819* ` deny(C) ` signals an error after encountering a violation of ` C ` ,
1920* ` forbid(C) ` is the same as ` deny(C) ` , but also forbids changing the lint
2021 level afterwards,
21- * ` warn(C) ` warns about violations of ` C ` but continues compilation.
2222
23- The lint checks supported by the compiler can be found via ` rustc -W help ` ,
24- along with their default settings and are documented in the [ rustc book] .
25- [ Compiler plugins] can provide additional lint checks.
23+ > Note: The lint checks supported by ` rustc ` can be found via ` rustc -W help ` ,
24+ > along with their default settings and are documented in the [ rustc book] .
2625
2726``` rust
2827pub mod m1 {
@@ -77,8 +76,8 @@ pub mod m3 {
7776
7877### Tool lint attributes
7978
80- Tool lints let you use scoped lints, to ` allow ` , ` warn ` , ` deny ` or ` forbid ` lints of
81- certain tools.
79+ Tool lints allows using scoped lints, to ` allow ` , ` warn ` , ` deny ` or ` forbid `
80+ lints of certain tools.
8281
8382Currently ` clippy ` is the only available lint tool.
8483
@@ -146,11 +145,11 @@ The [RFC][1270-deprecation.md] contains motivations and more details.
146145
147146[ 1270-deprecation.md ] : https://github.com/rust-lang/rfcs/blob/master/text/1270-deprecation.md
148147
149-
150148## The ` must_use ` attribute
151149
152150The * ` must_use ` attribute* can be used on user-defined composite types
153- ([ ` struct ` s] [ struct ] , [ ` enum ` s] [ enum ] , and [ ` union ` s] [ union ] ) and [ functions] .
151+ ([ ` struct ` s] [ struct ] , [ ` enum ` s] [ enum ] , and [ ` union ` s] [ union ] ), [ functions] ,
152+ and [ traits] .
154153
155154When used on user-defined composite types, if the [ expression] of an
156155[ expression statement] has that type, then the ` unused_must_use ` lint is
@@ -159,32 +158,30 @@ violated.
159158``` rust
160159#[must_use]
161160struct MustUse {
162- // some fields
161+ // some fields
163162}
164163
165164# impl MustUse {
166165# fn new () -> MustUse { MustUse {} }
167166# }
168167#
169168fn main () {
170- // Violates the `unused_must_use` lint.
171- MustUse :: new ();
169+ // Violates the `unused_must_use` lint.
170+ MustUse :: new ();
172171}
173172```
174173
175- When used on a function, if the [ expression] of an
176- [ expression statement] is a [ call expression] to that function, then the
177- ` unused_must_use ` lint is violated. The exceptions to this is if the return type
178- of the function is ` () ` , ` ! ` , or a [ zero-variant enum] , in which case the
179- attribute does nothing.
174+ When used on a function, if the [ expression] of an [ expression statement] is a
175+ [ call expression] to that function, then the ` unused_must_use ` lint is
176+ violated.
180177
181178``` rust
182179#[must_use]
183180fn five () -> i32 { 5i32 }
184181
185182fn main () {
186- // Violates the unused_must_use lint.
187- five ();
183+ // Violates the unused_must_use lint.
184+ five ();
188185}
189186```
190187
@@ -193,21 +190,21 @@ when the call expression is a function from an implementation of the trait.
193190
194191``` rust
195192trait Trait {
196- #[must_use]
197- fn use_me (& self ) -> i32 ;
193+ #[must_use]
194+ fn use_me (& self ) -> i32 ;
198195}
199196
200197impl Trait for i32 {
201- fn use_me (& self ) -> i32 { 0i32 }
198+ fn use_me (& self ) -> i32 { 0i32 }
202199}
203200
204201fn main () {
205- // Violates the `unused_must_use` lint.
206- 5i32 . use_me ();
202+ // Violates the `unused_must_use` lint.
203+ 5i32 . use_me ();
207204}
208205```
209206
210- When used on a function in an implementation, the attribute does nothing.
207+ When used on a function in a trait implementation, the attribute does nothing.
211208
212209> Note: Trivial no-op expressions containing the value will not violate the
213210> lint. Examples include wrapping the value in a type that does not implement
@@ -219,14 +216,14 @@ When used on a function in an implementation, the attribute does nothing.
219216> fn five () -> i32 { 5i32 }
220217>
221218> fn main () {
222- > // None of these violate the unused_must_use lint.
223- > (five (),);
224- > Some (five ());
225- > { five () };
226- > if true { five () } else { 0i32 };
227- > match true {
228- > _ => five ()
229- > };
219+ > // None of these violate the unused_must_use lint.
220+ > (five (),);
221+ > Some (five ());
222+ > { five () };
223+ > if true { five () } else { 0i32 };
224+ > match true {
225+ > _ => five ()
226+ > };
230227> }
231228> ```
232229
@@ -238,17 +235,16 @@ When used on a function in an implementation, the attribute does nothing.
238235> fn five() -> i32 { 5i32 }
239236>
240237> fn main() {
241- > // Does not violate the unused_must_use lint.
242- > let _ = five();
238+ > // Does not violate the unused_must_use lint.
239+ > let _ = five();
243240> }
244241> ```
245242
246- The `must_use ` attribute may also include a message by using the
243+ The `must_use ` attribute may include a message by using the
247244[_MetaNameValueStr_ ] syntax such as `#[must_use = " example message" ]`. The
248245message will be given alongside the warning .
249246
250247[Clippy ]: https : // github.com/rust-lang/rust-clippy
251- [Compiler plugins ]: .. / unstable - book / language - features / plugin . html#lint - plugins
252248[_MetaListNameValueStr_ ]: attributes . html#meta - item - attribute - syntax
253249[_MetaListPaths_ ]: attributes . html#meta - item - attribute - syntax
254250[_MetaNameValueStr_ ]: attributes . html#meta - item - attribute - syntax
@@ -271,5 +267,5 @@ message will be given alongside the warning.
271267[struct ]: items / structs . html
272268[trait implementation items ]: items / implementations . html#trait - implementations
273269[trait item ]: items / traits . html
270+ [traits ]: items / traits . html
274271[union ]: items / unions . html
275- [zero - variant enum ]: items / enumerations . html#zero - variant - enums
0 commit comments