Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unstable book section for
fn_must_use
- Loading branch information
1 parent
e9569d9
commit d09db63
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/doc/unstable-book/src/language-features/fn-must-use.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# `fn_must_use` | ||
|
||
The tracking issue for this feature is [#43302]. | ||
|
||
[#43302]: https://github.com/rust-lang/rust/issues/43302 | ||
|
||
------------------------ | ||
|
||
The `fn_must_use` feature allows functions and methods to be annotated with | ||
`#[must_use]`, indicating that the `unused_must_use` lint should require their | ||
return values to be used (similarly to how types annotated with `must_use`, | ||
most notably `Result`, are linted if not used). | ||
|
||
## Examples | ||
|
||
```rust | ||
#![feature(fn_must_use)] | ||
|
||
#[must_use] | ||
fn double(x: i32) -> i32 { | ||
2 * x | ||
} | ||
|
||
fn main() { | ||
double(4); // warning: unused return value of `double` which must be used | ||
|
||
let _ = double(4); // (no warning) | ||
} | ||
|
||
``` |