Skip to content

Commit 73bc754

Browse files
committed
Use is_some_and in compiler
1 parent 10f4ce3 commit 73bc754

File tree

107 files changed

+168
-152
lines changed

Some content is hidden

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

107 files changed

+168
-152
lines changed

compiler/rustc_ast/src/ast.rs

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

22752275
impl FnDecl {
22762276
pub fn has_self(&self) -> bool {
2277-
self.inputs.get(0).map_or(false, Param::is_self)
2277+
self.inputs.get(0).is_some_and(|p| p.is_self())
22782278
}
22792279
pub fn c_variadic(&self) -> bool {
2280-
self.inputs.last().map_or(false, |arg| matches!(arg.ty.kind, TyKind::CVarArgs))
2280+
self.inputs.last().is_some_and(|arg| matches!(arg.ty.kind, TyKind::CVarArgs))
22812281
}
22822282
}
22832283

compiler/rustc_ast/src/attr/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl NestedMetaItem {
5757

5858
/// Returns `true` if this list item is a MetaItem with a name of `name`.
5959
pub fn has_name(&self, name: Symbol) -> bool {
60-
self.meta_item().map_or(false, |meta_item| meta_item.has_name(name))
60+
self.meta_item().is_some_and(|meta_item| meta_item.has_name(name))
6161
}
6262

6363
/// For a single-segment meta item, returns its name; otherwise, returns `None`.
@@ -101,7 +101,7 @@ impl NestedMetaItem {
101101

102102
/// Returns `true` if `self` is a `MetaItem` and the meta item is a word.
103103
pub fn is_word(&self) -> bool {
104-
self.meta_item().map_or(false, |meta_item| meta_item.is_word())
104+
self.meta_item().is_some_and(|meta_item| meta_item.is_word())
105105
}
106106

107107
/// See [`MetaItem::name_value_literal_span`].
@@ -266,7 +266,7 @@ impl Attribute {
266266
}
267267

268268
pub fn may_have_doc_links(&self) -> bool {
269-
self.doc_str().map_or(false, |s| comments::may_have_doc_links(s.as_str()))
269+
self.doc_str().is_some_and(|s| comments::may_have_doc_links(s.as_str()))
270270
}
271271

272272
pub fn get_normal_item(&self) -> &AttrItem {

compiler/rustc_ast/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#![feature(const_default_impls)]
1414
#![feature(const_trait_impl)]
1515
#![feature(if_let_guard)]
16+
#![feature(is_some_with)]
1617
#![feature(label_break_value)]
1718
#![feature(let_chains)]
1819
#![feature(min_specialization)]

compiler/rustc_ast/src/token.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ impl Token {
524524
/// Returns `true` if the token is an identifier whose name is the given
525525
/// string slice.
526526
pub fn is_ident_named(&self, name: Symbol) -> bool {
527-
self.ident().map_or(false, |(ident, _)| ident.name == name)
527+
self.ident().is_some_and(|(ident, _)| ident.name == name)
528528
}
529529

530530
/// 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
@@ -329,8 +329,7 @@ fn integer_lit(symbol: Symbol, suffix: Option<Symbol>) -> Result<LitKind, LitErr
329329
// Small bases are lexed as if they were base 10, e.g, the string
330330
// might be `0b10201`. This will cause the conversion above to fail,
331331
// but these kinds of errors are already reported by the lexer.
332-
let from_lexer =
333-
base < 10 && s.chars().any(|c| c.to_digit(10).map_or(false, |d| d >= base));
332+
let from_lexer = base < 10 && s.chars().any(|c| c.to_digit(10).is_some_and(|&d| d >= base));
334333
if from_lexer { LitError::LexerError } else { LitError::IntTooLarge }
335334
})
336335
}

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
4040
}
4141
ExprKind::Tup(ref elts) => hir::ExprKind::Tup(self.lower_exprs(elts)),
4242
ExprKind::Call(ref f, ref args) => {
43-
if e.attrs.get(0).map_or(false, |a| a.has_name(sym::rustc_box)) {
43+
if e.attrs.get(0).is_some_and(|a| a.has_name(sym::rustc_box)) {
4444
if let [inner] = &args[..] && e.attrs.len() == 1 {
4545
let kind = hir::ExprKind::Box(self.lower_expr(&inner));
4646
let hir_id = self.lower_node_id(e.id);

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
//! in the HIR, especially for multiple identifiers.
3232
3333
#![feature(box_patterns)]
34+
#![feature(is_some_with)]
3435
#![feature(let_chains)]
3536
#![feature(let_else)]
3637
#![feature(never_type)]

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,8 +531,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
531531
match i.kind {
532532
ast::ForeignItemKind::Fn(..) | ast::ForeignItemKind::Static(..) => {
533533
let link_name = self.sess.first_attr_value_str_by_name(&i.attrs, sym::link_name);
534-
let links_to_llvm =
535-
link_name.map_or(false, |val| val.as_str().starts_with("llvm."));
534+
let links_to_llvm = link_name.is_some_and(|val| val.as_str().starts_with("llvm."));
536535
if links_to_llvm {
537536
gate_feature_post!(
538537
&self,

compiler/rustc_ast_passes/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#![allow(rustc::potential_query_instability)]
88
#![feature(box_patterns)]
99
#![feature(if_let_guard)]
10+
#![feature(is_some_with)]
1011
#![feature(iter_is_partitioned)]
1112
#![feature(let_chains)]
1213
#![feature(let_else)]

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
8787
let path_span = path_span.unwrap();
8888
// path_span is only present in the case of closure capture
8989
assert!(matches!(later_use_kind, LaterUseKind::ClosureCapture));
90-
if !borrow_span.map_or(false, |sp| sp.overlaps(var_or_use_span)) {
90+
if !borrow_span.is_some_and(|sp| sp.overlaps(var_or_use_span)) {
9191
let path_label = "used here by closure";
9292
let capture_kind_label = message;
9393
err.span_label(
@@ -429,7 +429,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
429429
use_location: Location,
430430
) -> bool {
431431
let back_edge = self.reach_through_backedge(borrow_location, use_location);
432-
back_edge.map_or(false, |back_edge| self.can_reach_head_of_loop(use_location, back_edge))
432+
back_edge.is_some_and(|&back_edge| self.can_reach_head_of_loop(use_location, back_edge))
433433
}
434434

435435
/// Returns the outmost back edge if `from` location can reach `to` location passing through

0 commit comments

Comments
 (0)