mirror of https://github.com/rust-lang/rust.git
Mark `map_or` as `#[must_use]`
This commit is contained in:
parent
5a65be8152
commit
90f9640528
|
@ -140,7 +140,7 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
|
||||||
impl1_def_id: DefId,
|
impl1_def_id: DefId,
|
||||||
impl2_def_id: DefId,
|
impl2_def_id: DefId,
|
||||||
) {
|
) {
|
||||||
traits::overlapping_impls(
|
let maybe_overlap = traits::overlapping_impls(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
impl1_def_id,
|
impl1_def_id,
|
||||||
impl2_def_id,
|
impl2_def_id,
|
||||||
|
@ -148,11 +148,11 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
|
||||||
// inherent impls without warning.
|
// inherent impls without warning.
|
||||||
SkipLeakCheck::Yes,
|
SkipLeakCheck::Yes,
|
||||||
overlap_mode,
|
overlap_mode,
|
||||||
)
|
);
|
||||||
.map_or(true, |overlap| {
|
|
||||||
|
if let Some(overlap) = maybe_overlap {
|
||||||
self.check_for_common_items_in_impls(impl1_def_id, impl2_def_id, overlap);
|
self.check_for_common_items_in_impls(impl1_def_id, impl2_def_id, overlap);
|
||||||
false
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_item(&mut self, id: hir::ItemId) {
|
fn check_item(&mut self, id: hir::ItemId) {
|
||||||
|
|
|
@ -442,9 +442,9 @@ impl<'a, 'tcx> Visitor<'tcx> for DropRangeVisitor<'a, 'tcx> {
|
||||||
// We add an edge to the hir_id of the expression/block we are breaking out of, and
|
// We add an edge to the hir_id of the expression/block we are breaking out of, and
|
||||||
// then in process_deferred_edges we will map this hir_id to its PostOrderId, which
|
// then in process_deferred_edges we will map this hir_id to its PostOrderId, which
|
||||||
// will refer to the end of the block due to the post order traversal.
|
// will refer to the end of the block due to the post order traversal.
|
||||||
self.find_target_expression_from_destination(destination).map_or((), |target| {
|
if let Ok(target) = self.find_target_expression_from_destination(destination) {
|
||||||
self.drop_ranges.add_control_edge_hir_id(self.expr_index, target)
|
self.drop_ranges.add_control_edge_hir_id(self.expr_index, target)
|
||||||
});
|
}
|
||||||
|
|
||||||
if let Some(value) = value {
|
if let Some(value) = value {
|
||||||
self.visit_expr(value);
|
self.visit_expr(value);
|
||||||
|
|
|
@ -150,9 +150,10 @@ impl<'tcx> expr_use_visitor::Delegate<'tcx> for ExprUseDelegate<'tcx> {
|
||||||
hir.node_to_string(diag_expr_id),
|
hir.node_to_string(diag_expr_id),
|
||||||
hir.node_to_string(parent)
|
hir.node_to_string(parent)
|
||||||
);
|
);
|
||||||
place_with_id
|
|
||||||
.try_into()
|
if let Ok(tracked_value) = place_with_id.try_into() {
|
||||||
.map_or((), |tracked_value| self.mark_consumed(parent, tracked_value));
|
self.mark_consumed(parent, tracked_value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn borrow(
|
fn borrow(
|
||||||
|
|
|
@ -1125,6 +1125,7 @@ impl<T> Option<T> {
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[must_use = "if you don't need the returned value, use `if let` instead"]
|
||||||
pub fn map_or<U, F>(self, default: U, f: F) -> U
|
pub fn map_or<U, F>(self, default: U, f: F) -> U
|
||||||
where
|
where
|
||||||
F: FnOnce(T) -> U,
|
F: FnOnce(T) -> U,
|
||||||
|
|
|
@ -768,6 +768,7 @@ impl<T, E> Result<T, E> {
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "result_map_or", since = "1.41.0")]
|
#[stable(feature = "result_map_or", since = "1.41.0")]
|
||||||
|
#[must_use = "if you don't need the returned value, use `if let` instead"]
|
||||||
pub fn map_or<U, F: FnOnce(T) -> U>(self, default: U, f: F) -> U {
|
pub fn map_or<U, F: FnOnce(T) -> U>(self, default: U, f: F) -> U {
|
||||||
match self {
|
match self {
|
||||||
Ok(t) => f(t),
|
Ok(t) => f(t),
|
||||||
|
|
|
@ -40,9 +40,9 @@ fn check_compare(cx: &LateContext<'_>, bit_op: &Expr<'_>, cmp_op: BinOpKind, cmp
|
||||||
if op.node != BinOpKind::BitAnd && op.node != BinOpKind::BitOr {
|
if op.node != BinOpKind::BitAnd && op.node != BinOpKind::BitOr {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fetch_int_literal(cx, right)
|
if let Some(mask) = fetch_int_literal(cx, right).or_else(|| fetch_int_literal(cx, left)) {
|
||||||
.or_else(|| fetch_int_literal(cx, left))
|
check_bit_mask(cx, op.node, cmp_op, mask, cmp_value, span);
|
||||||
.map_or((), |mask| check_bit_mask(cx, op.node, cmp_op, mask, cmp_value, span));
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,5 +15,5 @@ fn main() {
|
||||||
// A non-Some `f` closure where the argument is not used as the
|
// A non-Some `f` closure where the argument is not used as the
|
||||||
// return should not emit the lint
|
// return should not emit the lint
|
||||||
let opt: Result<u32, &str> = Ok(1);
|
let opt: Result<u32, &str> = Ok(1);
|
||||||
opt.map_or(None, |_x| Some(1));
|
_ = opt.map_or(None, |_x| Some(1));
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,5 +15,5 @@ fn main() {
|
||||||
// A non-Some `f` closure where the argument is not used as the
|
// A non-Some `f` closure where the argument is not used as the
|
||||||
// return should not emit the lint
|
// return should not emit the lint
|
||||||
let opt: Result<u32, &str> = Ok(1);
|
let opt: Result<u32, &str> = Ok(1);
|
||||||
opt.map_or(None, |_x| Some(1));
|
_ = opt.map_or(None, |_x| Some(1));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue