Skip to content

Commit 710a3dc

Browse files
committed
Replace option.map(cond) == Some(true) with option.is_some_and(cond)
1 parent beebcde commit 710a3dc

File tree

11 files changed

+24
-25
lines changed

11 files changed

+24
-25
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();

src/tools/rust-analyzer/crates/ide-assists/src/handlers/toggle_ignore.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub(crate) fn toggle_ignore(acc: &mut Assists, ctx: &AssistContext<'_>) -> Optio
5555
}
5656

5757
fn has_ignore_attribute(fn_def: &ast::Fn) -> Option<ast::Attr> {
58-
fn_def.attrs().find(|attr| attr.path().map(|it| it.syntax().text() == "ignore") == Some(true))
58+
fn_def.attrs().find(|attr| attr.path().is_some_and(|it| it.syntax().text() == "ignore"))
5959
}
6060

6161
#[cfg(test)]

src/tools/rust-analyzer/crates/ide/src/extend_selection.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ fn try_extend_selection(
108108

109109
let node = shallowest_node(&node);
110110

111-
if node.parent().map(|n| list_kinds.contains(&n.kind())) == Some(true) {
111+
if node.parent().is_some_and(|n| list_kinds.contains(&n.kind())) {
112112
if let Some(range) = extend_list_item(&node) {
113113
return Some(range);
114114
}

src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/tidy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ fn check_trailing_ws(path: &Path, text: &str) {
316316
return;
317317
}
318318
for (line_number, line) in text.lines().enumerate() {
319-
if line.chars().last().map(char::is_whitespace) == Some(true) {
319+
if line.chars().last().is_some_and(char::is_whitespace) {
320320
panic!("Trailing whitespace in {} at line {}", path.display(), line_number + 1)
321321
}
322322
}

0 commit comments

Comments
 (0)