1
Fork 0

Rollup merge of #91018 - est31:let_else, r=matthewjasper

Adopt let_else in more places in rustc_mir_build

Helps avoid rightward drift.

followup of #89933
This commit is contained in:
Matthias Krüger 2021-11-20 22:33:50 +01:00 committed by GitHub
commit f37a6caffe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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 // encounter a candidate where the test is not relevant; at
// that point, we stop sorting. // that point, we stop sorting.
while let Some(candidate) = candidates.first_mut() { 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 {
let (candidate, rest) = candidates.split_first_mut().unwrap();
target_candidates[idx].push(candidate);
candidates = rest;
} else {
break; break;
} };
let (candidate, rest) = candidates.split_first_mut().unwrap();
target_candidates[idx].push(candidate);
candidates = rest;
} }
// at least the first candidate ought to be tested // at least the first candidate ought to be tested
assert!(total_candidate_count > candidates.len()); assert!(total_candidate_count > candidates.len());

View file

@ -966,59 +966,58 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
DropKind::Value, DropKind::Value,
); );
if let Some(arg) = arg_opt { let Some(arg) = arg_opt else {
let pat = match tcx.hir().get(arg.pat.hir_id) { continue;
Node::Pat(pat) | Node::Binding(pat) => pat, };
node => bug!("pattern became {:?}", node), let pat = match tcx.hir().get(arg.pat.hir_id) {
}; Node::Pat(pat) | Node::Binding(pat) => pat,
let pattern = pat_from_hir(tcx, self.param_env, self.typeck_results, pat); node => bug!("pattern became {:?}", node),
let original_source_scope = self.source_scope; };
let span = pattern.span; let pattern = pat_from_hir(tcx, self.param_env, self.typeck_results, pat);
self.set_correct_source_scope_for_arg(arg.hir_id, original_source_scope, span); let original_source_scope = self.source_scope;
match *pattern.kind { let span = pattern.span;
// Don't introduce extra copies for simple bindings self.set_correct_source_scope_for_arg(arg.hir_id, original_source_scope, span);
PatKind::Binding { match *pattern.kind {
mutability, // Don't introduce extra copies for simple bindings
var, PatKind::Binding {
mode: BindingMode::ByValue, mutability,
subpattern: None, var,
.. mode: BindingMode::ByValue,
} => { subpattern: None,
self.local_decls[local].mutability = mutability; ..
self.local_decls[local].source_info.scope = self.source_scope; } => {
self.local_decls[local].local_info = if let Some(kind) = self_binding { self.local_decls[local].mutability = mutability;
Some(Box::new(LocalInfo::User(ClearCrossCrate::Set( self.local_decls[local].source_info.scope = self.source_scope;
BindingForm::ImplicitSelf(*kind), self.local_decls[local].local_info = if let Some(kind) = self_binding {
)))) Some(Box::new(LocalInfo::User(ClearCrossCrate::Set(
} else { BindingForm::ImplicitSelf(*kind),
let binding_mode = ty::BindingMode::BindByValue(mutability); ))))
Some(Box::new(LocalInfo::User(ClearCrossCrate::Set(BindingForm::Var( } else {
VarBindingForm { let binding_mode = ty::BindingMode::BindByValue(mutability);
binding_mode, Some(Box::new(LocalInfo::User(ClearCrossCrate::Set(BindingForm::Var(
opt_ty_info, VarBindingForm {
opt_match_place: Some((Some(place), span)), binding_mode,
pat_span: span, opt_ty_info,
}, opt_match_place: Some((Some(place), span)),
))))) pat_span: span,
}; },
self.var_indices.insert(var, LocalsForNode::One(local)); )))))
} };
_ => { self.var_indices.insert(var, LocalsForNode::One(local));
scope = self.declare_bindings( }
scope, _ => {
expr.span, scope = self.declare_bindings(
&pattern, scope,
matches::ArmHasGuard(false), expr.span,
Some((Some(&place), span)), &pattern,
); matches::ArmHasGuard(false),
let place_builder = PlaceBuilder::from(local); Some((Some(&place), span)),
unpack!( );
block = self.place_into_pattern(block, pattern, place_builder, false) let place_builder = PlaceBuilder::from(local);
); unpack!(block = self.place_into_pattern(block, pattern, place_builder, false));
}
} }
self.source_scope = original_source_scope;
} }
self.source_scope = original_source_scope;
} }
// Enter the argument pattern bindings source scope, if it exists. // Enter the argument pattern bindings source scope, if it exists.

View file

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