Skip to content

Commit e3bf088

Browse files
authored
Rollup merge of #112655 - WaffleLapkin:must_use_map_or, r=workingjubilee
Mark `map_or` as `#[must_use]` I don't know what else to say. r? libs
2 parents e517ee0 + 90f9640 commit e3bf088

File tree

7 files changed

+13
-10
lines changed

7 files changed

+13
-10
lines changed

compiler/rustc_hir_typeck/src/generator_interior/drop_ranges/cfg_build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,9 @@ impl<'a, 'tcx> Visitor<'tcx> for DropRangeVisitor<'a, 'tcx> {
443443
// We add an edge to the hir_id of the expression/block we are breaking out of, and
444444
// then in process_deferred_edges we will map this hir_id to its PostOrderId, which
445445
// will refer to the end of the block due to the post order traversal.
446-
self.find_target_expression_from_destination(destination).map_or((), |target| {
446+
if let Ok(target) = self.find_target_expression_from_destination(destination) {
447447
self.drop_ranges.add_control_edge_hir_id(self.expr_index, target)
448-
});
448+
}
449449

450450
if let Some(value) = value {
451451
self.visit_expr(value);

compiler/rustc_hir_typeck/src/generator_interior/drop_ranges/record_consumed_borrow.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,10 @@ impl<'tcx> expr_use_visitor::Delegate<'tcx> for ExprUseDelegate<'tcx> {
150150
hir.node_to_string(diag_expr_id),
151151
hir.node_to_string(parent)
152152
);
153-
place_with_id
154-
.try_into()
155-
.map_or((), |tracked_value| self.mark_consumed(parent, tracked_value));
153+
154+
if let Ok(tracked_value) = place_with_id.try_into() {
155+
self.mark_consumed(parent, tracked_value)
156+
}
156157
}
157158

158159
fn borrow(

library/core/src/option.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,7 @@ impl<T> Option<T> {
11251125
/// ```
11261126
#[inline]
11271127
#[stable(feature = "rust1", since = "1.0.0")]
1128+
#[must_use = "if you don't need the returned value, use `if let` instead"]
11281129
pub fn map_or<U, F>(self, default: U, f: F) -> U
11291130
where
11301131
F: FnOnce(T) -> U,

library/core/src/result.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,7 @@ impl<T, E> Result<T, E> {
768768
/// ```
769769
#[inline]
770770
#[stable(feature = "result_map_or", since = "1.41.0")]
771+
#[must_use = "if you don't need the returned value, use `if let` instead"]
771772
pub fn map_or<U, F: FnOnce(T) -> U>(self, default: U, f: F) -> U {
772773
match self {
773774
Ok(t) => f(t),

src/tools/clippy/clippy_lints/src/operators/bit_mask.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ fn check_compare(cx: &LateContext<'_>, bit_op: &Expr<'_>, cmp_op: BinOpKind, cmp
4040
if op.node != BinOpKind::BitAnd && op.node != BinOpKind::BitOr {
4141
return;
4242
}
43-
fetch_int_literal(cx, right)
44-
.or_else(|| fetch_int_literal(cx, left))
45-
.map_or((), |mask| check_bit_mask(cx, op.node, cmp_op, mask, cmp_value, span));
43+
if let Some(mask) = fetch_int_literal(cx, right).or_else(|| fetch_int_literal(cx, left)) {
44+
check_bit_mask(cx, op.node, cmp_op, mask, cmp_value, span);
45+
}
4646
}
4747
}
4848

src/tools/clippy/tests/ui/result_map_or_into_option.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ fn main() {
1515
// A non-Some `f` closure where the argument is not used as the
1616
// return should not emit the lint
1717
let opt: Result<u32, &str> = Ok(1);
18-
opt.map_or(None, |_x| Some(1));
18+
_ = opt.map_or(None, |_x| Some(1));
1919
}

src/tools/clippy/tests/ui/result_map_or_into_option.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ fn main() {
1515
// A non-Some `f` closure where the argument is not used as the
1616
// return should not emit the lint
1717
let opt: Result<u32, &str> = Ok(1);
18-
opt.map_or(None, |_x| Some(1));
18+
_ = opt.map_or(None, |_x| Some(1));
1919
}

0 commit comments

Comments
 (0)