Skip to content

Commit 4e208f6

Browse files
committed
Auto merge of rust-lang#81035 - JohnTitor:rollup-9m03awf, r=JohnTitor
Rollup of 5 pull requests Successful merges: - rust-lang#80254 (Don't try to add nested predicate to Rustdoc auto-trait `ParamEnv`) - rust-lang#80834 (Remove unreachable panics from VecDeque::{front/back}[_mut]) - rust-lang#80944 (Use Option::map_or instead of `.map(..).unwrap_or(..)`) - rust-lang#81008 (Don't ICE when computing a layout of a generator tainted by errors) - rust-lang#81023 (Remove doctree::Variant) Failed merges: - rust-lang#81033 (Remove useless `clean::Variant` struct) r? `@ghost` `@rustbot` modify labels: rollup
2 parents dcf622e + 7286be1 commit 4e208f6

File tree

62 files changed

+181
-117
lines changed

Some content is hidden

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

62 files changed

+181
-117
lines changed

Diff for: 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)

Diff for: 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
);

Diff for: 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);

Diff for: compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1832,8 +1832,9 @@ impl<'tcx> VariantInfo<'_, 'tcx> {
18321832
fn source_info(&self, cx: &CodegenCx<'ll, 'tcx>) -> Option<SourceInfo<'ll>> {
18331833
match self {
18341834
VariantInfo::Generator { def_id, variant_index, .. } => {
1835-
let span =
1836-
cx.tcx.generator_layout(*def_id).variant_source_info[*variant_index].span;
1835+
let span = cx.tcx.generator_layout(*def_id).unwrap().variant_source_info
1836+
[*variant_index]
1837+
.span;
18371838
if !span.is_dummy() {
18381839
let loc = cx.lookup_debug_loc(span.lo());
18391840
return Some(SourceInfo {

Diff for: 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
},

Diff for: 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,

Diff for: 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

Diff for: 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
}

Diff for: 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,

Diff for: 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
}

Diff for: 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

Diff for: 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

Diff for: compiler/rustc_hir/src/hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ impl WhereClause<'_> {
561561
/// in `fn foo<T>(t: T) where T: Foo,` so we don't suggest two trailing commas.
562562
pub fn tail_span_for_suggestion(&self) -> Span {
563563
let end = self.span_for_predicates_or_empty_place().shrink_to_hi();
564-
self.predicates.last().map(|p| p.span()).unwrap_or(end).shrink_to_hi().to(end)
564+
self.predicates.last().map_or(end, |p| p.span()).shrink_to_hi().to(end)
565565
}
566566
}
567567

Diff for: 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)

Diff for: 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

Diff for: 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);

Diff for: 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
}

Diff for: 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)]

Diff for: 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();

Diff for: 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!(

Diff for: compiler/rustc_middle/src/hir/map/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ impl<'hir> Map<'hir> {
815815
/// Given a node ID, gets a list of attributes associated with the AST
816816
/// corresponding to the node-ID.
817817
pub fn attrs(&self, id: HirId) -> &'hir [ast::Attribute] {
818-
let attrs = self.find_entry(id).map(|entry| match entry.node {
818+
self.find_entry(id).map_or(&[], |entry| match entry.node {
819819
Node::Param(a) => &a.attrs[..],
820820
Node::Local(l) => &l.attrs[..],
821821
Node::Item(i) => &i.attrs[..],
@@ -842,8 +842,7 @@ impl<'hir> Map<'hir> {
842842
| Node::Block(..)
843843
| Node::Lifetime(..)
844844
| Node::Visibility(..) => &[],
845-
});
846-
attrs.unwrap_or(&[])
845+
})
847846
}
848847

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

Diff for: 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]

Diff for: 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]> {

Diff for: 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> {

Diff for: compiler/rustc_middle/src/ty/layout.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1466,10 +1466,12 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
14661466
) -> Result<&'tcx Layout, LayoutError<'tcx>> {
14671467
use SavedLocalEligibility::*;
14681468
let tcx = self.tcx;
1469-
14701469
let subst_field = |ty: Ty<'tcx>| ty.subst(tcx, substs);
14711470

1472-
let info = tcx.generator_layout(def_id);
1471+
let info = match tcx.generator_layout(def_id) {
1472+
None => return Err(LayoutError::Unknown(ty)),
1473+
Some(info) => info,
1474+
};
14731475
let (ineligible_locals, assignments) = self.generator_saved_local_eligibility(&info);
14741476

14751477
// Build a prefix layout, including "promoting" all ineligible

Diff for: compiler/rustc_middle/src/ty/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -3068,8 +3068,10 @@ impl<'tcx> TyCtxt<'tcx> {
30683068
self.trait_def(trait_def_id).has_auto_impl
30693069
}
30703070

3071-
pub fn generator_layout(self, def_id: DefId) -> &'tcx GeneratorLayout<'tcx> {
3072-
self.optimized_mir(def_id).generator_layout.as_ref().unwrap()
3071+
/// Returns layout of a generator. Layout might be unavailable if the
3072+
/// generator is tainted by errors.
3073+
pub fn generator_layout(self, def_id: DefId) -> Option<&'tcx GeneratorLayout<'tcx>> {
3074+
self.optimized_mir(def_id).generator_layout.as_ref()
30733075
}
30743076

30753077
/// Given the `DefId` of an impl, returns the `DefId` of the trait it implements.

Diff for: compiler/rustc_middle/src/ty/sty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ impl<'tcx> GeneratorSubsts<'tcx> {
605605
#[inline]
606606
pub fn variant_range(&self, def_id: DefId, tcx: TyCtxt<'tcx>) -> Range<VariantIdx> {
607607
// FIXME requires optimized MIR
608-
let num_variants = tcx.generator_layout(def_id).variant_fields.len();
608+
let num_variants = tcx.generator_layout(def_id).unwrap().variant_fields.len();
609609
VariantIdx::new(0)..VariantIdx::new(num_variants)
610610
}
611611

@@ -666,7 +666,7 @@ impl<'tcx> GeneratorSubsts<'tcx> {
666666
def_id: DefId,
667667
tcx: TyCtxt<'tcx>,
668668
) -> impl Iterator<Item = impl Iterator<Item = Ty<'tcx>> + Captures<'tcx>> {
669-
let layout = tcx.generator_layout(def_id);
669+
let layout = tcx.generator_layout(def_id).unwrap();
670670
layout.variant_fields.iter().map(move |variant| {
671671
variant.iter().map(move |field| layout.field_tys[*field].subst(tcx, self.substs))
672672
})

Diff for: 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 {

Diff for: 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),

Diff for: 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)]

Diff for: 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()) {

Diff for: 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 {}",

Diff for: 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.

Diff for: 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());

Diff for: 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={:?}",

0 commit comments

Comments
 (0)