Skip to content

Commit 52adfdd

Browse files
committed
Use Option::map_or instead of .map(..).unwrap_or(..)
1 parent 9f3998b commit 52adfdd

File tree

50 files changed

+67
-79
lines changed

Some content is hidden

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

50 files changed

+67
-79
lines changed

compiler/rustc_ast_lowering/src/path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
273273
if !generic_args.parenthesized && !has_lifetimes {
274274
generic_args.args = self
275275
.elided_path_lifetimes(
276-
first_generic_span.map(|s| s.shrink_to_lo()).unwrap_or(segment.ident.span),
276+
first_generic_span.map_or(segment.ident.span, |s| s.shrink_to_lo()),
277277
expected_lifetimes,
278278
)
279279
.map(GenericArg::Lifetime)

compiler/rustc_ast_passes/src/feature_gate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
370370
gate_feature_post!(
371371
&self,
372372
negative_impls,
373-
span.to(of_trait.as_ref().map(|t| t.path.span).unwrap_or(span)),
373+
span.to(of_trait.as_ref().map_or(span, |t| t.path.span)),
374374
"negative trait bounds are not yet fully implemented; \
375375
use marker types for now"
376376
);

compiler/rustc_codegen_llvm/src/back/write.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1002,8 +1002,7 @@ pub unsafe fn with_llvm_pmb(
10021002
// reasonable defaults and prepare it to actually populate the pass
10031003
// manager.
10041004
let builder = llvm::LLVMPassManagerBuilderCreate();
1005-
let opt_size =
1006-
config.opt_size.map(|x| to_llvm_opt_settings(x).1).unwrap_or(llvm::CodeGenOptSizeNone);
1005+
let opt_size = config.opt_size.map_or(llvm::CodeGenOptSizeNone, |x| to_llvm_opt_settings(x).1);
10071006
let inline_threshold = config.inline_threshold;
10081007
let pgo_gen_path = get_pgo_gen_path(config);
10091008
let pgo_use_path = get_pgo_use_path(config);

compiler/rustc_codegen_ssa/src/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ fn get_linker(
166166
_ => match flavor {
167167
LinkerFlavor::Lld(f) => Command::lld(linker, f),
168168
LinkerFlavor::Msvc if sess.opts.cg.linker.is_none() && sess.target.linker.is_none() => {
169-
Command::new(msvc_tool.as_ref().map(|t| t.path()).unwrap_or(linker))
169+
Command::new(msvc_tool.as_ref().map_or(linker, |t| t.path()))
170170
}
171171
_ => Command::new(linker),
172172
},

compiler/rustc_data_structures/src/profiling.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl SelfProfilerRef {
166166
// If there is no SelfProfiler then the filter mask is set to NONE,
167167
// ensuring that nothing ever tries to actually access it.
168168
let event_filter_mask =
169-
profiler.as_ref().map(|p| p.event_filter_mask).unwrap_or(EventFilter::empty());
169+
profiler.as_ref().map_or(EventFilter::empty(), |p| p.event_filter_mask);
170170

171171
SelfProfilerRef {
172172
profiler,

compiler/rustc_driver/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
12361236
}
12371237

12381238
// If backtraces are enabled, also print the query stack
1239-
let backtrace = env::var_os("RUST_BACKTRACE").map(|x| &x != "0").unwrap_or(false);
1239+
let backtrace = env::var_os("RUST_BACKTRACE").map_or(false, |x| &x != "0");
12401240

12411241
let num_frames = if backtrace { None } else { Some(2) };
12421242

compiler/rustc_errors/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ impl HandlerInner {
804804
}
805805

806806
fn treat_err_as_bug(&self) -> bool {
807-
self.flags.treat_err_as_bug.map(|c| self.err_count() >= c).unwrap_or(false)
807+
self.flags.treat_err_as_bug.map_or(false, |c| self.err_count() >= c)
808808
}
809809

810810
fn print_error_count(&mut self, registry: &Registry) {
@@ -913,7 +913,7 @@ impl HandlerInner {
913913
// This is technically `self.treat_err_as_bug()` but `delay_span_bug` is called before
914914
// incrementing `err_count` by one, so we need to +1 the comparing.
915915
// FIXME: Would be nice to increment err_count in a more coherent way.
916-
if self.flags.treat_err_as_bug.map(|c| self.err_count() + 1 >= c).unwrap_or(false) {
916+
if self.flags.treat_err_as_bug.map_or(false, |c| self.err_count() + 1 >= c) {
917917
// FIXME: don't abort here if report_delayed_bugs is off
918918
self.span_bug(sp, msg);
919919
}

compiler/rustc_expand/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ impl<'a> StripUnconfigured<'a> {
423423

424424
/// If attributes are not allowed on expressions, emit an error for `attr`
425425
pub fn maybe_emit_expr_attr_err(&self, attr: &Attribute) {
426-
if !self.features.map(|features| features.stmt_expr_attributes).unwrap_or(true) {
426+
if !self.features.map_or(true, |features| features.stmt_expr_attributes) {
427427
let mut err = feature_err(
428428
&self.sess.parse_sess,
429429
sym::stmt_expr_attributes,

compiler/rustc_expand/src/mbe/macro_parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ fn inner_parse_loop<'root, 'tt>(
500500
if idx == len && item.sep.is_some() {
501501
// We have a separator, and it is the current token. We can advance past the
502502
// separator token.
503-
if item.sep.as_ref().map(|sep| token_name_eq(token, sep)).unwrap_or(false) {
503+
if item.sep.as_ref().map_or(false, |sep| token_name_eq(token, sep)) {
504504
item.idx += 1;
505505
next_items.push(item);
506506
}

compiler/rustc_expand/src/mbe/macro_rules.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ fn macro_rules_dummy_expander<'cx>(
203203
}
204204

205205
fn trace_macros_note(cx_expansions: &mut FxHashMap<Span, Vec<String>>, sp: Span, message: String) {
206-
let sp = sp.macro_backtrace().last().map(|trace| trace.call_site).unwrap_or(sp);
206+
let sp = sp.macro_backtrace().last().map_or(sp, |trace| trace.call_site);
207207
cx_expansions.entry(sp).or_default().push(message);
208208
}
209209

compiler/rustc_expand/src/mbe/quoted.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ pub(super) fn parse(
9999
}
100100
_ => token.span,
101101
},
102-
tree => tree.as_ref().map(tokenstream::TokenTree::span).unwrap_or(span),
102+
tree => tree.as_ref().map_or(span, tokenstream::TokenTree::span),
103103
}
104104
}
105-
tree => tree.as_ref().map(tokenstream::TokenTree::span).unwrap_or(start_sp),
105+
tree => tree.as_ref().map_or(start_sp, tokenstream::TokenTree::span),
106106
};
107107
if node_id != DUMMY_NODE_ID {
108108
// Macros loaded from other crates have dummy node ids.
@@ -250,7 +250,7 @@ fn parse_kleene_op(
250250
Some(op) => Ok(Ok((op, token.span))),
251251
None => Ok(Err(token)),
252252
},
253-
tree => Err(tree.as_ref().map(tokenstream::TokenTree::span).unwrap_or(span)),
253+
tree => Err(tree.as_ref().map_or(span, tokenstream::TokenTree::span)),
254254
}
255255
}
256256

compiler/rustc_hir/src/hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ impl WhereClause<'_> {
528528
/// in `fn foo<T>(t: T) where T: Foo,` so we don't suggest two trailing commas.
529529
pub fn tail_span_for_suggestion(&self) -> Span {
530530
let end = self.span_for_predicates_or_empty_place().shrink_to_hi();
531-
self.predicates.last().map(|p| p.span()).unwrap_or(end).shrink_to_hi().to(end)
531+
self.predicates.last().map_or(end, |p| p.span()).shrink_to_hi().to(end)
532532
}
533533
}
534534

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2118,7 +2118,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
21182118
let consider = format!(
21192119
"{} {}...",
21202120
msg,
2121-
if type_param_span.map(|(_, _, is_impl_trait)| is_impl_trait).unwrap_or(false) {
2121+
if type_param_span.map_or(false, |(_, _, is_impl_trait)| is_impl_trait) {
21222122
format!(" `{}` to `{}`", sub, bound_kind)
21232123
} else {
21242124
format!("`{}: {}`", bound_kind, sub)

compiler/rustc_infer/src/infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1533,7 +1533,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15331533
// Note: if these two lines are combined into one we get
15341534
// dynamic borrow errors on `self.inner`.
15351535
let known = self.inner.borrow_mut().type_variables().probe(v).known();
1536-
known.map(|t| self.shallow_resolve_ty(t)).unwrap_or(typ)
1536+
known.map_or(typ, |t| self.shallow_resolve_ty(t))
15371537
}
15381538

15391539
ty::Infer(ty::IntVar(v)) => self

compiler/rustc_lint/src/types.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,7 @@ pub fn transparent_newtype_field<'a, 'tcx>(
647647
let param_env = tcx.param_env(variant.def_id);
648648
for field in &variant.fields {
649649
let field_ty = tcx.type_of(field.did);
650-
let is_zst =
651-
tcx.layout_of(param_env.and(field_ty)).map(|layout| layout.is_zst()).unwrap_or(false);
650+
let is_zst = tcx.layout_of(param_env.and(field_ty)).map_or(false, |layout| layout.is_zst());
652651

653652
if !is_zst {
654653
return Some(field);

compiler/rustc_lint/src/unused.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,8 @@ trait UnusedDelimLint {
529529
pprust::expr_to_string(value)
530530
};
531531
let keep_space = (
532-
left_pos.map(|s| s >= value.span.lo()).unwrap_or(false),
533-
right_pos.map(|s| s <= value.span.hi()).unwrap_or(false),
532+
left_pos.map_or(false, |s| s >= value.span.lo()),
533+
right_pos.map_or(false, |s| s <= value.span.hi()),
534534
);
535535
self.emit_unused_delims(cx, value.span, &expr_text, ctx.into(), keep_space);
536536
}

compiler/rustc_macros/src/query.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ fn add_query_description_impl(
429429
};
430430

431431
let (tcx, desc) = modifiers.desc;
432-
let tcx = tcx.as_ref().map(|t| quote! { #t }).unwrap_or(quote! { _ });
432+
let tcx = tcx.as_ref().map_or(quote! { _ }, |t| quote! { #t });
433433

434434
let desc = quote! {
435435
#[allow(unused_variables)]

compiler/rustc_metadata/src/creader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ impl<'a> CrateLoader<'a> {
326326
self.verify_no_symbol_conflicts(&crate_root)?;
327327

328328
let private_dep =
329-
self.sess.opts.externs.get(&name.as_str()).map(|e| e.is_private_dep).unwrap_or(false);
329+
self.sess.opts.externs.get(&name.as_str()).map_or(false, |e| e.is_private_dep);
330330

331331
// Claim this crate number and cache it
332332
let cnum = self.cstore.alloc_new_crate_num();

compiler/rustc_metadata/src/native_libs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> {
132132

133133
impl Collector<'tcx> {
134134
fn register_native_lib(&mut self, span: Option<Span>, lib: NativeLib) {
135-
if lib.name.as_ref().map(|&s| s == kw::Empty).unwrap_or(false) {
135+
if lib.name.as_ref().map_or(false, |&s| s == kw::Empty) {
136136
match span {
137137
Some(span) => {
138138
struct_span_err!(

compiler/rustc_middle/src/hir/map/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ impl<'hir> Map<'hir> {
813813
/// Given a node ID, gets a list of attributes associated with the AST
814814
/// corresponding to the node-ID.
815815
pub fn attrs(&self, id: HirId) -> &'hir [ast::Attribute] {
816-
let attrs = self.find_entry(id).map(|entry| match entry.node {
816+
self.find_entry(id).map_or(&[], |entry| match entry.node {
817817
Node::Param(a) => &a.attrs[..],
818818
Node::Local(l) => &l.attrs[..],
819819
Node::Item(i) => &i.attrs[..],
@@ -840,8 +840,7 @@ impl<'hir> Map<'hir> {
840840
| Node::Block(..)
841841
| Node::Lifetime(..)
842842
| Node::Visibility(..) => &[],
843-
});
844-
attrs.unwrap_or(&[])
843+
})
845844
}
846845

847846
/// Gets the span of the definition of the specified HIR node.

compiler/rustc_middle/src/ty/consts/kind.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<'tcx> ConstKind<'tcx> {
8282
/// Tries to evaluate the constant if it is `Unevaluated`. If that doesn't succeed, return the
8383
/// unevaluated constant.
8484
pub fn eval(self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> Self {
85-
self.try_eval(tcx, param_env).and_then(Result::ok).map(ConstKind::Value).unwrap_or(self)
85+
self.try_eval(tcx, param_env).and_then(Result::ok).map_or(self, ConstKind::Value)
8686
}
8787

8888
#[inline]

compiler/rustc_middle/src/ty/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,7 @@ impl<'tcx> TyCtxt<'tcx> {
13381338
}
13391339

13401340
pub fn serialize_query_result_cache(self, encoder: &mut FileEncoder) -> FileEncodeResult {
1341-
self.queries.on_disk_cache.as_ref().map(|c| c.serialize(self, encoder)).unwrap_or(Ok(()))
1341+
self.queries.on_disk_cache.as_ref().map_or(Ok(()), |c| c.serialize(self, encoder))
13421342
}
13431343

13441344
/// If `true`, we should use the MIR-based borrowck, but also
@@ -2601,7 +2601,7 @@ impl<'tcx> TyCtxt<'tcx> {
26012601
}
26022602

26032603
pub fn is_late_bound(self, id: HirId) -> bool {
2604-
self.is_late_bound_map(id.owner).map(|set| set.contains(&id.local_id)).unwrap_or(false)
2604+
self.is_late_bound_map(id.owner).map_or(false, |set| set.contains(&id.local_id))
26052605
}
26062606

26072607
pub fn object_lifetime_defaults(self, id: HirId) -> Option<&'tcx [ObjectLifetimeDefault]> {

compiler/rustc_middle/src/ty/instance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ fn polymorphize<'tcx>(
535535
} else {
536536
None
537537
};
538-
let has_upvars = upvars_ty.map(|ty| ty.tuple_fields().count() > 0).unwrap_or(false);
538+
let has_upvars = upvars_ty.map_or(false, |ty| ty.tuple_fields().count() > 0);
539539
debug!("polymorphize: upvars_ty={:?} has_upvars={:?}", upvars_ty, has_upvars);
540540

541541
struct PolymorphizationFolder<'tcx> {

compiler/rustc_mir/src/borrow_check/borrow_set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl<'tcx> BorrowSet<'tcx> {
149149
}
150150

151151
crate fn activations_at_location(&self, location: Location) -> &[BorrowIndex] {
152-
self.activation_map.get(&location).map(|activations| &activations[..]).unwrap_or(&[])
152+
self.activation_map.get(&location).map_or(&[], |activations| &activations[..])
153153
}
154154

155155
crate fn len(&self) -> usize {

compiler/rustc_mir/src/borrow_check/diagnostics/explain_borrow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl BorrowExplanation {
7575
LaterUseKind::FakeLetRead => "stored here",
7676
LaterUseKind::Other => "used here",
7777
};
78-
if !borrow_span.map(|sp| sp.overlaps(var_or_use_span)).unwrap_or(false) {
78+
if !borrow_span.map_or(false, |sp| sp.overlaps(var_or_use_span)) {
7979
err.span_label(
8080
var_or_use_span,
8181
format!("{}borrow later {}", borrow_desc, message),

compiler/rustc_mir/src/interpret/eval_context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
370370

371371
#[inline(always)]
372372
pub fn cur_span(&self) -> Span {
373-
self.stack().last().map(|f| f.current_span()).unwrap_or(self.tcx.span)
373+
self.stack().last().map_or(self.tcx.span, |f| f.current_span())
374374
}
375375

376376
#[inline(always)]

compiler/rustc_mir/src/interpret/util.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ where
4747
let index = index
4848
.try_into()
4949
.expect("more generic parameters than can fit into a `u32`");
50-
let is_used =
51-
unused_params.contains(index).map(|unused| !unused).unwrap_or(true);
50+
let is_used = unused_params.contains(index).map_or(true, |unused| !unused);
5251
// Only recurse when generic parameters in fns, closures and generators
5352
// are used and require substitution.
5453
match (is_used, subst.needs_subst()) {

compiler/rustc_mir/src/monomorphize/partitioning/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,7 @@ where
247247
for (mono_item, linkage) in cgu.items() {
248248
let symbol_name = mono_item.symbol_name(tcx).name;
249249
let symbol_hash_start = symbol_name.rfind('h');
250-
let symbol_hash =
251-
symbol_hash_start.map(|i| &symbol_name[i..]).unwrap_or("<no hash>");
250+
let symbol_hash = symbol_hash_start.map_or("<no hash>", |i| &symbol_name[i..]);
252251

253252
debug!(
254253
" - {} [{:?}] [{}] estimated size {}",

compiler/rustc_mir/src/transform/simplify_try.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ fn get_arm_identity_info<'a, 'tcx>(
113113
test: impl Fn(&'a Statement<'tcx>) -> bool,
114114
mut action: impl FnMut(usize, &'a Statement<'tcx>),
115115
) {
116-
while stmt_iter.peek().map(|(_, stmt)| test(stmt)).unwrap_or(false) {
116+
while stmt_iter.peek().map_or(false, |(_, stmt)| test(stmt)) {
117117
let (idx, stmt) = stmt_iter.next().unwrap();
118118

119119
action(idx, stmt);
@@ -635,7 +635,7 @@ impl<'a, 'tcx> SimplifyBranchSameOptimizationFinder<'a, 'tcx> {
635635
})
636636
.peekable();
637637

638-
let bb_first = iter_bbs_reachable.peek().map(|(idx, _)| *idx).unwrap_or(&targets_and_values[0]);
638+
let bb_first = iter_bbs_reachable.peek().map_or(&targets_and_values[0], |(idx, _)| *idx);
639639
let mut all_successors_equivalent = StatementEquality::TrivialEqual;
640640

641641
// All successor basic blocks must be equal or contain statements that are pairwise considered equal.

compiler/rustc_mir_build/src/thir/pattern/usefulness.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ fn is_useful<'p, 'tcx>(
952952
assert!(rows.iter().all(|r| r.len() == v.len()));
953953

954954
// FIXME(Nadrieril): Hack to work around type normalization issues (see #72476).
955-
let ty = matrix.heads().next().map(|r| r.ty).unwrap_or(v.head().ty);
955+
let ty = matrix.heads().next().map_or(v.head().ty, |r| r.ty);
956956
let pcx = PatCtxt { cx, ty, span: v.head().span, is_top_level };
957957

958958
debug!("is_useful_expand_first_col: ty={:#?}, expanding {:#?}", pcx.ty, v.head());

compiler/rustc_parse/src/parser/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ impl<'a> Parser<'a> {
511511
//
512512
// `x.foo::<u32>>>(3)`
513513
let parsed_angle_bracket_args =
514-
segment.args.as_ref().map(|args| args.is_angle_bracketed()).unwrap_or(false);
514+
segment.args.as_ref().map_or(false, |args| args.is_angle_bracketed());
515515

516516
debug!(
517517
"check_trailing_angle_brackets: parsed_angle_bracket_args={:?}",

compiler/rustc_parse_format/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ impl<'a> Parser<'a> {
347347
let mut pos = pos;
348348
// This handles the raw string case, the raw argument is the number of #
349349
// in r###"..."### (we need to add one because of the `r`).
350-
let raw = self.style.map(|raw| raw + 1).unwrap_or(0);
350+
let raw = self.style.map_or(0, |raw| raw + 1);
351351
for skip in &self.skips {
352352
if pos > *skip {
353353
pos += 1;
@@ -814,7 +814,7 @@ fn find_skips_from_snippet(
814814
skips
815815
}
816816

817-
let r_start = str_style.map(|r| r + 1).unwrap_or(0);
817+
let r_start = str_style.map_or(0, |r| r + 1);
818818
let r_end = str_style.unwrap_or(0);
819819
let s = &snippet[r_start + 1..snippet.len() - r_end - 1];
820820
(find_skips(s, str_style.is_some()), true)

compiler/rustc_query_system/src/dep_graph/graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ impl<K: DepKind> DepGraph<K> {
953953
// Returns true if the given node has been marked as green during the
954954
// current compilation session. Used in various assertions
955955
pub fn is_green(&self, dep_node: &DepNode<K>) -> bool {
956-
self.node_color(dep_node).map(|c| c.is_green()).unwrap_or(false)
956+
self.node_color(dep_node).map_or(false, |c| c.is_green())
957957
}
958958

959959
// This method loads all on-disk cacheable query results into memory, so

compiler/rustc_resolve/src/late.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1925,7 +1925,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
19251925
{
19261926
// Check if we wrote `str::from_utf8` instead of `std::str::from_utf8`
19271927
let item_span =
1928-
path.iter().last().map(|segment| segment.ident.span).unwrap_or(span);
1928+
path.iter().last().map_or(span, |segment| segment.ident.span);
19291929

19301930
let mut hm = self.r.session.confused_type_with_std_module.borrow_mut();
19311931
hm.insert(item_span, span);

compiler/rustc_resolve/src/late/diagnostics.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
264264
// The current function has a `self' parameter, but we were unable to resolve
265265
// a reference to `self`. This can only happen if the `self` identifier we
266266
// are resolving came from a different hygiene context.
267-
if fn_kind.decl().inputs.get(0).map(|p| p.is_self()).unwrap_or(false) {
267+
if fn_kind.decl().inputs.get(0).map_or(false, |p| p.is_self()) {
268268
err.span_label(*span, "this function has a `self` parameter, but a macro invocation can only access identifiers it receives from parameters");
269269
} else {
270270
let doesnt = if is_assoc_fn {
@@ -1452,8 +1452,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
14521452
}
14531453
} else {
14541454
let needs_placeholder = |def_id: DefId, kind: CtorKind| {
1455-
let has_no_fields =
1456-
self.r.field_names.get(&def_id).map(|f| f.is_empty()).unwrap_or(false);
1455+
let has_no_fields = self.r.field_names.get(&def_id).map_or(false, |f| f.is_empty());
14571456
match kind {
14581457
CtorKind::Const => false,
14591458
CtorKind::Fn | CtorKind::Fictive if has_no_fields => false,

0 commit comments

Comments
 (0)