Skip to content

Commit 2ef8af6

Browse files
committed
Adopt let else in more places
1 parent b8c56fa commit 2ef8af6

File tree

132 files changed

+539
-881
lines changed

Some content is hidden

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

132 files changed

+539
-881
lines changed

compiler/rustc_ast_lowering/src/asm.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
338338

339339
let idx2 = *o.get();
340340
let &(ref op2, op_sp2) = &operands[idx2];
341-
let reg2 = match op2.reg() {
342-
Some(asm::InlineAsmRegOrRegClass::Reg(r)) => r,
343-
_ => unreachable!(),
341+
let Some(asm::InlineAsmRegOrRegClass::Reg(reg2)) = op2.reg() else {
342+
unreachable!();
344343
};
345344

346345
let msg = format!(

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
326326
args: Vec<AstP<Expr>>,
327327
legacy_args_idx: &[usize],
328328
) -> hir::ExprKind<'hir> {
329-
let path = match f.kind {
330-
ExprKind::Path(None, ref mut path) => path,
331-
_ => unreachable!(),
329+
let ExprKind::Path(None, ref mut path) = f.kind else {
330+
unreachable!();
332331
};
333332

334333
// Split the arguments into const generics and normal arguments

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,9 +1331,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
13311331
// keep track of the Span info. Now, `add_implicitly_sized` in `AstConv` checks both param bounds and
13321332
// where clauses for `?Sized`.
13331333
for pred in &generics.where_clause.predicates {
1334-
let bound_pred = match *pred {
1335-
WherePredicate::BoundPredicate(ref bound_pred) => bound_pred,
1336-
_ => continue,
1334+
let WherePredicate::BoundPredicate(ref bound_pred) = *pred else {
1335+
continue;
13371336
};
13381337
let compute_is_param = || {
13391338
// Check if the where clause type is a plain type parameter.

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -482,9 +482,8 @@ impl<'a> AstValidator<'a> {
482482
}
483483

484484
fn check_foreign_kind_bodyless(&self, ident: Ident, kind: &str, body: Option<Span>) {
485-
let body = match body {
486-
None => return,
487-
Some(body) => body,
485+
let Some(body) = body else {
486+
return;
488487
};
489488
self.err_handler()
490489
.struct_span_err(ident.span, &format!("incorrect `{}` inside `extern` block", kind))
@@ -504,9 +503,8 @@ impl<'a> AstValidator<'a> {
504503

505504
/// An `fn` in `extern { ... }` cannot have a body `{ ... }`.
506505
fn check_foreign_fn_bodyless(&self, ident: Ident, body: Option<&Block>) {
507-
let body = match body {
508-
None => return,
509-
Some(body) => body,
506+
let Some(body) = body else {
507+
return;
510508
};
511509
self.err_handler()
512510
.struct_span_err(ident.span, "incorrect function inside `extern` block")

compiler/rustc_ast_passes/src/show_span.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ impl<'a> Visitor<'a> for ShowSpanVisitor<'a> {
5757
}
5858

5959
pub fn run(span_diagnostic: &rustc_errors::Handler, mode: &str, krate: &ast::Crate) {
60-
let mode = match mode.parse().ok() {
61-
Some(mode) => mode,
62-
None => return,
60+
let Ok(mode) = mode.parse() else {
61+
return;
6362
};
6463
let mut v = ShowSpanVisitor { span_diagnostic, mode };
6564
visit::walk_crate(&mut v, krate);

compiler/rustc_attr/src/builtin.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -531,17 +531,14 @@ pub fn eval_condition(
531531
return false;
532532
}
533533
};
534-
let min_version = match parse_version(min_version.as_str(), false) {
535-
Some(ver) => ver,
536-
None => {
537-
sess.span_diagnostic
538-
.struct_span_warn(
539-
*span,
540-
"unknown version literal format, assuming it refers to a future version",
541-
)
542-
.emit();
543-
return false;
544-
}
534+
let Some(min_version) = parse_version(min_version.as_str(), false) else {
535+
sess.span_diagnostic
536+
.struct_span_warn(
537+
*span,
538+
"unknown version literal format, assuming it refers to a future version",
539+
)
540+
.emit();
541+
return false;
545542
};
546543
let rustc_version = parse_version(env!("CFG_RELEASE"), true).unwrap();
547544

@@ -644,9 +641,8 @@ where
644641
break;
645642
}
646643

647-
let meta = match attr.meta() {
648-
Some(meta) => meta,
649-
None => continue,
644+
let Some(meta) = attr.meta() else {
645+
continue;
650646
};
651647
let mut since = None;
652648
let mut note = None;

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,22 +2071,17 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
20712071
) = rvalue
20722072
{
20732073
for operand in operands {
2074-
let assigned_from = match operand {
2075-
Operand::Copy(assigned_from) | Operand::Move(assigned_from) => {
2076-
assigned_from
2077-
}
2078-
_ => continue,
2074+
let (Operand::Copy(assigned_from) | Operand::Move(assigned_from)) = operand else {
2075+
continue;
20792076
};
20802077
debug!(
20812078
"annotate_argument_and_return_for_borrow: assigned_from={:?}",
20822079
assigned_from
20832080
);
20842081

20852082
// Find the local from the operand.
2086-
let assigned_from_local = match assigned_from.local_or_deref_local()
2087-
{
2088-
Some(local) => local,
2089-
None => continue,
2083+
let Some(assigned_from_local) = assigned_from.local_or_deref_local() else {
2084+
continue;
20902085
};
20912086

20922087
if assigned_from_local != target {
@@ -2138,10 +2133,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
21382133
);
21392134

21402135
// Find the local from the rvalue.
2141-
let assigned_from_local = match assigned_from.local_or_deref_local() {
2142-
Some(local) => local,
2143-
None => continue,
2144-
};
2136+
let Some(assigned_from_local) = assigned_from.local_or_deref_local() else { continue };
21452137
debug!(
21462138
"annotate_argument_and_return_for_borrow: \
21472139
assigned_from_local={:?}",
@@ -2189,11 +2181,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
21892181
assigned_to, args
21902182
);
21912183
for operand in args {
2192-
let assigned_from = match operand {
2193-
Operand::Copy(assigned_from) | Operand::Move(assigned_from) => {
2194-
assigned_from
2195-
}
2196-
_ => continue,
2184+
let (Operand::Copy(assigned_from) | Operand::Move(assigned_from)) = operand else {
2185+
continue;
21972186
};
21982187
debug!(
21992188
"annotate_argument_and_return_for_borrow: assigned_from={:?}",

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -650,13 +650,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
650650

651651
// The only kind of statement that we care about is assignments...
652652
if let StatementKind::Assign(box (place, rvalue)) = &stmt.kind {
653-
let into = match place.local_or_deref_local() {
654-
Some(into) => into,
655-
None => {
656-
// Continue at the next location.
657-
queue.push(current_location.successor_within_block());
658-
continue;
659-
}
653+
let Some(into) = place.local_or_deref_local() else {
654+
// Continue at the next location.
655+
queue.push(current_location.successor_within_block());
656+
continue;
660657
};
661658

662659
match rvalue {

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
444444
debug!("borrowed_content_source: init={:?}", init);
445445
// We're only interested in statements that initialized a value, not the
446446
// initializations from arguments.
447-
let loc = match init.location {
448-
InitLocation::Statement(stmt) => stmt,
449-
_ => continue,
450-
};
447+
let InitLocation::Statement(loc) = init.location else { continue };
451448

452449
let bbd = &self.body[loc.block];
453450
let is_terminator = bbd.statements.len() == loc.statement_index;
@@ -787,9 +784,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
787784
) -> UseSpans<'tcx> {
788785
use self::UseSpans::*;
789786

790-
let stmt = match self.body[location.block].statements.get(location.statement_index) {
791-
Some(stmt) => stmt,
792-
None => return OtherUse(self.body.source_info(location).span),
787+
let Some(stmt) = self.body[location.block].statements.get(location.statement_index) else {
788+
return OtherUse(self.body.source_info(location).span);
793789
};
794790

795791
debug!("move_spans: moved_place={:?} location={:?} stmt={:?}", moved_place, location, stmt);

compiler/rustc_borrowck/src/diagnostics/move_errors.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
188188
}
189189
// Error with the pattern
190190
LookupResult::Exact(_) => {
191-
let mpi = match self.move_data.rev_lookup.find(move_from.as_ref()) {
192-
LookupResult::Parent(Some(mpi)) => mpi,
191+
let LookupResult::Parent(Some(mpi)) = self.move_data.rev_lookup.find(move_from.as_ref()) else {
193192
// move_from should be a projection from match_place.
194-
_ => unreachable!("Probably not unreachable..."),
193+
unreachable!("Probably not unreachable...");
195194
};
196195
for ge in &mut *grouped_errors {
197196
if let GroupedMoveError::MovesFromValue {

0 commit comments

Comments
 (0)