Skip to content

Commit 264fa0f

Browse files
committed
Run clippy --fix for unnecessary_map_or lint
1 parent 39dc268 commit 264fa0f

File tree

39 files changed

+61
-67
lines changed

39 files changed

+61
-67
lines changed

compiler/rustc_ast_lowering/src/delegation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
7272
if let Some(local_sig_id) = def_id.as_local() {
7373
// The value may be missing due to recursive delegation.
7474
// Error will be emitted later during HIR ty lowering.
75-
self.resolver.delegation_fn_sigs.get(&local_sig_id).map_or(false, |sig| sig.has_self)
75+
self.resolver.delegation_fn_sigs.get(&local_sig_id).is_some_and(|sig| sig.has_self)
7676
} else {
7777
match self.tcx.def_kind(def_id) {
7878
DefKind::Fn => false,

compiler/rustc_ast_passes/src/feature_gate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl<'a> PostExpansionVisitor<'a> {
8383
feature_err_issue(&self.sess, feature, span, GateIssue::Language, explain).emit();
8484
}
8585
Err(abi::AbiDisabled::Unrecognized) => {
86-
if self.sess.opts.pretty.map_or(true, |ppm| ppm.needs_hir()) {
86+
if self.sess.opts.pretty.is_none_or(|ppm| ppm.needs_hir()) {
8787
self.sess.dcx().span_delayed_bug(
8888
span,
8989
format!(

compiler/rustc_attr_parsing/src/attributes/repr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ pub fn parse_repr_attr(sess: &Session, attr: &impl AttributeExt) -> Vec<ReprAttr
166166
// the `check_mod_attrs` pass, but this pass doesn't always run
167167
// (e.g. if we only pretty-print the source), so we have to gate
168168
// the `span_delayed_bug` call as follows:
169-
if sess.opts.pretty.map_or(true, |pp| pp.needs_analysis()) {
169+
if sess.opts.pretty.is_none_or(|pp| pp.needs_analysis()) {
170170
dcx.span_delayed_bug(item.span(), "unrecognized representation hint");
171171
}
172172
}

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2480,7 +2480,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
24802480
// To support cases like `|| { v.call(|this| v.get()) }`
24812481
// FIXME: actually support such cases (need to figure out how to move from the
24822482
// capture place to original local).
2483-
&& self.res.as_ref().map_or(true, |(prev_res, _)| prev_res.span.contains(ex.span))
2483+
&& self.res.as_ref().is_none_or(|(prev_res, _)| prev_res.span.contains(ex.span))
24842484
{
24852485
self.res = Some((ex, closure));
24862486
}

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ impl<'tcx> BorrowExplanation<'tcx> {
131131
&& let Ok(pat) = tcx.sess.source_map().span_to_snippet(pat.span)
132132
{
133133
suggest_rewrite_if_let(tcx, expr, &pat, init, conseq, alt, err);
134-
} else if path_span.map_or(true, |path_span| path_span == var_or_use_span) {
134+
} else if path_span.is_none_or(|path_span| path_span == var_or_use_span) {
135135
// We can use `var_or_use_span` if either `path_span` is not present, or both
136136
// spans are the same.
137-
if borrow_span.map_or(true, |sp| !sp.overlaps(var_or_use_span)) {
137+
if borrow_span.is_none_or(|sp| !sp.overlaps(var_or_use_span)) {
138138
err.span_label(
139139
var_or_use_span,
140140
format!("{borrow_desc}borrow later {message}"),

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ pub(crate) fn type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) ->
442442
// (or if there is no allocator argument).
443443
ty::Adt(def, args)
444444
if def.is_box()
445-
&& args.get(1).map_or(true, |arg| cx.layout_of(arg.expect_ty()).is_1zst()) =>
445+
&& args.get(1).is_none_or(|arg| cx.layout_of(arg.expect_ty()).is_1zst()) =>
446446
{
447447
build_pointer_or_reference_di_node(cx, t, t.expect_boxed_ty(), unique_type_id)
448448
}

compiler/rustc_errors/src/emitter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3146,7 +3146,7 @@ impl FileWithAnnotatedLines {
31463146
add_annotation_to_file(&mut output, Lrc::clone(&file), line, ann.as_line());
31473147
}
31483148
let line_end = ann.line_end - 1;
3149-
let end_is_empty = file.get_line(line_end - 1).map_or(false, |s| !filter(&s));
3149+
let end_is_empty = file.get_line(line_end - 1).is_some_and(|s| !filter(&s));
31503150
if middle < line_end && !end_is_empty {
31513151
add_annotation_to_file(&mut output, Lrc::clone(&file), line_end, ann.as_line());
31523152
}

compiler/rustc_errors/src/json.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ impl DiagnosticSpan {
463463
// is an empty string, increase the length to include the newline so we don't
464464
// leave an empty line
465465
if start.col.0 == 0
466-
&& suggestion.map_or(false, |(s, _)| s.is_empty())
466+
&& suggestion.is_some_and(|(s, _)| s.is_empty())
467467
&& let Ok(after) = je.sm.span_to_next_source(span)
468468
&& after.starts_with('\n')
469469
{

compiler/rustc_errors/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1717,7 +1717,7 @@ impl DiagCtxtInner {
17171717
let bugs: Vec<_> =
17181718
std::mem::take(&mut self.delayed_bugs).into_iter().map(|(b, _)| b).collect();
17191719

1720-
let backtrace = std::env::var_os("RUST_BACKTRACE").map_or(true, |x| &x != "0");
1720+
let backtrace = std::env::var_os("RUST_BACKTRACE").is_none_or(|x| &x != "0");
17211721
let decorate = backtrace || self.ice_file.is_none();
17221722
let mut out = self
17231723
.ice_file

compiler/rustc_expand/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ impl<'a> StripUnconfigured<'a> {
391391
validate_attr::deny_builtin_meta_unsafety(&self.sess.psess, &meta_item);
392392

393393
(
394-
parse_cfg(&meta_item, self.sess).map_or(true, |meta_item| {
394+
parse_cfg(&meta_item, self.sess).is_none_or(|meta_item| {
395395
attr::cfg_matches(meta_item, &self.sess, self.lint_node_id, self.features)
396396
}),
397397
Some(meta_item),

compiler/rustc_expand/src/mbe/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl<'dcx, 'matcher> Tracker<'matcher> for CollectTrackerAndEmitter<'dcx, 'match
159159
if self
160160
.best_failure
161161
.as_ref()
162-
.map_or(true, |failure| failure.is_better_position(*approx_position))
162+
.is_none_or(|failure| failure.is_better_position(*approx_position))
163163
{
164164
self.best_failure = Some(BestFailure {
165165
token: token.clone(),

compiler/rustc_hir/src/def.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ impl<Id> Res<Id> {
794794

795795
/// Always returns `true` if `self` is `Res::Err`
796796
pub fn matches_ns(&self, ns: Namespace) -> bool {
797-
self.ns().map_or(true, |actual_ns| actual_ns == ns)
797+
self.ns().is_none_or(|actual_ns| actual_ns == ns)
798798
}
799799

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

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12101210
// - foo((), "current", 42u32, "next")
12111211
// + foo((), 42u32)
12121212
{
1213-
prev_extra_idx.map_or(true, |prev_extra_idx| {
1213+
prev_extra_idx.is_none_or(|prev_extra_idx| {
12141214
prev_extra_idx + 1 == arg_idx.index()
12151215
})
12161216
}

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11431143
self.may_coerce(found, ty)
11441144
}
11451145
hir::FnRetTy::DefaultReturn(_) if in_closure => {
1146-
self.ret_coercion.as_ref().map_or(false, |ret| {
1146+
self.ret_coercion.as_ref().is_some_and(|ret| {
11471147
let ret_ty = ret.borrow().expected_ty();
11481148
self.may_coerce(found, ret_ty)
11491149
})
@@ -1784,14 +1784,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17841784
let results = self.typeck_results.borrow();
17851785
// First, look for a `Clone::clone` call
17861786
if segment.ident.name == sym::clone
1787-
&& results.type_dependent_def_id(expr.hir_id).map_or(
1788-
false,
1789-
|did| {
1787+
&& results.type_dependent_def_id(expr.hir_id).is_some_and(|did| {
17901788
let assoc_item = self.tcx.associated_item(did);
17911789
assoc_item.container == ty::AssocItemContainer::Trait
17921790
&& assoc_item.container_id(self.tcx) == clone_trait_did
1793-
},
1794-
)
1791+
})
17951792
// If that clone call hasn't already dereferenced the self type (i.e. don't give this
17961793
// diagnostic in cases where we have `(&&T).clone()` and we expect `T`).
17971794
&& !results.expr_adjustments(callee_expr).iter().any(|adj| matches!(adj.kind, ty::adjustment::Adjust::Deref(..)))

compiler/rustc_hir_typeck/src/method/suggest.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -3761,18 +3761,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
37613761
hir::TraitFn::Required([ident, ..]) => {
37623762
ident.name == kw::SelfLower
37633763
}
3764-
hir::TraitFn::Provided(body_id) => {
3765-
self.tcx.hir().body(*body_id).params.first().map_or(
3766-
false,
3767-
|param| {
3768-
matches!(
3769-
param.pat.kind,
3770-
hir::PatKind::Binding(_, _, ident, _)
3771-
if ident.name == kw::SelfLower
3772-
)
3773-
},
3774-
)
3775-
}
3764+
hir::TraitFn::Provided(body_id) => self
3765+
.tcx
3766+
.hir()
3767+
.body(*body_id)
3768+
.params
3769+
.first()
3770+
.is_some_and(|param| {
3771+
matches!(
3772+
param.pat.kind,
3773+
hir::PatKind::Binding(_, _, ident, _)
3774+
if ident.name == kw::SelfLower
3775+
)
3776+
}),
37763777
_ => false,
37773778
};
37783779

compiler/rustc_index/src/interval.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ impl<I: Idx> IntervalSet<I> {
258258
}
259259
current = Some(*end);
260260
}
261-
current.map_or(true, |x| x < self.domain as u32)
261+
current.is_none_or(|x| x < self.domain as u32)
262262
}
263263
}
264264

compiler/rustc_lint/src/expect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fn check_expectations(tcx: TyCtxt<'_>, tool_filter: Option<Symbol>) {
5757
let expect_id = canonicalize_id(expect_id);
5858

5959
if !fulfilled_expectations.contains(&expect_id)
60-
&& tool_filter.map_or(true, |filter| expectation.lint_tool == Some(filter))
60+
&& tool_filter.is_none_or(|filter| expectation.lint_tool == Some(filter))
6161
{
6262
let rationale = expectation.reason.map(|rationale| ExpectationNote { rationale });
6363
let note = expectation.is_unfulfilled_lint_expectations;

compiler/rustc_metadata/src/creader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
417417
// Any descendants of `std` should be private. These crates are usually not marked
418418
// private in metadata, so we ignore that field.
419419
if extern_private.is_none()
420-
&& dep_root.map_or(false, |d| STDLIB_STABLE_CRATES.contains(&d.name))
420+
&& dep_root.is_some_and(|d| STDLIB_STABLE_CRATES.contains(&d.name))
421421
{
422422
return true;
423423
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl<Prov: Provenance> ProvenanceMap<Prov> {
9797
debug_assert!(prov.len() <= 1);
9898
if let Some(entry) = prov.first() {
9999
// If it overlaps with this byte, it is on this byte.
100-
debug_assert!(self.bytes.as_ref().map_or(true, |b| b.get(&offset).is_none()));
100+
debug_assert!(self.bytes.as_ref().is_none_or(|b| b.get(&offset).is_none()));
101101
Some(entry.1)
102102
} else {
103103
// Look up per-byte provenance.
@@ -301,7 +301,7 @@ impl<Prov: Provenance> ProvenanceMap<Prov> {
301301
// For really small copies, make sure we don't start before `src` does.
302302
let entry_start = cmp::max(entry.0, src.start);
303303
for offset in entry_start..src.end() {
304-
if bytes.last().map_or(true, |bytes_entry| bytes_entry.0 < offset) {
304+
if bytes.last().is_none_or(|bytes_entry| bytes_entry.0 < offset) {
305305
// The last entry, if it exists, has a lower offset than us.
306306
bytes.push((offset, entry.1));
307307
} else {

compiler/rustc_middle/src/ty/closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ pub fn analyze_coroutine_closure_captures<'a, 'tcx: 'a, T>(
433433
// A parent matches a child if they share the same prefix of projections.
434434
// The child may have more, if it is capturing sub-fields out of
435435
// something that is captured by-move in the parent closure.
436-
while child_captures.peek().map_or(false, |(_, child_capture)| {
436+
while child_captures.peek().is_some_and(|(_, child_capture)| {
437437
child_prefix_matches_parent_projections(parent_capture, child_capture)
438438
}) {
439439
let (child_field_idx, child_capture) = child_captures.next().unwrap();

compiler/rustc_middle/src/ty/instance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ impl<'tcx> InstanceKind<'tcx> {
328328
// We include enums without destructors to allow, say, optimizing
329329
// drops of `Option::None` before LTO. We also respect the intent of
330330
// `#[inline]` on `Drop::drop` implementations.
331-
return ty.ty_adt_def().map_or(true, |adt_def| {
331+
return ty.ty_adt_def().is_none_or(|adt_def| {
332332
match *self {
333333
ty::InstanceKind::DropGlue(..) => adt_def.destructor(tcx).map(|dtor| dtor.did),
334334
ty::InstanceKind::AsyncDropGlueCtorShim(..) => {

compiler/rustc_middle/src/ty/sty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1894,11 +1894,11 @@ impl<'tcx> Ty<'tcx> {
18941894

18951895
ty::Str | ty::Slice(_) | ty::Dynamic(_, _, ty::Dyn) | ty::Foreign(..) => false,
18961896

1897-
ty::Tuple(tys) => tys.last().map_or(true, |ty| ty.is_trivially_sized(tcx)),
1897+
ty::Tuple(tys) => tys.last().is_none_or(|ty| ty.is_trivially_sized(tcx)),
18981898

18991899
ty::Adt(def, args) => def
19001900
.sized_constraint(tcx)
1901-
.map_or(true, |ty| ty.instantiate(tcx, args).is_trivially_sized(tcx)),
1901+
.is_none_or(|ty| ty.instantiate(tcx, args).is_trivially_sized(tcx)),
19021902

19031903
ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) | ty::Bound(..) => false,
19041904

compiler/rustc_middle/src/values.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ fn find_item_ty_spans(
360360
if let Res::Def(kind, def_id) = path.res
361361
&& matches!(kind, DefKind::Enum | DefKind::Struct | DefKind::Union)
362362
{
363-
let check_params = def_id.as_local().map_or(true, |def_id| {
363+
let check_params = def_id.as_local().is_none_or(|def_id| {
364364
if def_id == needle {
365365
spans.push(ty.span);
366366
}

compiler/rustc_mir_build/src/check_unsafety.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for LayoutConstrainedPlaceVisitor<'a, 'tcx> {
266266
// place, i.e. the expression is a place expression and not a dereference
267267
// (since dereferencing something leads us to a different place).
268268
ExprKind::Deref { .. } => {}
269-
ref kind if ExprCategory::of(kind).map_or(true, |cat| cat == ExprCategory::Place) => {
269+
ref kind if ExprCategory::of(kind).is_none_or(|cat| cat == ExprCategory::Place) => {
270270
visit::walk_expr(self, expr);
271271
}
272272

compiler/rustc_mir_dataflow/src/framework/graphviz.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ where
608608
let before = diffs_before.as_mut().map(next_in_dataflow_order);
609609

610610
assert!(diffs_after.is_empty());
611-
assert!(diffs_before.as_ref().map_or(true, ExactSizeIterator::is_empty));
611+
assert!(diffs_before.as_ref().is_none_or(ExactSizeIterator::is_empty));
612612

613613
let terminator = self.cursor.body()[block].terminator();
614614
let mut terminator_str = String::new();

compiler/rustc_mir_transform/src/coverage/graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl CoverageGraph {
135135
bb_to_bcb[bb] = Some(bcb);
136136
}
137137

138-
let is_out_summable = basic_blocks.last().map_or(false, |&bb| {
138+
let is_out_summable = basic_blocks.last().is_some_and(|&bb| {
139139
bcb_filtered_successors(mir_body[bb].terminator()).is_out_summable()
140140
});
141141
let bcb_data = BasicCoverageBlockData { basic_blocks, is_out_summable };

compiler/rustc_next_trait_solver/src/canonicalizer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ impl<'a, D: SolverDelegate<Interner = I>, I: Interner> Canonicalizer<'a, D, I> {
273273
//
274274
// For this we set `next_orig_uv` to the next smallest, not yet compressed,
275275
// universe of the input.
276-
if next_orig_uv.map_or(true, |curr_next_uv| uv.cannot_name(curr_next_uv)) {
276+
if next_orig_uv.is_none_or(|curr_next_uv| uv.cannot_name(curr_next_uv)) {
277277
next_orig_uv = Some(uv);
278278
}
279279
}

compiler/rustc_parse/src/parser/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2095,7 +2095,7 @@ impl<'a> Parser<'a> {
20952095
// point literal here, since there's no use of the exponent
20962096
// syntax that also constitutes a valid integer, so we need
20972097
// not check for that.
2098-
if suffix.map_or(true, |s| s == sym::f32 || s == sym::f64)
2098+
if suffix.is_none_or(|s| s == sym::f32 || s == sym::f64)
20992099
&& symbol.as_str().chars().all(|c| c.is_numeric() || c == '_')
21002100
&& self.token.span.hi() == next_token.span.lo()
21012101
{

compiler/rustc_passes/src/dead.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalModDefId) {
12311231
continue;
12321232
}
12331233

1234-
let is_positional = variant.fields.raw.first().map_or(false, |field| {
1234+
let is_positional = variant.fields.raw.first().is_some_and(|field| {
12351235
field.name.as_str().starts_with(|c: char| c.is_ascii_digit())
12361236
});
12371237
let report_on =

compiler/rustc_resolve/src/check_unused.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ impl Resolver<'_, '_> {
397397
}
398398
ImportKind::ExternCrate { id, .. } => {
399399
let def_id = self.local_def_id(id);
400-
if self.extern_crate_map.get(&def_id).map_or(true, |&cnum| {
400+
if self.extern_crate_map.get(&def_id).is_none_or(|&cnum| {
401401
!tcx.is_compiler_builtins(cnum)
402402
&& !tcx.is_panic_runtime(cnum)
403403
&& !tcx.has_global_allocator(cnum)

compiler/rustc_resolve/src/diagnostics.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
322322
let duplicate = new_binding.res().opt_def_id() == old_binding.res().opt_def_id();
323323
let has_dummy_span = new_binding.span.is_dummy() || old_binding.span.is_dummy();
324324
let from_item =
325-
self.extern_prelude.get(&ident).map_or(true, |entry| entry.introduced_by_item);
325+
self.extern_prelude.get(&ident).is_none_or(|entry| entry.introduced_by_item);
326326
// Only suggest removing an import if both bindings are to the same def, if both spans
327327
// aren't dummy spans. Further, if both bindings are imports, then the ident must have
328328
// been introduced by an item.
@@ -537,7 +537,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
537537
) {
538538
module.for_each_child(self, |_this, ident, _ns, binding| {
539539
let res = binding.res();
540-
if filter_fn(res) && ctxt.map_or(true, |ctxt| ctxt == ident.span.ctxt()) {
540+
if filter_fn(res) && ctxt.is_none_or(|ctxt| ctxt == ident.span.ctxt()) {
541541
names.push(TypoSuggestion::typo_from_ident(ident, res));
542542
}
543543
});
@@ -1229,7 +1229,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
12291229
_ => res.opt_def_id(),
12301230
};
12311231
let child_doc_visible = doc_visible
1232-
&& (did.map_or(true, |did| did.is_local() || !this.tcx.is_doc_hidden(did)));
1232+
&& did.is_none_or(|did| did.is_local() || !this.tcx.is_doc_hidden(did));
12331233

12341234
// collect results based on the filter function
12351235
// avoid suggesting anything from the same module in which we are resolving

0 commit comments

Comments
 (0)