Skip to content

Commit 1418df5

Browse files
committed
Adopt let_else across the compiler
This performs a substitution of code following the pattern: let <id> = if let <pat> = ... { identity } else { ... : ! }; To simplify it to: let <pat> = ... { identity } else { ... : ! }; By adopting the let_else feature.
1 parent c102653 commit 1418df5

File tree

51 files changed

+69
-137
lines changed

Some content is hidden

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

51 files changed

+69
-137
lines changed

compiler/rustc_borrowck/src/borrow_set.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,7 @@ impl<'a, 'tcx> GatherBorrows<'a, 'tcx> {
315315
// TEMP = &foo
316316
//
317317
// so extract `temp`.
318-
let temp = if let Some(temp) = assigned_place.as_local() {
319-
temp
320-
} else {
318+
let Some(temp) = assigned_place.as_local() else {
321319
span_bug!(
322320
self.body.source_info(start_location).span,
323321
"expected 2-phase borrow to assign to a local, not `{:?}`",

compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ impl OutlivesSuggestionBuilder {
9090
let mut unified_already = FxHashSet::default();
9191

9292
for (fr, outlived) in &self.constraints_to_add {
93-
let fr_name = if let Some(fr_name) = self.region_vid_to_name(mbcx, *fr) {
94-
fr_name
95-
} else {
93+
let Some(fr_name) = self.region_vid_to_name(mbcx, *fr) else {
9694
continue;
9795
};
9896

compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#![feature(format_args_capture)]
88
#![feature(in_band_lifetimes)]
99
#![feature(iter_zip)]
10+
#![feature(let_else)]
1011
#![feature(min_specialization)]
1112
#![feature(stmt_expr_attributes)]
1213
#![feature(trusted_step)]

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,8 @@ pub fn each_linked_rlib(
174174
_ => {}
175175
}
176176
}
177-
let fmts = match fmts {
178-
Some(f) => f,
179-
None => return Err("could not find formats for rlibs".to_string()),
177+
let Some(fmts) = fmts else {
178+
return Err("could not find formats for rlibs".to_string());
180179
};
181180
for &cnum in crates {
182181
match fmts.get(cnum.as_usize() - 1) {

compiler/rustc_codegen_ssa/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#![feature(box_patterns)]
44
#![feature(try_blocks)]
55
#![feature(in_band_lifetimes)]
6+
#![feature(let_else)]
67
#![feature(once_cell)]
78
#![feature(nll)]
89
#![feature(associated_type_bounds)]

compiler/rustc_codegen_ssa/src/mir/operand.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,7 @@ impl<'a, 'tcx, V: CodegenObject> OperandValue<V> {
343343
.unwrap_or_else(|| bug!("indirect_dest has non-pointer type: {:?}", indirect_dest))
344344
.ty;
345345

346-
let (llptr, llextra) = if let OperandValue::Ref(llptr, Some(llextra), _) = self {
347-
(llptr, llextra)
348-
} else {
346+
let OperandValue::Ref(llptr, Some(llextra), _) = self else {
349347
bug!("store_unsized called with a sized value")
350348
};
351349

compiler/rustc_const_eval/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Rust MIR: a lowered representation of Rust.
1313
#![feature(exact_size_is_empty)]
1414
#![feature(in_band_lifetimes)]
1515
#![feature(iter_zip)]
16+
#![feature(let_else)]
1617
#![feature(map_try_insert)]
1718
#![feature(min_specialization)]
1819
#![feature(slice_ptr_get)]

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ impl Qualif for NeedsNonConstDrop {
122122
Ok([..]) => {}
123123
}
124124

125-
let drop_trait = if let Some(did) = cx.tcx.lang_items().drop_trait() {
126-
did
127-
} else {
125+
let Some(drop_trait) = cx.tcx.lang_items().drop_trait() else {
128126
// there is no way to define a type that needs non-const drop
129127
// without having the lang item present.
130128
return false;

compiler/rustc_errors/src/emitter.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -449,11 +449,7 @@ pub trait Emitter {
449449
span: &mut MultiSpan,
450450
children: &mut Vec<SubDiagnostic>,
451451
) {
452-
let source_map = if let Some(ref sm) = source_map {
453-
sm
454-
} else {
455-
return;
456-
};
452+
let Some(source_map) = source_map else { return };
457453
debug!("fix_multispans_in_extern_macros: before: span={:?} children={:?}", span, children);
458454
self.fix_multispan_in_extern_macros(source_map, span);
459455
for child in children.iter_mut() {

compiler/rustc_errors/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#![feature(if_let_guard)]
99
#![feature(format_args_capture)]
1010
#![feature(iter_zip)]
11+
#![feature(let_else)]
1112
#![feature(nll)]
1213

1314
#[macro_use]

0 commit comments

Comments
 (0)