Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit fb0f74a

Browse files
committed
Use Option::is_some_and and Result::is_ok_and in the compiler
1 parent 70db836 commit fb0f74a

File tree

87 files changed

+148
-158
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+148
-158
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2391,10 +2391,10 @@ pub struct FnDecl {
23912391

23922392
impl FnDecl {
23932393
pub fn has_self(&self) -> bool {
2394-
self.inputs.get(0).map_or(false, Param::is_self)
2394+
self.inputs.get(0).is_some_and(Param::is_self)
23952395
}
23962396
pub fn c_variadic(&self) -> bool {
2397-
self.inputs.last().map_or(false, |arg| matches!(arg.ty.kind, TyKind::CVarArgs))
2397+
self.inputs.last().is_some_and(|arg| matches!(arg.ty.kind, TyKind::CVarArgs))
23982398
}
23992399
}
24002400

compiler/rustc_ast/src/attr/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl Attribute {
149149
}
150150

151151
pub fn may_have_doc_links(&self) -> bool {
152-
self.doc_str().map_or(false, |s| comments::may_have_doc_links(s.as_str()))
152+
self.doc_str().is_some_and(|s| comments::may_have_doc_links(s.as_str()))
153153
}
154154

155155
pub fn is_proc_macro_attr(&self) -> bool {
@@ -441,12 +441,12 @@ impl NestedMetaItem {
441441

442442
/// Returns `true` if this list item is a MetaItem with a name of `name`.
443443
pub fn has_name(&self, name: Symbol) -> bool {
444-
self.meta_item().map_or(false, |meta_item| meta_item.has_name(name))
444+
self.meta_item().is_some_and(|meta_item| meta_item.has_name(name))
445445
}
446446

447447
/// Returns `true` if `self` is a `MetaItem` and the meta item is a word.
448448
pub fn is_word(&self) -> bool {
449-
self.meta_item().map_or(false, |meta_item| meta_item.is_word())
449+
self.meta_item().is_some_and(|meta_item| meta_item.is_word())
450450
}
451451

452452
/// Gets a list of inner meta items from a list `MetaItem` type.

compiler/rustc_ast/src/token.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ impl Token {
607607
/// Returns `true` if the token is an identifier whose name is the given
608608
/// string slice.
609609
pub fn is_ident_named(&self, name: Symbol) -> bool {
610-
self.ident().map_or(false, |(ident, _)| ident.name == name)
610+
self.ident().is_some_and(|(ident, _)| ident.name == name)
611611
}
612612

613613
/// Returns `true` if the token is an interpolated path.

compiler/rustc_ast/src/util/literal.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,7 @@ fn integer_lit(symbol: Symbol, suffix: Option<Symbol>) -> Result<LitKind, LitErr
392392
// Small bases are lexed as if they were base 10, e.g, the string
393393
// might be `0b10201`. This will cause the conversion above to fail,
394394
// but these kinds of errors are already reported by the lexer.
395-
let from_lexer =
396-
base < 10 && s.chars().any(|c| c.to_digit(10).map_or(false, |d| d >= base));
395+
let from_lexer = base < 10 && s.chars().any(|c| c.to_digit(10).is_some_and(|d| d >= base));
397396
if from_lexer { LitError::LexerError } else { LitError::IntTooLarge(base) }
398397
})
399398
}

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
317317
match i.kind {
318318
ast::ForeignItemKind::Fn(..) | ast::ForeignItemKind::Static(..) => {
319319
let link_name = attr::first_attr_value_str_by_name(&i.attrs, sym::link_name);
320-
let links_to_llvm =
321-
link_name.map_or(false, |val| val.as_str().starts_with("llvm."));
320+
let links_to_llvm = link_name.is_some_and(|val| val.as_str().starts_with("llvm."));
322321
if links_to_llvm {
323322
gate_feature_post!(
324323
&self,

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
118118
let path_span = path_span.unwrap();
119119
// path_span is only present in the case of closure capture
120120
assert!(matches!(later_use_kind, LaterUseKind::ClosureCapture));
121-
if !borrow_span.map_or(false, |sp| sp.overlaps(var_or_use_span)) {
121+
if !borrow_span.is_some_and(|sp| sp.overlaps(var_or_use_span)) {
122122
let path_label = "used here by closure";
123123
let capture_kind_label = message;
124124
err.span_label(

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11561156
ty::Adt(def, ..) => Some(def.did()),
11571157
_ => None,
11581158
});
1159-
let is_option_or_result = parent_self_ty.map_or(false, |def_id| {
1159+
let is_option_or_result = parent_self_ty.is_some_and(|def_id| {
11601160
matches!(tcx.get_diagnostic_name(def_id), Some(sym::Option | sym::Result))
11611161
});
11621162
if is_option_or_result && maybe_reinitialized_locations_is_empty {

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
443443
.sess
444444
.source_map()
445445
.span_to_snippet(span)
446-
.map_or(false, |snippet| snippet.starts_with("&mut ")) =>
446+
.is_ok_and(|snippet| snippet.starts_with("&mut ")) =>
447447
{
448448
err.span_label(span, format!("cannot {act}"));
449449
err.span_suggestion(

compiler/rustc_borrowck/src/region_infer/values.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl<N: Idx> LivenessValues<N> {
159159
/// Returns `true` if the region `r` contains the given element.
160160
pub(crate) fn contains(&self, row: N, location: Location) -> bool {
161161
let index = self.elements.point_from_location(location);
162-
self.points.row(row).map_or(false, |r| r.contains(index))
162+
self.points.row(row).is_some_and(|r| r.contains(index))
163163
}
164164

165165
/// Returns an iterator of all the elements contained by the region `r`

compiler/rustc_builtin_macros/src/cfg_eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl<'ast> visit::Visitor<'ast> for CfgFinder {
119119
self.has_cfg_or_cfg_attr = self.has_cfg_or_cfg_attr
120120
|| attr
121121
.ident()
122-
.map_or(false, |ident| ident.name == sym::cfg || ident.name == sym::cfg_attr);
122+
.is_some_and(|ident| ident.name == sym::cfg || ident.name == sym::cfg_attr);
123123
}
124124
}
125125

0 commit comments

Comments
 (0)