@@ -15,14 +15,13 @@ For any lint check `C`:
15
15
16
16
* ` allow(C) ` overrides the check for ` C ` so that violations will go
17
17
unreported,
18
+ * ` warn(C) ` warns about violations of ` C ` but continues compilation.
18
19
* ` deny(C) ` signals an error after encountering a violation of ` C ` ,
19
20
* ` forbid(C) ` is the same as ` deny(C) ` , but also forbids changing the lint
20
21
level afterwards,
21
- * ` warn(C) ` warns about violations of ` C ` but continues compilation.
22
22
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] .
26
25
27
26
``` rust
28
27
pub mod m1 {
@@ -77,8 +76,8 @@ pub mod m3 {
77
76
78
77
### Tool lint attributes
79
78
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.
82
81
83
82
Currently ` clippy ` is the only available lint tool.
84
83
@@ -146,11 +145,11 @@ The [RFC][1270-deprecation.md] contains motivations and more details.
146
145
147
146
[ 1270-deprecation.md ] : https://github.com/rust-lang/rfcs/blob/master/text/1270-deprecation.md
148
147
149
-
150
148
## The ` must_use ` attribute
151
149
152
150
The * ` 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] .
154
153
155
154
When used on user-defined composite types, if the [ expression] of an
156
155
[ expression statement] has that type, then the ` unused_must_use ` lint is
@@ -159,32 +158,30 @@ violated.
159
158
``` rust
160
159
#[must_use]
161
160
struct MustUse {
162
- // some fields
161
+ // some fields
163
162
}
164
163
165
164
# impl MustUse {
166
165
# fn new () -> MustUse { MustUse {} }
167
166
# }
168
167
#
169
168
fn main () {
170
- // Violates the `unused_must_use` lint.
171
- MustUse :: new ();
169
+ // Violates the `unused_must_use` lint.
170
+ MustUse :: new ();
172
171
}
173
172
```
174
173
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.
180
177
181
178
``` rust
182
179
#[must_use]
183
180
fn five () -> i32 { 5i32 }
184
181
185
182
fn main () {
186
- // Violates the unused_must_use lint.
187
- five ();
183
+ // Violates the unused_must_use lint.
184
+ five ();
188
185
}
189
186
```
190
187
@@ -193,21 +190,21 @@ when the call expression is a function from an implementation of the trait.
193
190
194
191
``` rust
195
192
trait Trait {
196
- #[must_use]
197
- fn use_me (& self ) -> i32 ;
193
+ #[must_use]
194
+ fn use_me (& self ) -> i32 ;
198
195
}
199
196
200
197
impl Trait for i32 {
201
- fn use_me (& self ) -> i32 { 0i32 }
198
+ fn use_me (& self ) -> i32 { 0i32 }
202
199
}
203
200
204
201
fn main () {
205
- // Violates the `unused_must_use` lint.
206
- 5i32 . use_me ();
202
+ // Violates the `unused_must_use` lint.
203
+ 5i32 . use_me ();
207
204
}
208
205
```
209
206
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.
211
208
212
209
> Note: Trivial no-op expressions containing the value will not violate the
213
210
> 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.
219
216
> fn five () -> i32 { 5i32 }
220
217
>
221
218
> 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
+ > };
230
227
> }
231
228
> ```
232
229
@@ -238,17 +235,16 @@ When used on a function in an implementation, the attribute does nothing.
238
235
> fn five() -> i32 { 5i32 }
239
236
>
240
237
> 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();
243
240
> }
244
241
> ```
245
242
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
247
244
[_MetaNameValueStr_ ] syntax such as `#[must_use = " example message" ]`. The
248
245
message will be given alongside the warning .
249
246
250
247
[Clippy ]: https : // github.com/rust-lang/rust-clippy
251
- [Compiler plugins ]: .. / unstable - book / language - features / plugin . html#lint - plugins
252
248
[_MetaListNameValueStr_ ]: attributes . html#meta - item - attribute - syntax
253
249
[_MetaListPaths_ ]: attributes . html#meta - item - attribute - syntax
254
250
[_MetaNameValueStr_ ]: attributes . html#meta - item - attribute - syntax
@@ -271,5 +267,5 @@ message will be given alongside the warning.
271
267
[struct ]: items / structs . html
272
268
[trait implementation items ]: items / implementations . html#trait - implementations
273
269
[trait item ]: items / traits . html
270
+ [traits ]: items / traits . html
274
271
[union ]: items / unions . html
275
- [zero - variant enum ]: items / enumerations . html#zero - variant - enums
0 commit comments