Use more let_else in rustc_mir_build

Helps avoid rightward drift.
This commit is contained in:
est31 2021-11-18 17:21:21 +01:00
parent 6414e0b5b3
commit 8dc8e72c4d
3 changed files with 66 additions and 69 deletions

View file

@ -1606,13 +1606,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// encounter a candidate where the test is not relevant; at
// that point, we stop sorting.
while let Some(candidate) = candidates.first_mut() {
if let Some(idx) = self.sort_candidate(&match_place.clone(), &test, candidate) {
let Some(idx) = self.sort_candidate(&match_place.clone(), &test, candidate) else {
break;
};
let (candidate, rest) = candidates.split_first_mut().unwrap();
target_candidates[idx].push(candidate);
candidates = rest;
} else {
break;
}
}
// at least the first candidate ought to be tested
assert!(total_candidate_count > candidates.len());

View file

@ -966,7 +966,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
DropKind::Value,
);
if let Some(arg) = arg_opt {
let Some(arg) = arg_opt else {
continue;
};
let pat = match tcx.hir().get(arg.pat.hir_id) {
Node::Pat(pat) | Node::Binding(pat) => pat,
node => bug!("pattern became {:?}", node),
@ -1012,14 +1014,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Some((Some(&place), span)),
);
let place_builder = PlaceBuilder::from(local);
unpack!(
block = self.place_into_pattern(block, pattern, place_builder, false)
);
unpack!(block = self.place_into_pattern(block, pattern, place_builder, false));
}
}
self.source_scope = original_source_scope;
}
}
// Enter the argument pattern bindings source scope, if it exists.
if let Some(source_scope) = scope {

View file

@ -256,7 +256,13 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
}
PatKind::Binding { mode: BindingMode::ByRef(borrow_kind), ty, .. } => {
if self.inside_adt {
if let ty::Ref(_, ty, _) = ty.kind() {
let ty::Ref(_, ty, _) = ty.kind() else {
span_bug!(
pat.span,
"BindingMode::ByRef in pattern, but found non-reference type {}",
ty
);
};
match borrow_kind {
BorrowKind::Shallow | BorrowKind::Shared | BorrowKind::Unique => {
if !ty.is_freeze(self.tcx.at(pat.span), self.param_env) {
@ -267,13 +273,6 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
self.requires_unsafe(pat.span, MutationOfLayoutConstrainedField);
}
}
} else {
span_bug!(
pat.span,
"BindingMode::ByRef in pattern, but found non-reference type {}",
ty
);
}
}
visit::walk_pat(self, pat);
}