Skip to content

Commit 8ab2dcc

Browse files
authored
Rollup merge of rust-lang#94420 - c410-f3r:more-let-chains, r=Dylan-DPC
3 - Make more use of `let_chains` Continuation of rust-lang#94376. cc rust-lang#53667
2 parents 178df4e + 0eb8b32 commit 8ab2dcc

File tree

6 files changed

+44
-58
lines changed

6 files changed

+44
-58
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -1921,17 +1921,16 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
19211921
err.span_label(assigned_span, format!("first assignment to {}", place_description));
19221922
}
19231923
}
1924-
if let Some(decl) = local_decl {
1925-
if let Some(name) = local_name {
1926-
if decl.can_be_made_mutable() {
1927-
err.span_suggestion(
1928-
decl.source_info.span,
1929-
"consider making this binding mutable",
1930-
format!("mut {}", name),
1931-
Applicability::MachineApplicable,
1932-
);
1933-
}
1934-
}
1924+
if let Some(decl) = local_decl
1925+
&& let Some(name) = local_name
1926+
&& decl.can_be_made_mutable()
1927+
{
1928+
err.span_suggestion(
1929+
decl.source_info.span,
1930+
"consider making this binding mutable",
1931+
format!("mut {}", name),
1932+
Applicability::MachineApplicable,
1933+
);
19351934
}
19361935
err.span_label(span, msg);
19371936
self.buffer_error(err);

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -375,15 +375,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
375375

376376
Some(Cause::DropVar(local, location)) => {
377377
let mut should_note_order = false;
378-
if self.local_names[local].is_some() {
379-
if let Some((WriteKind::StorageDeadOrDrop, place)) = kind_place {
380-
if let Some(borrowed_local) = place.as_local() {
381-
if self.local_names[borrowed_local].is_some() && local != borrowed_local
382-
{
383-
should_note_order = true;
384-
}
385-
}
386-
}
378+
if self.local_names[local].is_some()
379+
&& let Some((WriteKind::StorageDeadOrDrop, place)) = kind_place
380+
&& let Some(borrowed_local) = place.as_local()
381+
&& self.local_names[borrowed_local].is_some() && local != borrowed_local
382+
{
383+
should_note_order = true;
387384
}
388385

389386
BorrowExplanation::UsedLaterWhenDropped {

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+11-15
Original file line numberDiff line numberDiff line change
@@ -1086,21 +1086,17 @@ fn get_mut_span_in_struct_field<'tcx>(
10861086
field: &mir::Field,
10871087
) -> Option<Span> {
10881088
// Expect our local to be a reference to a struct of some kind.
1089-
if let ty::Ref(_, ty, _) = ty.kind() {
1090-
if let ty::Adt(def, _) = ty.kind() {
1091-
let field = def.all_fields().nth(field.index())?;
1092-
// Use the HIR types to construct the diagnostic message.
1093-
let node = tcx.hir().find_by_def_id(field.did.as_local()?)?;
1094-
// Now we're dealing with the actual struct that we're going to suggest a change to,
1095-
// we can expect a field that is an immutable reference to a type.
1096-
if let hir::Node::Field(field) = node {
1097-
if let hir::TyKind::Rptr(lifetime, hir::MutTy { mutbl: hir::Mutability::Not, ty }) =
1098-
field.ty.kind
1099-
{
1100-
return Some(lifetime.span.between(ty.span));
1101-
}
1102-
}
1103-
}
1089+
if let ty::Ref(_, ty, _) = ty.kind()
1090+
&& let ty::Adt(def, _) = ty.kind()
1091+
&& let field = def.all_fields().nth(field.index())?
1092+
// Use the HIR types to construct the diagnostic message.
1093+
&& let node = tcx.hir().find_by_def_id(field.did.as_local()?)?
1094+
// Now we're dealing with the actual struct that we're going to suggest a change to,
1095+
// we can expect a field that is an immutable reference to a type.
1096+
&& let hir::Node::Field(field) = node
1097+
&& let hir::TyKind::Rptr(lt, hir::MutTy { mutbl: hir::Mutability::Not, ty }) = field.ty.kind
1098+
{
1099+
return Some(lt.span.between(ty.span));
11041100
}
11051101

11061102
None

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
140140

141141
/// Returns `true` if a closure is inferred to be an `FnMut` closure.
142142
fn is_closure_fn_mut(&self, fr: RegionVid) -> bool {
143-
if let Some(ty::ReFree(free_region)) = self.to_error_region(fr).as_deref() {
144-
if let ty::BoundRegionKind::BrEnv = free_region.bound_region {
145-
if let DefiningTy::Closure(_, substs) =
146-
self.regioncx.universal_regions().defining_ty
147-
{
148-
return substs.as_closure().kind() == ty::ClosureKind::FnMut;
149-
}
150-
}
143+
if let Some(ty::ReFree(free_region)) = self.to_error_region(fr).as_deref()
144+
&& let ty::BoundRegionKind::BrEnv = free_region.bound_region
145+
&& let DefiningTy::Closure(_, substs) = self.regioncx.universal_regions().defining_ty
146+
{
147+
return substs.as_closure().kind() == ty::ClosureKind::FnMut;
151148
}
152149

153150
false

compiler/rustc_borrowck/src/lib.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
//! This query borrow-checks the MIR to (further) ensure it is not broken.
22
3+
#![allow(rustc::potential_query_instability)]
34
#![feature(bool_to_option)]
45
#![feature(box_patterns)]
56
#![feature(crate_visibility_modifier)]
7+
#![feature(let_chains)]
68
#![feature(let_else)]
79
#![feature(min_specialization)]
810
#![feature(stmt_expr_attributes)]
911
#![feature(trusted_step)]
1012
#![feature(try_blocks)]
1113
#![recursion_limit = "256"]
12-
#![allow(rustc::potential_query_instability)]
1314

1415
#[macro_use]
1516
extern crate rustc_middle;
@@ -159,16 +160,14 @@ fn do_mir_borrowck<'a, 'tcx>(
159160
for var_debug_info in &input_body.var_debug_info {
160161
if let VarDebugInfoContents::Place(place) = var_debug_info.value {
161162
if let Some(local) = place.as_local() {
162-
if let Some(prev_name) = local_names[local] {
163-
if var_debug_info.name != prev_name {
164-
span_bug!(
165-
var_debug_info.source_info.span,
166-
"local {:?} has many names (`{}` vs `{}`)",
167-
local,
168-
prev_name,
169-
var_debug_info.name
170-
);
171-
}
163+
if let Some(prev_name) = local_names[local] && var_debug_info.name != prev_name {
164+
span_bug!(
165+
var_debug_info.source_info.span,
166+
"local {:?} has many names (`{}` vs `{}`)",
167+
local,
168+
prev_name,
169+
var_debug_info.name
170+
);
172171
}
173172
local_names[local] = Some(var_debug_info.name);
174173
}

compiler/rustc_borrowck/src/places_conflict.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,8 @@ pub(super) fn borrow_conflicts_with_place<'tcx>(
6060

6161
// This Local/Local case is handled by the more general code below, but
6262
// it's so common that it's a speed win to check for it first.
63-
if let Some(l1) = borrow_place.as_local() {
64-
if let Some(l2) = access_place.as_local() {
65-
return l1 == l2;
66-
}
63+
if let Some(l1) = borrow_place.as_local() && let Some(l2) = access_place.as_local() {
64+
return l1 == l2;
6765
}
6866

6967
place_components_conflict(tcx, body, borrow_place, borrow_kind, access_place, access, bias)

0 commit comments

Comments
 (0)