Skip to content

Commit 83f0822

Browse files
committed
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);`
2 parents 0ecff8c + 774a79e commit 83f0822

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

Diff for: library/core/src/option.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,7 @@ impl<T> Option<T> {
11791179
/// *val = 3;
11801180
/// assert_eq!(opt.unwrap(), 3);
11811181
/// ```
1182+
#[must_use = "if you intended to set a value, consider assignment instead"]
11821183
#[inline]
11831184
#[stable(feature = "option_insert", since = "1.53.0")]
11841185
pub fn insert(&mut self, value: T) -> &mut T {

0 commit comments

Comments
 (0)