Skip to content

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

+2-2
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

+3-3
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

+1-1
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

+1-2
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

+1-2
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ impl CoverageMapGenerator {
163163
counter_regions.sort_unstable_by_key(|(_counter, region)| *region);
164164
for (counter, region) in counter_regions {
165165
let CodeRegion { file_name, start_line, start_col, end_line, end_col } = *region;
166-
let same_file = current_file_name.map_or(false, |p| p == file_name);
166+
let same_file = current_file_name.is_some_and(|p| p == file_name);
167167
if !same_file {
168168
if current_file_name.is_some() {
169169
current_file_id += 1;

compiler/rustc_codegen_ssa/src/mir/block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
10311031
});
10321032

10331033
let needs_location =
1034-
instance.map_or(false, |i| i.def.requires_caller_location(self.cx.tcx()));
1034+
instance.is_some_and(|i| i.def.requires_caller_location(self.cx.tcx()));
10351035
if needs_location {
10361036
let mir_args = if let Some(num_untupled) = num_untupled {
10371037
first_args.len() + num_untupled

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
971971
// have no `rustc_const_stable` attributes to be const-unstable as well. This
972972
// should be fixed later.
973973
let callee_is_unstable_unmarked = tcx.lookup_const_stability(callee).is_none()
974-
&& tcx.lookup_stability(callee).map_or(false, |s| s.is_unstable());
974+
&& tcx.lookup_stability(callee).is_some_and(|s| s.is_unstable());
975975
if callee_is_unstable_unmarked {
976976
trace!("callee_is_unstable_unmarked");
977977
// We do not use `const` modifiers for intrinsic "functions", as intrinsics are

compiler/rustc_const_eval/src/transform/check_consts/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,5 +139,5 @@ fn is_parent_const_stable_trait(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
139139
return false;
140140
}
141141

142-
tcx.lookup_const_stability(parent.owner).map_or(false, |stab| stab.is_const_stable())
142+
tcx.lookup_const_stability(parent.owner).is_some_and(|stab| stab.is_const_stable())
143143
}

compiler/rustc_data_structures/src/obligation_forest/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ impl<O: ForestObligation> ObligationForest<O> {
366366
&& self
367367
.error_cache
368368
.get(&obligation_tree_id)
369-
.map_or(false, |errors| errors.contains(v.key()));
369+
.is_some_and(|errors| errors.contains(v.key()));
370370

371371
if already_failed {
372372
Err(())

compiler/rustc_driver_impl/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,7 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str, extra_info:
13151315
}
13161316

13171317
// If backtraces are enabled, also print the query stack
1318-
let backtrace = env::var_os("RUST_BACKTRACE").map_or(false, |x| &x != "0");
1318+
let backtrace = env::var_os("RUST_BACKTRACE").is_some_and(|x| &x != "0");
13191319

13201320
let num_frames = if backtrace { None } else { Some(2) };
13211321

compiler/rustc_errors/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,7 @@ impl HandlerInner {
14371437
}
14381438

14391439
fn treat_err_as_bug(&self) -> bool {
1440-
self.flags.treat_err_as_bug.map_or(false, |c| {
1440+
self.flags.treat_err_as_bug.is_some_and(|c| {
14411441
self.err_count() + self.lint_err_count + self.delayed_bug_count() >= c.get()
14421442
})
14431443
}
@@ -1603,7 +1603,7 @@ impl HandlerInner {
16031603
// This is technically `self.treat_err_as_bug()` but `delay_span_bug` is called before
16041604
// incrementing `err_count` by one, so we need to +1 the comparing.
16051605
// FIXME: Would be nice to increment err_count in a more coherent way.
1606-
if self.flags.treat_err_as_bug.map_or(false, |c| {
1606+
if self.flags.treat_err_as_bug.is_some_and(|c| {
16071607
self.err_count() + self.lint_err_count + self.delayed_bug_count() + 1 >= c.get()
16081608
}) {
16091609
// FIXME: don't abort here if report_delayed_bugs is off

compiler/rustc_expand/src/base.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ impl SyntaxExtension {
780780
let allow_internal_unsafe = attr::contains_name(attrs, sym::allow_internal_unsafe);
781781
let local_inner_macros = attr::find_by_name(attrs, sym::macro_export)
782782
.and_then(|macro_export| macro_export.meta_item_list())
783-
.map_or(false, |l| attr::list_contains_name(&l, sym::local_inner_macros));
783+
.is_some_and(|l| attr::list_contains_name(&l, sym::local_inner_macros));
784784
let collapse_debuginfo = attr::contains_name(attrs, sym::collapse_debuginfo);
785785
tracing::debug!(?local_inner_macros, ?collapse_debuginfo, ?allow_internal_unsafe);
786786

@@ -1449,7 +1449,7 @@ fn pretty_printing_compatibility_hack(item: &Item, sess: &ParseSess) -> bool {
14491449
&& version
14501450
.next()
14511451
.and_then(|c| c.parse::<u32>().ok())
1452-
.map_or(false, |v| v < 6)
1452+
.is_some_and(|v| v < 6)
14531453
};
14541454

14551455
if crate_matches {

compiler/rustc_expand/src/expand.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1599,7 +1599,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
15991599
cfg_pos = Some(pos); // a cfg attr found, no need to search anymore
16001600
break;
16011601
} else if attr_pos.is_none()
1602-
&& !name.map_or(false, rustc_feature::is_builtin_attr_name)
1602+
&& !name.is_some_and(rustc_feature::is_builtin_attr_name)
16031603
{
16041604
attr_pos = Some(pos); // a non-cfg attr found, still may find a cfg attr
16051605
}
@@ -1647,7 +1647,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
16471647
let current_span = if let Some(sp) = span { sp.to(attr.span) } else { attr.span };
16481648
span = Some(current_span);
16491649

1650-
if attrs.peek().map_or(false, |next_attr| next_attr.doc_str().is_some()) {
1650+
if attrs.peek().is_some_and(|next_attr| next_attr.doc_str().is_some()) {
16511651
continue;
16521652
}
16531653

@@ -1950,6 +1950,6 @@ impl<'feat> ExpansionConfig<'feat> {
19501950
}
19511951

19521952
fn proc_macro_hygiene(&self) -> bool {
1953-
self.features.map_or(false, |features| features.proc_macro_hygiene)
1953+
self.features.is_some_and(|features| features.proc_macro_hygiene)
19541954
}
19551955
}

compiler/rustc_feature/src/builtin_attrs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -861,11 +861,11 @@ pub fn is_builtin_attr_name(name: Symbol) -> bool {
861861
/// Whether this builtin attribute is only used in the local crate.
862862
/// If so, it is not encoded in the crate metadata.
863863
pub fn is_builtin_only_local(name: Symbol) -> bool {
864-
BUILTIN_ATTRIBUTE_MAP.get(&name).map_or(false, |attr| attr.only_local)
864+
BUILTIN_ATTRIBUTE_MAP.get(&name).is_some_and(|attr| attr.only_local)
865865
}
866866

867867
pub fn is_valid_for_get_attr(name: Symbol) -> bool {
868-
BUILTIN_ATTRIBUTE_MAP.get(&name).map_or(false, |attr| match attr.duplicates {
868+
BUILTIN_ATTRIBUTE_MAP.get(&name).is_some_and(|attr| match attr.duplicates {
869869
WarnFollowing | ErrorFollowing | ErrorPreceding | FutureWarnFollowing
870870
| FutureWarnPreceding => true,
871871
DuplicatesOk | WarnFollowingWordOnly => false,

compiler/rustc_feature/src/lib.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,11 @@ impl UnstableFeatures {
8686
let disable_unstable_features =
8787
option_env!("CFG_DISABLE_UNSTABLE_FEATURES").map(|s| s != "0").unwrap_or(false);
8888
// Returns whether `krate` should be counted as unstable
89-
let is_unstable_crate = |var: &str| {
90-
krate.map_or(false, |name| var.split(',').any(|new_krate| new_krate == name))
91-
};
89+
let is_unstable_crate =
90+
|var: &str| krate.is_some_and(|name| var.split(',').any(|new_krate| new_krate == name));
9291
// `true` if we should enable unstable features for bootstrapping.
93-
let bootstrap = std::env::var("RUSTC_BOOTSTRAP")
94-
.map_or(false, |var| var == "1" || is_unstable_crate(&var));
92+
let bootstrap =
93+
std::env::var("RUSTC_BOOTSTRAP").is_ok_and(|var| var == "1" || is_unstable_crate(&var));
9594
match (disable_unstable_features, bootstrap) {
9695
(_, true) => UnstableFeatures::Cheat,
9796
(true, _) => UnstableFeatures::Disallow,

compiler/rustc_hir/src/hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ pub struct WhereBoundPredicate<'hir> {
787787
impl<'hir> WhereBoundPredicate<'hir> {
788788
/// Returns `true` if `param_def_id` matches the `bounded_ty` of this predicate.
789789
pub fn is_param_bound(&self, param_def_id: DefId) -> bool {
790-
self.bounded_ty.as_generic_param().map_or(false, |(def_id, _)| def_id == param_def_id)
790+
self.bounded_ty.as_generic_param().is_some_and(|(def_id, _)| def_id == param_def_id)
791791
}
792792
}
793793

compiler/rustc_hir_analysis/src/astconv/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2625,7 +2625,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
26252625
&& tcx.all_impls(*trait_def_id)
26262626
.any(|impl_def_id| {
26272627
let trait_ref = tcx.impl_trait_ref(impl_def_id);
2628-
trait_ref.map_or(false, |trait_ref| {
2628+
trait_ref.is_some_and(|trait_ref| {
26292629
let impl_ = trait_ref.subst(
26302630
tcx,
26312631
infcx.fresh_substs_for_item(DUMMY_SP, impl_def_id),
@@ -3654,7 +3654,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
36543654
..
36553655
}) = tcx.hir().get_by_def_id(parent_id) && self_ty.hir_id == impl_self_ty.hir_id
36563656
{
3657-
if !of_trait_ref.trait_def_id().map_or(false, |def_id| def_id.is_local()) {
3657+
if !of_trait_ref.trait_def_id().is_some_and(|def_id| def_id.is_local()) {
36583658
return;
36593659
}
36603660
let of_trait_span = of_trait_ref.path.span;
@@ -3693,7 +3693,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
36933693
.source_map()
36943694
.span_to_prev_source(self_ty.span)
36953695
.ok()
3696-
.map_or(false, |s| s.trim_end().ends_with('<'));
3696+
.is_some_and(|s| s.trim_end().ends_with('<'));
36973697

36983698
let is_global = poly_trait_ref.trait_ref.path.is_global();
36993699

compiler/rustc_hir_analysis/src/check/check.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -800,16 +800,15 @@ fn check_impl_items_against_trait<'tcx>(
800800

801801
let is_implemented = leaf_def
802802
.as_ref()
803-
.map_or(false, |node_item| node_item.item.defaultness(tcx).has_value());
803+
.is_some_and(|node_item| node_item.item.defaultness(tcx).has_value());
804804

805805
if !is_implemented && tcx.impl_defaultness(impl_id).is_final() {
806806
missing_items.push(tcx.associated_item(trait_item_id));
807807
}
808808

809809
// true if this item is specifically implemented in this impl
810-
let is_implemented_here = leaf_def
811-
.as_ref()
812-
.map_or(false, |node_item| !node_item.defining_node.is_from_trait());
810+
let is_implemented_here =
811+
leaf_def.as_ref().is_some_and(|node_item| !node_item.defining_node.is_from_trait());
813812

814813
if !is_implemented_here {
815814
let full_impl_span =
@@ -1082,8 +1081,8 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
10821081
let layout = tcx.layout_of(param_env.and(ty));
10831082
// We are currently checking the type this field came from, so it must be local
10841083
let span = tcx.hir().span_if_local(field.did).unwrap();
1085-
let zst = layout.map_or(false, |layout| layout.is_zst());
1086-
let align1 = layout.map_or(false, |layout| layout.align.abi.bytes() == 1);
1084+
let zst = layout.is_ok_and(|layout| layout.is_zst());
1085+
let align1 = layout.is_ok_and(|layout| layout.align.abi.bytes() == 1);
10871086
if !zst {
10881087
return (span, zst, align1, None);
10891088
}

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) {
179179
hir::ItemKind::Impl(impl_) => {
180180
let is_auto = tcx
181181
.impl_trait_ref(def_id)
182-
.map_or(false, |trait_ref| tcx.trait_is_auto(trait_ref.skip_binder().def_id));
182+
.is_some_and(|trait_ref| tcx.trait_is_auto(trait_ref.skip_binder().def_id));
183183
if let (hir::Defaultness::Default { .. }, true) = (impl_.defaultness, is_auto) {
184184
let sp = impl_.of_trait.as_ref().map_or(item.span, |t| t.path.span);
185185
let mut err =

compiler/rustc_hir_analysis/src/collect.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ fn convert_variant(
819819
recovered,
820820
adt_kind == AdtKind::Struct && tcx.has_attr(parent_did, sym::non_exhaustive)
821821
|| variant_did
822-
.map_or(false, |variant_did| tcx.has_attr(variant_did, sym::non_exhaustive)),
822+
.is_some_and(|variant_did| tcx.has_attr(variant_did, sym::non_exhaustive)),
823823
)
824824
}
825825

@@ -1025,7 +1025,7 @@ fn is_suggestable_infer_ty(ty: &hir::Ty<'_>) -> bool {
10251025
is_suggestable_infer_ty(ty) || are_suggestable_generic_args(segment.args().args)
10261026
}
10271027
Path(hir::QPath::Resolved(ty_opt, hir::Path { segments, .. })) => {
1028-
ty_opt.map_or(false, is_suggestable_infer_ty)
1028+
ty_opt.is_some_and(is_suggestable_infer_ty)
10291029
|| segments.iter().any(|segment| are_suggestable_generic_args(segment.args().args))
10301030
}
10311031
_ => false,

compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
395395
) -> String {
396396
let fn_sig = self.tcx.hir().get_if_local(self.def_id).and_then(hir::Node::fn_sig);
397397
let is_used_in_input = |def_id| {
398-
fn_sig.map_or(false, |fn_sig| {
398+
fn_sig.is_some_and(|fn_sig| {
399399
fn_sig.decl.inputs.iter().any(|ty| match ty.kind {
400400
hir::TyKind::Path(hir::QPath::Resolved(
401401
None,

compiler/rustc_hir_typeck/src/cast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
465465
.sess
466466
.source_map()
467467
.span_to_snippet(self.expr_span)
468-
.map_or(false, |snip| snip.starts_with('('));
468+
.is_ok_and(|snip| snip.starts_with('('));
469469

470470
// Very crude check to see whether the expression must be wrapped
471471
// in parentheses for the suggestion to work (issue #89497).

compiler/rustc_hir_typeck/src/coercion.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1814,7 +1814,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
18141814
.span_to_snippet(return_sp)
18151815
.unwrap_or_else(|_| "dyn Trait".to_string());
18161816
let mut snippet_iter = snippet.split_whitespace();
1817-
let has_impl = snippet_iter.next().map_or(false, |s| s == "impl");
1817+
let has_impl = snippet_iter.next().is_some_and(|s| s == "impl");
18181818
// Only suggest `Box<dyn Trait>` if `Trait` in `impl Trait` is object safe.
18191819
let mut is_object_safe = false;
18201820
if let hir::FnRetTy::Return(ty) = fn_output
@@ -1834,7 +1834,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
18341834
bound
18351835
.trait_ref()
18361836
.and_then(|t| t.trait_def_id())
1837-
.map_or(false, |def_id| {
1837+
.is_some_and(|def_id| {
18381838
fcx.tcx.check_is_object_safe(def_id)
18391839
})
18401840
})

0 commit comments

Comments
 (0)