Skip to content

Commit

Permalink
Auto merge of #87196 - oxalica:option-insert-must-use, r=joshtriplett
Browse files Browse the repository at this point in the history
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);`
  • Loading branch information
bors committed Jul 19, 2021
2 parents 0ecff8c + 774a79e commit 83f0822
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 83f0822

Please sign in to comment.