Skip to content

Commit f3f21ae

Browse files
authored
Rollup merge of rust-lang#135738 - yotamofek:map_or_true-compiler, r=compiler-errors
Replace usages of `map_or(bool, ...)` with `is_{some_and|none_or|ok_and}` Split out from rust-lang#135732 according to rust-lang#135732 , same thing but just for the compiler: > The usage of `map_or(bool, ...)` is really hard to understand IMHO. > This PR simply uses clippy (with `--fix`) to replace that with `is_{some_and|none_or|ok_and}`. > (no manual modifications were made, just machine applicable clippy fixes and then fmt) r? ``@compiler-errors``
2 parents 64768c5 + 1951d86 commit f3f21ae

File tree

40 files changed

+67
-69
lines changed

40 files changed

+67
-69
lines changed

compiler/rustc_ast_lowering/src/delegation.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,8 @@ 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+
&& let Some((suggestion, _)) = suggestion
467+
&& suggestion.is_empty()
467468
&& let Ok(after) = je.sm.span_to_next_source(span)
468469
&& after.starts_with('\n')
469470
{

compiler/rustc_errors/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use std::backtrace::{Backtrace, BacktraceStatus};
3535
use std::borrow::Cow;
3636
use std::cell::Cell;
3737
use std::error::Report;
38+
use std::ffi::OsStr;
3839
use std::hash::Hash;
3940
use std::io::Write;
4041
use std::num::NonZero;
@@ -1717,7 +1718,7 @@ impl DiagCtxtInner {
17171718
let bugs: Vec<_> =
17181719
std::mem::take(&mut self.delayed_bugs).into_iter().map(|(b, _)| b).collect();
17191720

1720-
let backtrace = std::env::var_os("RUST_BACKTRACE").map_or(true, |x| &x != "0");
1721+
let backtrace = std::env::var_os("RUST_BACKTRACE").as_deref() != Some(OsStr::new("0"));
17211722
let decorate = backtrace || self.ice_file.is_none();
17221723
let mut out = self
17231724
.ice_file

compiler/rustc_expand/src/config.rs

Lines changed: 1 addition & 1 deletion
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),

0 commit comments

Comments
 (0)