Skip to content

Commit 8e606a6

Browse files
authored
Rollup merge of #118253 - dtolnay:issomeand, r=compiler-errors
Replace `option.map(cond) == Some(true)` with `option.is_some_and(cond)` Requested by `@fmease` in #118226 (review). There is also a much larger number of `option.map_or(false, cond)` that can be changed separately if someone wants. r? fmease
2 parents 0304aac + 8cc7073 commit 8e606a6

File tree

8 files changed

+21
-22
lines changed

8 files changed

+21
-22
lines changed

compiler/rustc_codegen_cranelift/scripts/rustc-clif.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn main() {
2727
args.push(codegen_backend_arg);
2828
}
2929
if !passed_args.iter().any(|arg| {
30-
arg == "--sysroot" || arg.to_str().map(|s| s.starts_with("--sysroot=")) == Some(true)
30+
arg == "--sysroot" || arg.to_str().is_some_and(|s| s.starts_with("--sysroot="))
3131
}) {
3232
args.push(OsString::from("--sysroot"));
3333
args.push(OsString::from(sysroot.to_str().unwrap()));

compiler/rustc_codegen_cranelift/scripts/rustdoc-clif.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn main() {
2727
args.push(codegen_backend_arg);
2828
}
2929
if !passed_args.iter().any(|arg| {
30-
arg == "--sysroot" || arg.to_str().map(|s| s.starts_with("--sysroot=")) == Some(true)
30+
arg == "--sysroot" || arg.to_str().is_some_and(|s| s.starts_with("--sysroot="))
3131
}) {
3232
args.push(OsString::from("--sysroot"));
3333
args.push(OsString::from(sysroot.to_str().unwrap()));

compiler/rustc_expand/src/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pub(crate) fn matches_codepattern(a: &str, b: &str) -> bool {
135135

136136
/// Advances the given peekable `Iterator` until it reaches a non-whitespace character.
137137
fn scan_for_non_ws_or_end<I: Iterator<Item = char>>(iter: &mut Peekable<I>) {
138-
while iter.peek().copied().map(rustc_lexer::is_whitespace) == Some(true) {
138+
while iter.peek().copied().is_some_and(rustc_lexer::is_whitespace) {
139139
iter.next();
140140
}
141141
}

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -2293,12 +2293,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22932293
let clone_trait =
22942294
self.tcx.require_lang_item(LangItem::Clone, Some(segment.ident.span));
22952295
if args.is_empty()
2296-
&& self.typeck_results.borrow().type_dependent_def_id(expr.hir_id).map(
2297-
|did| {
2296+
&& self
2297+
.typeck_results
2298+
.borrow()
2299+
.type_dependent_def_id(expr.hir_id)
2300+
.is_some_and(|did| {
22982301
let ai = self.tcx.associated_item(did);
22992302
ai.trait_container(self.tcx) == Some(clone_trait)
2300-
},
2301-
) == Some(true)
2303+
})
23022304
&& segment.ident.name == sym::clone
23032305
{
23042306
// If this expression had a clone call when suggesting borrowing

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/util.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
161161
&& self
162162
.tcx()
163163
.opt_associated_item(scope_def_id.to_def_id())
164-
.map(|i| i.fn_has_self_parameter)
165-
== Some(true)
164+
.is_some_and(|i| i.fn_has_self_parameter)
166165
}
167166
}

compiler/rustc_lint/src/non_fmt_panic.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,13 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
154154

155155
let infcx = cx.tcx.infer_ctxt().build();
156156
let suggest_display = is_str
157-
|| cx
158-
.tcx
159-
.get_diagnostic_item(sym::Display)
160-
.map(|t| infcx.type_implements_trait(t, [ty], cx.param_env).may_apply())
161-
== Some(true);
157+
|| cx.tcx.get_diagnostic_item(sym::Display).is_some_and(|t| {
158+
infcx.type_implements_trait(t, [ty], cx.param_env).may_apply()
159+
});
162160
let suggest_debug = !suggest_display
163-
&& cx
164-
.tcx
165-
.get_diagnostic_item(sym::Debug)
166-
.map(|t| infcx.type_implements_trait(t, [ty], cx.param_env).may_apply())
167-
== Some(true);
161+
&& cx.tcx.get_diagnostic_item(sym::Debug).is_some_and(|t| {
162+
infcx.type_implements_trait(t, [ty], cx.param_env).may_apply()
163+
});
168164

169165
let suggest_panic_any = !is_str && panic == sym::std_panic_macro;
170166

src/librustdoc/html/render/print_item.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,10 @@ fn extra_info_tags<'a, 'tcx: 'a>(
596596

597597
// The "rustc_private" crates are permanently unstable so it makes no sense
598598
// to render "unstable" everywhere.
599-
if item.stability(tcx).as_ref().map(|s| s.is_unstable() && s.feature != sym::rustc_private)
600-
== Some(true)
599+
if item
600+
.stability(tcx)
601+
.as_ref()
602+
.is_some_and(|s| s.is_unstable() && s.feature != sym::rustc_private)
601603
{
602604
write!(f, "{}", tag_html("unstable", "", "Experimental"))?;
603605
}

src/tools/compiletest/src/header.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ fn iter_header_extra(
632632
it(None, directive, 0);
633633
}
634634

635-
let comment = if testfile.extension().map(|e| e == "rs") == Some(true) { "//" } else { "#" };
635+
let comment = if testfile.extension().is_some_and(|e| e == "rs") { "//" } else { "#" };
636636

637637
let mut rdr = BufReader::new(rdr);
638638
let mut ln = String::new();

0 commit comments

Comments
 (0)