Skip to content

Commit a584d87

Browse files
authored
Rollup merge of #80944 - LingMan:map_or, r=nagisa
Use Option::map_or instead of `.map(..).unwrap_or(..)` ``@rustbot`` modify labels +C-cleanup +T-compiler
2 parents 1b8fd02 + a56bffb commit a584d87

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)