Skip to content

Commit 3bd865c

Browse files
committed
Use OptionExt::is_none_or in the compiler
1 parent ddc72fe commit 3bd865c

File tree

36 files changed

+78
-42
lines changed

36 files changed

+78
-42
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use rustc_ast as ast;
22
use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor};
33
use rustc_ast::{attr, AssocConstraint, AssocConstraintKind, NodeId};
44
use rustc_ast::{PatKind, RangeEnd};
5+
use rustc_data_structures::OptionExt as _;
56
use rustc_errors::{Applicability, StashKey};
67
use rustc_feature::{AttributeGate, BuiltinAttribute, Features, GateIssue, BUILTIN_ATTRIBUTE_MAP};
78
use rustc_session::parse::{feature_err, feature_err_issue, feature_warn};
@@ -101,7 +102,7 @@ impl<'a> PostExpansionVisitor<'a> {
101102
.emit();
102103
}
103104
Err(abi::AbiDisabled::Unrecognized) => {
104-
if self.sess.opts.pretty.map_or(true, |ppm| ppm.needs_hir()) {
105+
if self.sess.opts.pretty.is_none_or(|ppm| ppm.needs_hir()) {
105106
self.sess.parse_sess.span_diagnostic.delay_span_bug(
106107
span,
107108
format!(

compiler/rustc_attr/src/builtin.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use rustc_ast::{self as ast, attr};
44
use rustc_ast::{Attribute, LitKind, MetaItem, MetaItemKind, MetaItemLit, NestedMetaItem, NodeId};
55
use rustc_ast_pretty::pprust;
6+
use rustc_data_structures::OptionExt as _;
67
use rustc_feature::{find_gated_cfg, is_builtin_attr_name, Features, GatedCfg};
78
use rustc_macros::HashStable_Generic;
89
use rustc_session::config::ExpectedValues;
@@ -1096,7 +1097,7 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
10961097
// the `check_mod_attrs` pass, but this pass doesn't always run
10971098
// (e.g. if we only pretty-print the source), so we have to gate
10981099
// the `delay_span_bug` call as follows:
1099-
if sess.opts.pretty.map_or(true, |pp| pp.needs_analysis()) {
1100+
if sess.opts.pretty.is_none_or(|pp| pp.needs_analysis()) {
11001101
diagnostic.delay_span_bug(item.span(), "unrecognized representation hint");
11011102
}
11021103
}

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::iter;
33
use either::Either;
44
use rustc_data_structures::captures::Captures;
55
use rustc_data_structures::fx::FxIndexSet;
6+
use rustc_data_structures::OptionExt as _;
67
use rustc_errors::{
78
struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, MultiSpan,
89
};
@@ -1328,7 +1329,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13281329
&& ex.span.contains(self.borrow_span)
13291330
// To support cases like `|| { v.call(|this| v.get()) }`
13301331
// FIXME: actually support such cases (need to figure out how to move from the capture place to original local)
1331-
&& self.res.as_ref().map_or(true, |(prev_res, _)| prev_res.span.contains(ex.span))
1332+
&& self.res.as_ref().is_none_or(|(prev_res, _)| prev_res.span.contains(ex.span))
13321333
{
13331334
self.res = Some((ex, closure));
13341335
}

compiler/rustc_borrowck/src/type_check/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use either::Either;
1010
use hir::OpaqueTyOrigin;
1111
use rustc_data_structures::frozen::Frozen;
1212
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
13+
use rustc_data_structures::OptionExt as _;
1314
use rustc_hir as hir;
1415
use rustc_hir::def::DefKind;
1516
use rustc_hir::def_id::LocalDefId;
@@ -1812,7 +1813,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
18121813
// than 1.
18131814
// If the length is larger than 1, the repeat expression will need to copy the
18141815
// element, so we require the `Copy` trait.
1815-
if len.try_eval_target_usize(tcx, self.param_env).map_or(true, |len| len > 1) {
1816+
if len.try_eval_target_usize(tcx, self.param_env).is_none_or(|len| len > 1) {
18161817
match operand {
18171818
Operand::Copy(..) | Operand::Constant(..) => {
18181819
// These are always okay: direct use of a const, or a value that can evidently be copied.

compiler/rustc_const_eval/src/interpret/intern.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
1717
use super::validity::RefTracking;
1818
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
19+
use rustc_data_structures::OptionExt as _;
1920
use rustc_errors::ErrorGuaranteed;
2021
use rustc_hir as hir;
2122
use rustc_middle::mir::interpret::InterpResult;
@@ -114,7 +115,7 @@ fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx, const_eval:
114115
if let InternMode::Static(mutability) = mode {
115116
// For this, we need to take into account `UnsafeCell`. When `ty` is `None`, we assume
116117
// no interior mutability.
117-
let frozen = ty.map_or(true, |ty| ty.is_freeze(*ecx.tcx, ecx.param_env));
118+
let frozen = ty.is_none_or(|ty| ty.is_freeze(*ecx.tcx, ecx.param_env));
118119
// For statics, allocation mutability is the combination of place mutability and
119120
// type mutability.
120121
// The entire allocation needs to be mutable if it contains an `UnsafeCell` anywhere.

compiler/rustc_const_eval/src/interpret/memory.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::ptr;
1414

1515
use rustc_ast::Mutability;
1616
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
17+
use rustc_data_structures::OptionExt as _;
1718
use rustc_middle::mir::display_allocation;
1819
use rustc_middle::ty::{self, Instance, ParamEnv, Ty, TyCtxt};
1920
use rustc_target::abi::{Align, HasDataLayout, Size};
@@ -422,7 +423,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
422423
let (alloc_size, alloc_align, ret_val) = alloc_size(alloc_id, offset, prov)?;
423424
// Test bounds. This also ensures non-null.
424425
// It is sufficient to check this for the end pointer. Also check for overflow!
425-
if offset.checked_add(size, &self.tcx).map_or(true, |end| end > alloc_size) {
426+
if offset.checked_add(size, &self.tcx).is_none_or(|end| end > alloc_size) {
426427
throw_ub!(PointerOutOfBounds {
427428
alloc_id,
428429
alloc_size,

compiler/rustc_const_eval/src/interpret/projection.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
1010
use either::{Left, Right};
1111

12+
use rustc_data_structures::OptionExt as _;
1213
use rustc_middle::mir;
1314
use rustc_middle::ty;
1415
use rustc_middle::ty::layout::LayoutOf;
@@ -294,7 +295,7 @@ where
294295
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
295296
let len = base.len(self)?; // also asserts that we have a type where this makes sense
296297
let actual_to = if from_end {
297-
if from.checked_add(to).map_or(true, |to| to > len) {
298+
if from.checked_add(to).is_none_or(|to| to > len) {
298299
// This can only be reached in ConstProp and non-rustc-MIR.
299300
throw_ub!(BoundsCheckFailed { len: len, index: from.saturating_add(to) });
300301
}

compiler/rustc_data_structures/src/option_ext.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
pub trait OptionExt {
33
type T;
44

5+
/// Returns `true` if `self` is `None` or the value inside the `Some` matches a predicate `f`.
56
fn is_none_or(self, f: impl FnOnce(Self::T) -> bool) -> bool;
67
}
78

89
impl<T> OptionExt for Option<T> {
910
type T = T;
1011

11-
/// Returns `true` is `self` is `None` or the value inside matches a predicate `f`.
1212
fn is_none_or(self, f: impl FnOnce(T) -> bool) -> bool {
1313
match self {
1414
None => true,

compiler/rustc_expand/src/config.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_ast::{self as ast, AttrStyle, Attribute, HasAttrs, HasTokens, MetaItem
1414
use rustc_attr as attr;
1515
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
1616
use rustc_data_structures::fx::FxHashMap;
17+
use rustc_data_structures::OptionExt as _;
1718
use rustc_feature::{Feature, Features, State as FeatureState};
1819
use rustc_feature::{
1920
ACCEPTED_FEATURES, ACTIVE_FEATURES, REMOVED_FEATURES, STABLE_REMOVED_FEATURES,
@@ -427,15 +428,15 @@ impl<'a> StripUnconfigured<'a> {
427428
return true;
428429
}
429430
};
430-
parse_cfg(&meta_item, &self.sess).map_or(true, |meta_item| {
431+
parse_cfg(&meta_item, &self.sess).is_none_or(|meta_item| {
431432
attr::cfg_matches(&meta_item, &self.sess.parse_sess, self.lint_node_id, self.features)
432433
})
433434
}
434435

435436
/// If attributes are not allowed on expressions, emit an error for `attr`
436437
#[instrument(level = "trace", skip(self))]
437438
pub(crate) fn maybe_emit_expr_attr_err(&self, attr: &Attribute) {
438-
if !self.features.map_or(true, |features| features.stmt_expr_attributes) {
439+
if !self.features.is_none_or(|features| features.stmt_expr_attributes) {
439440
let mut err = feature_err(
440441
&self.sess.parse_sess,
441442
sym::stmt_expr_attributes,

compiler/rustc_expand/src/mbe/diagnostics.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::mbe::{
77
use rustc_ast::token::{self, Token, TokenKind};
88
use rustc_ast::tokenstream::TokenStream;
99
use rustc_ast_pretty::pprust;
10+
use rustc_data_structures::OptionExt as _;
1011
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, DiagnosticMessage};
1112
use rustc_parse::parser::{Parser, Recovery};
1213
use rustc_span::source_map::SourceMap;
@@ -155,7 +156,7 @@ impl<'a, 'cx, 'matcher> Tracker<'matcher> for CollectTrackerAndEmitter<'a, 'cx,
155156
if self
156157
.best_failure
157158
.as_ref()
158-
.map_or(true, |failure| failure.is_better_position(*approx_position))
159+
.is_none_or(|failure| failure.is_better_position(*approx_position))
159160
{
160161
self.best_failure = Some(BestFailure {
161162
token: token.clone(),

compiler/rustc_hir/src/def.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use rustc_ast as ast;
44
use rustc_ast::NodeId;
55
use rustc_data_structures::fx::FxHashMap;
66
use rustc_data_structures::stable_hasher::ToStableHashKey;
7+
use rustc_data_structures::OptionExt as _;
78
use rustc_macros::HashStable_Generic;
89
use rustc_span::def_id::{DefId, LocalDefId};
910
use rustc_span::hygiene::MacroKind;
@@ -731,7 +732,7 @@ impl<Id> Res<Id> {
731732

732733
/// Always returns `true` if `self` is `Res::Err`
733734
pub fn matches_ns(&self, ns: Namespace) -> bool {
734-
self.ns().map_or(true, |actual_ns| actual_ns == ns)
735+
self.ns().is_none_or(|actual_ns| actual_ns == ns)
735736
}
736737

737738
/// Returns whether such a resolved path can occur in a tuple struct/variant pattern

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::collect::ItemCtxt;
44
use crate::constrained_generic_params as cgp;
55
use hir::{HirId, Node};
66
use rustc_data_structures::fx::FxIndexSet;
7+
use rustc_data_structures::OptionExt as _;
78
use rustc_hir as hir;
89
use rustc_hir::def::DefKind;
910
use rustc_hir::def_id::{DefId, LocalDefId};
@@ -803,7 +804,7 @@ impl<'tcx> ItemCtxt<'tcx> {
803804
bound_ty,
804805
predicate.bounds.iter().filter(|bound| {
805806
assoc_name
806-
.map_or(true, |assoc_name| self.bound_defines_assoc_item(bound, assoc_name))
807+
.is_none_or(|assoc_name| self.bound_defines_assoc_item(bound, assoc_name))
807808
}),
808809
&mut bounds,
809810
bound_vars,

compiler/rustc_hir_typeck/src/_match.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::coercion::{AsCoercionSite, CoerceMany};
22
use crate::{Diverges, Expectation, FnCtxt, Needs};
3+
use rustc_data_structures::OptionExt as _;
34
use rustc_errors::{Applicability, Diagnostic, MultiSpan};
45
use rustc_hir::{self as hir, ExprKind};
56
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
@@ -211,7 +212,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
211212
let ret_ty = ret_coercion.borrow().expected_ty();
212213
let ret_ty = self.inh.infcx.shallow_resolve(ret_ty);
213214
self.can_coerce(arm_ty, ret_ty)
214-
&& prior_arm.map_or(true, |(_, ty, _)| self.can_coerce(ty, ret_ty))
215+
&& prior_arm.is_none_or(|(_, ty, _)| self.can_coerce(ty, ret_ty))
215216
// The match arms need to unify for the case of `impl Trait`.
216217
&& !matches!(ret_ty.kind(), ty::Alias(ty::Opaque, ..))
217218
}

compiler/rustc_hir_typeck/src/coercion.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
//! ```
3737
3838
use crate::FnCtxt;
39+
use rustc_data_structures::OptionExt as _;
3940
use rustc_errors::{
4041
struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, MultiSpan,
4142
};
@@ -917,7 +918,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
917918
if self
918919
.tcx
919920
.upvars_mentioned(closure_def_id_a.expect_local())
920-
.map_or(true, |u| u.is_empty()) =>
921+
.is_none_or(|u| u.is_empty()) =>
921922
{
922923
// We coerce the closure, which has fn type
923924
// `extern "rust-call" fn((arg0,arg1,...)) -> _`

compiler/rustc_hir_typeck/src/expr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use crate::{
2222
use rustc_ast as ast;
2323
use rustc_data_structures::fx::FxHashMap;
2424
use rustc_data_structures::stack::ensure_sufficient_stack;
25+
use rustc_data_structures::OptionExt as _;
2526
use rustc_errors::{
2627
pluralize, struct_span_err, AddToDiagnostic, Applicability, Diagnostic, DiagnosticBuilder,
2728
DiagnosticId, ErrorGuaranteed, StashKey,
@@ -1467,7 +1468,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14671468

14681469
// If the length is 0, we don't create any elements, so we don't copy any. If the length is 1, we
14691470
// don't copy that one element, we move it. Only check for Copy if the length is larger.
1470-
if count.try_eval_target_usize(tcx, self.param_env).map_or(true, |len| len > 1) {
1471+
if count.try_eval_target_usize(tcx, self.param_env).is_none_or(|len| len > 1) {
14711472
let lang_item = self.tcx.require_lang_item(LangItem::Copy, None);
14721473
let code = traits::ObligationCauseCode::RepeatElementCopy { is_const_fn };
14731474
self.require_type_meets(element_ty, element.span, code, lang_item);

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::{
1010
};
1111
use rustc_ast as ast;
1212
use rustc_data_structures::fx::FxIndexSet;
13+
use rustc_data_structures::OptionExt as _;
1314
use rustc_errors::{
1415
pluralize, Applicability, Diagnostic, DiagnosticId, ErrorGuaranteed, MultiSpan,
1516
};
@@ -940,7 +941,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
940941
if only_extras_so_far
941942
&& errors
942943
.peek()
943-
.map_or(true, |next_error| !matches!(next_error, Error::Extra(_)))
944+
.is_none_or(|next_error| !matches!(next_error, Error::Extra(_)))
944945
{
945946
let next = provided_arg_tys
946947
.get(arg_idx + 1)
@@ -1955,7 +1956,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19551956
for (_, param) in params
19561957
.into_iter()
19571958
.enumerate()
1958-
.filter(|(idx, _)| expected_idx.map_or(true, |expected_idx| expected_idx == *idx))
1959+
.filter(|(idx, _)| expected_idx.is_none_or(|expected_idx| expected_idx == *idx))
19591960
{
19601961
spans.push_span_label(param.span, "");
19611962
}

compiler/rustc_hir_typeck/src/generator_interior/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use self::drop_ranges::DropRanges;
77
use super::FnCtxt;
88
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
9+
use rustc_data_structures::OptionExt as _;
910
use rustc_errors::{pluralize, DelayDm};
1011
use rustc_hir as hir;
1112
use rustc_hir::def::{CtorKind, DefKind, Res};
@@ -456,7 +457,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> {
456457
// doesn't match the behavior of MIR borrowck and causes ICEs. See the FIXME comment in
457458
// tests/ui/generator/drop-tracking-parent-expression.rs.
458459
let scope = if self.drop_ranges.is_borrowed_temporary(expr)
459-
|| ty.map_or(true, |ty| {
460+
|| ty.is_none_or(|ty| {
460461
// Avoid ICEs in needs_drop.
461462
let ty = self.fcx.resolve_vars_if_possible(ty);
462463
let ty = self.fcx.tcx.erase_regions(ty);

compiler/rustc_lint/src/expect.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::lints::{Expectation, ExpectationNote};
2+
use rustc_data_structures::OptionExt as _;
23
use rustc_middle::query::Providers;
34
use rustc_middle::ty::TyCtxt;
45
use rustc_session::lint::builtin::UNFULFILLED_LINT_EXPECTATIONS;
@@ -25,7 +26,7 @@ fn check_expectations(tcx: TyCtxt<'_>, tool_filter: Option<Symbol>) {
2526
// holds stable ids
2627
if let LintExpectationId::Stable { hir_id, .. } = id {
2728
if !fulfilled_expectations.contains(&id)
28-
&& tool_filter.map_or(true, |filter| expectation.lint_tool == Some(filter))
29+
&& tool_filter.is_none_or(|filter| expectation.lint_tool == Some(filter))
2930
{
3031
let rationale = expectation.reason.map(|rationale| ExpectationNote { rationale });
3132
let note = expectation.is_unfulfilled_lint_expectations.then_some(());

compiler/rustc_middle/src/mir/interpret/allocation/provenance_map.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use std::cmp;
55

66
use rustc_data_structures::sorted_map::SortedMap;
7+
use rustc_data_structures::OptionExt as _;
78
use rustc_target::abi::{HasDataLayout, Size};
89

910
use super::{alloc_range, AllocError, AllocId, AllocRange, AllocResult, Provenance};
@@ -90,7 +91,7 @@ impl<Prov: Provenance> ProvenanceMap<Prov> {
9091
debug_assert!(prov.len() <= 1);
9192
if let Some(entry) = prov.first() {
9293
// If it overlaps with this byte, it is on this byte.
93-
debug_assert!(self.bytes.as_ref().map_or(true, |b| b.get(&offset).is_none()));
94+
debug_assert!(self.bytes.as_ref().is_none_or(|b| b.get(&offset).is_none()));
9495
Some(entry.1)
9596
} else {
9697
// Look up per-byte provenance.
@@ -275,7 +276,7 @@ impl<Prov: Provenance> ProvenanceMap<Prov> {
275276
// For really small copies, make sure we don't start before `src` does.
276277
let entry_start = cmp::max(entry.0, src.start);
277278
for offset in entry_start..src.end() {
278-
if bytes.last().map_or(true, |bytes_entry| bytes_entry.0 < offset) {
279+
if bytes.last().is_none_or(|bytes_entry| bytes_entry.0 < offset) {
279280
// The last entry, if it exists, has a lower offset than us.
280281
bytes.push((offset, entry.1));
281282
} else {

compiler/rustc_middle/src/ty/instance.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
22
use crate::ty::print::{FmtPrinter, Printer};
33
use crate::ty::{self, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable};
44
use crate::ty::{EarlyBinder, InternalSubsts, SubstsRef, TypeVisitableExt};
5+
use rustc_data_structures::OptionExt as _;
56
use rustc_errors::ErrorGuaranteed;
67
use rustc_hir::def::Namespace;
78
use rustc_hir::def_id::{CrateNum, DefId};
@@ -241,7 +242,7 @@ impl<'tcx> InstanceDef<'tcx> {
241242
// We include enums without destructors to allow, say, optimizing
242243
// drops of `Option::None` before LTO. We also respect the intent of
243244
// `#[inline]` on `Drop::drop` implementations.
244-
return ty.ty_adt_def().map_or(true, |adt_def| {
245+
return ty.ty_adt_def().is_none_or(|adt_def| {
245246
adt_def.destructor(tcx).map_or_else(
246247
|| adt_def.is_enum(),
247248
|dtor| tcx.codegen_fn_attrs(dtor.did).requests_inline(),

compiler/rustc_middle/src/values.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::dep_graph::DepKind;
22
use rustc_data_structures::fx::FxHashSet;
3+
use rustc_data_structures::OptionExt as _;
34
use rustc_errors::{pluralize, struct_span_err, Applicability, MultiSpan};
45
use rustc_hir as hir;
56
use rustc_hir::def::{DefKind, Res};
@@ -207,7 +208,7 @@ fn find_item_ty_spans(
207208
hir::TyKind::Path(hir::QPath::Resolved(_, path)) => {
208209
if let Res::Def(kind, def_id) = path.res
209210
&& kind != DefKind::TyAlias {
210-
let check_params = def_id.as_local().map_or(true, |def_id| {
211+
let check_params = def_id.as_local().is_none_or(|def_id| {
211212
if def_id == needle {
212213
spans.push(ty.span);
213214
}

compiler/rustc_mir_build/src/check_unsafety.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::build::ExprCategory;
22
use crate::errors::*;
33
use rustc_middle::thir::visit::{self, Visitor};
44

5+
use rustc_data_structures::OptionExt as _;
56
use rustc_hir as hir;
67
use rustc_middle::mir::BorrowKind;
78
use rustc_middle::thir::*;
@@ -164,7 +165,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for LayoutConstrainedPlaceVisitor<'a, 'tcx> {
164165
// place, i.e. the expression is a place expression and not a dereference
165166
// (since dereferencing something leads us to a different place).
166167
ExprKind::Deref { .. } => {}
167-
ref kind if ExprCategory::of(kind).map_or(true, |cat| cat == ExprCategory::Place) => {
168+
ref kind if ExprCategory::of(kind).is_none_or(|cat| cat == ExprCategory::Place) => {
168169
visit::walk_expr(self, expr);
169170
}
170171

0 commit comments

Comments
 (0)