diff options
| author | bors <bors@rust-lang.org> | 2021-07-19 07:03:36 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-07-19 07:03:36 +0000 |
| commit | 83f08223a90b71f59e5dc5f38e384a49a76c8452 (patch) | |
| tree | bd43202e46c3f75762d66a6d5be1820dd5204eb8 | |
| parent | 0ecff8c623fa29cccad6f946c657e81dacd85847 (diff) | |
| parent | 774a79e3fd40dee6dcdb80ef57e9e49a6d38d381 (diff) | |
| download | rust-83f08223a90b71f59e5dc5f38e384a49a76c8452.tar.gz rust-83f08223a90b71f59e5dc5f38e384a49a76c8452.zip | |
Auto merge of #87196 - oxalica:option-insert-must-use, r=joshtriplett
Mark `Option::insert` as must_use Some people seems misled by the function name and use it in case where a simple assignment just works. If the return value is not used, `option = Some(value);` should be preferred instead of `option.insert(value);`
| -rw-r--r-- | library/core/src/option.rs | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/library/core/src/option.rs b/library/core/src/option.rs index c27db0767ac..8057ff07591 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -1179,6 +1179,7 @@ impl<T> Option<T> { /// *val = 3; /// assert_eq!(opt.unwrap(), 3); /// ``` + #[must_use = "if you intended to set a value, consider assignment instead"] #[inline] #[stable(feature = "option_insert", since = "1.53.0")] pub fn insert(&mut self, value: T) -> &mut T { |
