Skip to content

Commit c75817f

Browse files
committed
rustc_borrowck: remove ref patterns
1 parent c5351ad commit c75817f

File tree

13 files changed

+145
-160
lines changed

13 files changed

+145
-160
lines changed

compiler/rustc_borrowck/src/borrow_set.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'tcx> {
198198
rvalue: &mir::Rvalue<'tcx>,
199199
location: mir::Location,
200200
) {
201-
if let mir::Rvalue::Ref(region, kind, ref borrowed_place) = *rvalue {
201+
if let &mir::Rvalue::Ref(region, kind, borrowed_place) = rvalue {
202202
if borrowed_place.ignore_borrow(self.tcx, self.body, &self.locals_state_at_exit) {
203203
debug!("ignoring_borrow of {:?}", borrowed_place);
204204
return;
@@ -211,7 +211,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'tcx> {
211211
region,
212212
reserve_location: location,
213213
activation_location: TwoPhaseActivation::NotTwoPhase,
214-
borrowed_place: *borrowed_place,
214+
borrowed_place,
215215
assigned_place: *assigned_place,
216216
};
217217
let (idx, _) = self.location_map.insert_full(location, borrow);
@@ -273,14 +273,14 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'tcx> {
273273
}
274274

275275
fn visit_rvalue(&mut self, rvalue: &mir::Rvalue<'tcx>, location: mir::Location) {
276-
if let mir::Rvalue::Ref(region, kind, ref place) = *rvalue {
276+
if let &mir::Rvalue::Ref(region, kind, place) = rvalue {
277277
// double-check that we already registered a BorrowData for this
278278

279279
let borrow_data = &self.location_map[&location];
280280
assert_eq!(borrow_data.reserve_location, location);
281281
assert_eq!(borrow_data.kind, kind);
282282
assert_eq!(borrow_data.region, region.to_region_vid());
283-
assert_eq!(borrow_data.borrowed_place, *place);
283+
assert_eq!(borrow_data.borrowed_place, place);
284284
}
285285

286286
self.super_rvalue(rvalue, location)

compiler/rustc_borrowck/src/dataflow.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,9 @@ impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
358358
stmt: &mir::Statement<'tcx>,
359359
location: Location,
360360
) {
361-
match stmt.kind {
362-
mir::StatementKind::Assign(box (lhs, ref rhs)) => {
363-
if let mir::Rvalue::Ref(_, _, place) = *rhs {
361+
match &stmt.kind {
362+
mir::StatementKind::Assign(box (lhs, rhs)) => {
363+
if let mir::Rvalue::Ref(_, _, place) = rhs {
364364
if place.ignore_borrow(
365365
self.tcx,
366366
self.body,
@@ -377,13 +377,13 @@ impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
377377

378378
// Make sure there are no remaining borrows for variables
379379
// that are assigned over.
380-
self.kill_borrows_on_place(trans, lhs);
380+
self.kill_borrows_on_place(trans, *lhs);
381381
}
382382

383383
mir::StatementKind::StorageDead(local) => {
384384
// Make sure there are no remaining borrows for locals that
385385
// are gone out of scope.
386-
self.kill_borrows_on_place(trans, Place::from(local));
386+
self.kill_borrows_on_place(trans, Place::from(*local));
387387
}
388388

389389
mir::StatementKind::FakeRead(..)

compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@ impl<'tcx> TypeOpInfo<'tcx> for PredicateQuery<'tcx> {
243243
placeholder_region: ty::Region<'tcx>,
244244
error_region: Option<ty::Region<'tcx>>,
245245
) -> Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>> {
246-
let (ref infcx, key, _) =
246+
let (infcx, key, _) =
247247
mbcx.infcx.tcx.infer_ctxt().build_with_canonical(cause.span, &self.canonical_query);
248-
let ocx = ObligationCtxt::new(infcx);
248+
let ocx = ObligationCtxt::new(&infcx);
249249
type_op_prove_predicate_with_cause(&ocx, key, cause);
250250
try_extract_error_from_fulfill_cx(&ocx, placeholder_region, error_region)
251251
}
@@ -284,9 +284,9 @@ where
284284
placeholder_region: ty::Region<'tcx>,
285285
error_region: Option<ty::Region<'tcx>>,
286286
) -> Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>> {
287-
let (ref infcx, key, _) =
287+
let (infcx, key, _) =
288288
mbcx.infcx.tcx.infer_ctxt().build_with_canonical(cause.span, &self.canonical_query);
289-
let ocx = ObligationCtxt::new(infcx);
289+
let ocx = ObligationCtxt::new(&infcx);
290290

291291
// FIXME(lqd): Unify and de-duplicate the following with the actual
292292
// `rustc_traits::type_op::type_op_normalize` query to allow the span we need in the
@@ -328,9 +328,9 @@ impl<'tcx> TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> {
328328
placeholder_region: ty::Region<'tcx>,
329329
error_region: Option<ty::Region<'tcx>>,
330330
) -> Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>> {
331-
let (ref infcx, key, _) =
331+
let (infcx, key, _) =
332332
mbcx.infcx.tcx.infer_ctxt().build_with_canonical(cause.span, &self.canonical_query);
333-
let ocx = ObligationCtxt::new(infcx);
333+
let ocx = ObligationCtxt::new(&infcx);
334334
type_op_ascribe_user_type_with_span(&ocx, key, Some(cause.span)).ok()?;
335335
try_extract_error_from_fulfill_cx(&ocx, placeholder_region, error_region)
336336
}

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
265265
DescribePlaceOpt { including_downcast: true, including_tuple_field: true },
266266
);
267267
let note_msg = match opt_name {
268-
Some(ref name) => format!("`{}`", name),
268+
Some(name) => format!("`{}`", name),
269269
None => "value".to_owned(),
270270
};
271271
if self.suggest_borrow_fn_like(&mut err, ty, &move_site_vec, &note_msg) {
@@ -1417,7 +1417,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
14171417
// then just use the normal error. The closure isn't escaping
14181418
// and `move` will not help here.
14191419
(
1420-
Some(ref name),
1420+
Some(name),
14211421
BorrowExplanation::MustBeValidFor {
14221422
category:
14231423
category @ (ConstraintCategory::Return(_)
@@ -1438,7 +1438,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
14381438
&format!("`{}`", name),
14391439
),
14401440
(
1441-
ref name,
1441+
name,
14421442
BorrowExplanation::MustBeValidFor {
14431443
category: ConstraintCategory::Assignment,
14441444
from_closure: false,
@@ -1450,7 +1450,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
14501450
span,
14511451
..
14521452
},
1453-
) => self.report_escaping_data(borrow_span, name, upvar_span, upvar_name, span),
1453+
) => self.report_escaping_data(borrow_span, &name, upvar_span, upvar_name, span),
14541454
(Some(name), explanation) => self.report_local_value_does_not_live_long_enough(
14551455
location,
14561456
&name,
@@ -2452,7 +2452,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
24522452
// and it'll make sense.
24532453
let location = borrow.reserve_location;
24542454
debug!("annotate_argument_and_return_for_borrow: location={:?}", location);
2455-
if let Some(&Statement { kind: StatementKind::Assign(box (ref reservation, _)), .. }) =
2455+
if let Some(Statement { kind: StatementKind::Assign(box (reservation, _)), .. }) =
24562456
&self.body[location.block].statements.get(location.statement_index)
24572457
{
24582458
debug!("annotate_argument_and_return_for_borrow: reservation={:?}", reservation);
@@ -2480,8 +2480,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
24802480
// Check if our `target` was captured by a closure.
24812481
if let Rvalue::Aggregate(
24822482
box AggregateKind::Closure(def_id, substs),
2483-
ref operands,
2484-
) = *rvalue
2483+
operands,
2484+
) = rvalue
24852485
{
24862486
for operand in operands {
24872487
let (Operand::Copy(assigned_from) | Operand::Move(assigned_from)) = operand else {
@@ -2505,7 +2505,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
25052505
// into a place then we should annotate the closure in
25062506
// case it ends up being assigned into the return place.
25072507
annotated_closure =
2508-
self.annotate_fn_sig(def_id, substs.as_closure().sig());
2508+
self.annotate_fn_sig(*def_id, substs.as_closure().sig());
25092509
debug!(
25102510
"annotate_argument_and_return_for_borrow: \
25112511
annotated_closure={:?} assigned_from_local={:?} \

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
469469
} else if self.was_captured_by_trait_object(borrow) {
470470
LaterUseKind::TraitCapture
471471
} else if location.statement_index == block.statements.len() {
472-
if let TerminatorKind::Call { ref func, from_hir_call: true, .. } =
473-
block.terminator().kind
472+
if let TerminatorKind::Call { func, from_hir_call: true, .. } =
473+
&block.terminator().kind
474474
{
475475
// Just point to the function, to reduce the chance of overlapping spans.
476476
let function_span = match func {
@@ -515,19 +515,16 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
515515
// will only ever have one item at any given time, but by using a vector, we can pop from
516516
// it which simplifies the termination logic.
517517
let mut queue = vec![location];
518-
let mut target = if let Some(&Statement {
519-
kind: StatementKind::Assign(box (ref place, _)),
520-
..
521-
}) = stmt
522-
{
523-
if let Some(local) = place.as_local() {
524-
local
518+
let mut target =
519+
if let Some(Statement { kind: StatementKind::Assign(box (place, _)), .. }) = stmt {
520+
if let Some(local) = place.as_local() {
521+
local
522+
} else {
523+
return false;
524+
}
525525
} else {
526526
return false;
527-
}
528-
} else {
529-
return false;
530-
};
527+
};
531528

532529
debug!("was_captured_by_trait: target={:?} queue={:?}", target, queue);
533530
while let Some(current_location) = queue.pop() {

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
7878
if let StatementKind::Assign(box (into, Rvalue::Use(from))) = &stmt.kind {
7979
debug!("add_fnonce_closure_note: into={:?} from={:?}", into, from);
8080
match from {
81-
Operand::Copy(ref place) | Operand::Move(ref place)
81+
Operand::Copy(place) | Operand::Move(place)
8282
if target == place.local_or_deref_local() =>
8383
{
8484
target = into.local_or_deref_local()
@@ -101,7 +101,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
101101
debug!("add_moved_or_invoked_closure_note: id={:?}", id);
102102
if Some(self.infcx.tcx.parent(id)) == self.infcx.tcx.lang_items().fn_once_trait() {
103103
let closure = match args.first() {
104-
Some(Operand::Copy(ref place)) | Some(Operand::Move(ref place))
104+
Some(Operand::Copy(place) | Operand::Move(place))
105105
if target == place.local_or_deref_local() =>
106106
{
107107
place.local_or_deref_local().unwrap()
@@ -439,9 +439,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
439439
if !is_terminator {
440440
continue;
441441
} else if let Some(Terminator {
442-
kind: TerminatorKind::Call { ref func, from_hir_call: false, .. },
442+
kind: TerminatorKind::Call { func, from_hir_call: false, .. },
443443
..
444-
}) = bbd.terminator
444+
}) = &bbd.terminator
445445
{
446446
if let Some(source) =
447447
BorrowedContentSource::from_call(func.ty(self.body, tcx), tcx)
@@ -811,33 +811,30 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
811811
};
812812

813813
debug!("move_spans: moved_place={:?} location={:?} stmt={:?}", moved_place, location, stmt);
814-
if let StatementKind::Assign(box (_, Rvalue::Aggregate(ref kind, ref places))) = stmt.kind {
815-
match **kind {
816-
AggregateKind::Closure(def_id, _) | AggregateKind::Generator(def_id, _, _) => {
817-
debug!("move_spans: def_id={:?} places={:?}", def_id, places);
818-
if let Some((args_span, generator_kind, capture_kind_span, path_span)) =
819-
self.closure_span(def_id, moved_place, places)
820-
{
821-
return ClosureUse {
822-
generator_kind,
823-
args_span,
824-
capture_kind_span,
825-
path_span,
826-
};
827-
}
828-
}
829-
_ => {}
814+
if let StatementKind::Assign(box (_, Rvalue::Aggregate(kind, places))) = &stmt.kind
815+
&& let AggregateKind::Closure(def_id, _) | AggregateKind::Generator(def_id, _, _) = **kind
816+
{
817+
debug!("move_spans: def_id={:?} places={:?}", def_id, places);
818+
if let Some((args_span, generator_kind, capture_kind_span, path_span)) =
819+
self.closure_span(def_id, moved_place, places)
820+
{
821+
return ClosureUse {
822+
generator_kind,
823+
args_span,
824+
capture_kind_span,
825+
path_span,
826+
};
830827
}
831828
}
832829

833830
// StatementKind::FakeRead only contains a def_id if they are introduced as a result
834831
// of pattern matching within a closure.
835-
if let StatementKind::FakeRead(box (cause, ref place)) = stmt.kind {
832+
if let StatementKind::FakeRead(box (cause, place)) = stmt.kind {
836833
match cause {
837834
FakeReadCause::ForMatchedPlace(Some(closure_def_id))
838835
| FakeReadCause::ForLet(Some(closure_def_id)) => {
839836
debug!("move_spans: def_id={:?} place={:?}", closure_def_id, place);
840-
let places = &[Operand::Move(*place)];
837+
let places = &[Operand::Move(place)];
841838
if let Some((args_span, generator_kind, capture_kind_span, path_span)) =
842839
self.closure_span(closure_def_id, moved_place, places)
843840
{
@@ -924,7 +921,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
924921
debug!("borrow_spans: use_span={:?} location={:?}", use_span, location);
925922

926923
let target = match self.body[location.block].statements.get(location.statement_index) {
927-
Some(&Statement { kind: StatementKind::Assign(box (ref place, _)), .. }) => {
924+
Some(Statement { kind: StatementKind::Assign(box (place, _)), .. }) => {
928925
if let Some(local) = place.as_local() {
929926
local
930927
} else {
@@ -940,9 +937,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
940937
}
941938

942939
for stmt in &self.body[location.block].statements[location.statement_index + 1..] {
943-
if let StatementKind::Assign(box (_, Rvalue::Aggregate(ref kind, ref places))) =
944-
stmt.kind
945-
{
940+
if let StatementKind::Assign(box (_, Rvalue::Aggregate(kind, places))) = &stmt.kind {
946941
let (&def_id, is_generator) = match kind {
947942
box AggregateKind::Closure(def_id, _) => (def_id, false),
948943
box AggregateKind::Generator(def_id, _, _) => (def_id, true),

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
219219
PlaceRef {
220220
local,
221221
projection:
222-
&[
223-
ref proj_base @ ..,
222+
[
223+
proj_base @ ..,
224224
ProjectionElem::Deref,
225225
ProjectionElem::Field(field, _),
226226
ProjectionElem::Deref,
@@ -231,7 +231,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
231231
if let Some(span) = get_mut_span_in_struct_field(
232232
self.infcx.tcx,
233233
Place::ty_from(local, proj_base, self.body, self.infcx.tcx).ty,
234-
field,
234+
*field,
235235
) {
236236
err.span_suggestion_verbose(
237237
span,

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
921921
}
922922
}
923923
hir::ExprKind::Block(blk, _) => {
924-
if let Some(ref expr) = blk.expr {
924+
if let Some(expr) = blk.expr {
925925
// only when the block is a closure
926926
if let hir::ExprKind::Closure(hir::Closure {
927927
capture_clause: hir::CaptureBy::Ref,

compiler/rustc_borrowck/src/diagnostics/region_name.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
254254
.or_else(|| self.give_name_if_anonymous_region_appears_in_impl_signature(fr))
255255
.or_else(|| self.give_name_if_anonymous_region_appears_in_arg_position_impl_trait(fr));
256256

257-
if let Some(ref value) = value {
257+
if let Some(value) = &value {
258258
self.region_names.try_borrow_mut().unwrap().insert(fr, value.clone());
259259
}
260260

0 commit comments

Comments
 (0)