Skip to content

Commit 52cec8c

Browse files
authored
Rollup merge of #105368 - WaffleLapkin:deref-even-harder, r=TaKO8Ki
Remove more `ref` patterns from the compiler Previous PR: #105045
2 parents 95da525 + 700c095 commit 52cec8c

30 files changed

+390
-421
lines changed

compiler/rustc_attr/src/builtin.rs

+69-65
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,7 @@ where
277277
allowed_through_unstable_modules = true;
278278
}
279279
// attributes with data
280-
else if let Some(MetaItem { kind: MetaItemKind::List(ref metas), .. }) = meta {
281-
let meta = meta.as_ref().unwrap();
280+
else if let Some(meta @ MetaItem { kind: MetaItemKind::List(metas), .. }) = &meta {
282281
let get = |meta: &MetaItem, item: &mut Option<Symbol>| {
283282
if item.is_some() {
284283
handle_errors(
@@ -533,25 +532,24 @@ where
533532

534533
// Merge the const-unstable info into the stability info
535534
if promotable {
536-
if let Some((ref mut stab, _)) = const_stab {
537-
stab.promotable = promotable;
538-
} else {
539-
sess.emit_err(session_diagnostics::RustcPromotablePairing { span: item_sp });
535+
match &mut const_stab {
536+
Some((stab, _)) => stab.promotable = promotable,
537+
_ => _ = sess.emit_err(session_diagnostics::RustcPromotablePairing { span: item_sp }),
540538
}
541539
}
542540

543541
if allowed_through_unstable_modules {
544-
if let Some((
545-
Stability {
546-
level: StabilityLevel::Stable { ref mut allowed_through_unstable_modules, .. },
547-
..
548-
},
549-
_,
550-
)) = stab
551-
{
552-
*allowed_through_unstable_modules = true;
553-
} else {
554-
sess.emit_err(session_diagnostics::RustcAllowedUnstablePairing { span: item_sp });
542+
match &mut stab {
543+
Some((
544+
Stability {
545+
level: StabilityLevel::Stable { allowed_through_unstable_modules, .. },
546+
..
547+
},
548+
_,
549+
)) => *allowed_through_unstable_modules = true,
550+
_ => {
551+
sess.emit_err(session_diagnostics::RustcAllowedUnstablePairing { span: item_sp });
552+
}
555553
}
556554
}
557555

@@ -654,8 +652,8 @@ pub fn eval_condition(
654652
features: Option<&Features>,
655653
eval: &mut impl FnMut(Condition) -> bool,
656654
) -> bool {
657-
match cfg.kind {
658-
ast::MetaItemKind::List(ref mis) if cfg.name_or_empty() == sym::version => {
655+
match &cfg.kind {
656+
ast::MetaItemKind::List(mis) if cfg.name_or_empty() == sym::version => {
659657
try_gate_cfg(sym::version, cfg.span, sess, features);
660658
let (min_version, span) = match &mis[..] {
661659
[NestedMetaItem::Lit(MetaItemLit { kind: LitKind::Str(sym, ..), span, .. })] => {
@@ -688,7 +686,7 @@ pub fn eval_condition(
688686
rustc_version >= min_version
689687
}
690688
}
691-
ast::MetaItemKind::List(ref mis) => {
689+
ast::MetaItemKind::List(mis) => {
692690
for mi in mis.iter() {
693691
if !mi.is_meta_item() {
694692
handle_errors(
@@ -759,7 +757,7 @@ pub fn eval_condition(
759757
sess.emit_err(session_diagnostics::CfgPredicateIdentifier { span: cfg.path.span });
760758
true
761759
}
762-
MetaItemKind::NameValue(ref lit) if !lit.kind.is_str() => {
760+
MetaItemKind::NameValue(lit) if !lit.kind.is_str() => {
763761
handle_errors(
764762
sess,
765763
lit.span,
@@ -1036,52 +1034,58 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
10361034
});
10371035
}
10381036
} else if let Some(meta_item) = item.meta_item() {
1039-
if let MetaItemKind::NameValue(ref value) = meta_item.kind {
1040-
if meta_item.has_name(sym::align) || meta_item.has_name(sym::packed) {
1041-
let name = meta_item.name_or_empty().to_ident_string();
1042-
recognised = true;
1043-
sess.emit_err(session_diagnostics::IncorrectReprFormatGeneric {
1044-
span: item.span(),
1045-
repr_arg: &name,
1046-
cause: IncorrectReprFormatGenericCause::from_lit_kind(
1047-
item.span(),
1048-
&value.kind,
1049-
&name,
1050-
),
1051-
});
1052-
} else if matches!(
1053-
meta_item.name_or_empty(),
1054-
sym::C | sym::simd | sym::transparent
1055-
) || int_type_of_word(meta_item.name_or_empty()).is_some()
1056-
{
1057-
recognised = true;
1058-
sess.emit_err(session_diagnostics::InvalidReprHintNoValue {
1059-
span: meta_item.span,
1060-
name: meta_item.name_or_empty().to_ident_string(),
1061-
});
1037+
match &meta_item.kind {
1038+
MetaItemKind::NameValue(value) => {
1039+
if meta_item.has_name(sym::align) || meta_item.has_name(sym::packed) {
1040+
let name = meta_item.name_or_empty().to_ident_string();
1041+
recognised = true;
1042+
sess.emit_err(session_diagnostics::IncorrectReprFormatGeneric {
1043+
span: item.span(),
1044+
repr_arg: &name,
1045+
cause: IncorrectReprFormatGenericCause::from_lit_kind(
1046+
item.span(),
1047+
&value.kind,
1048+
&name,
1049+
),
1050+
});
1051+
} else if matches!(
1052+
meta_item.name_or_empty(),
1053+
sym::C | sym::simd | sym::transparent
1054+
) || int_type_of_word(meta_item.name_or_empty()).is_some()
1055+
{
1056+
recognised = true;
1057+
sess.emit_err(session_diagnostics::InvalidReprHintNoValue {
1058+
span: meta_item.span,
1059+
name: meta_item.name_or_empty().to_ident_string(),
1060+
});
1061+
}
10621062
}
1063-
} else if let MetaItemKind::List(_) = meta_item.kind {
1064-
if meta_item.has_name(sym::align) {
1065-
recognised = true;
1066-
sess.emit_err(session_diagnostics::IncorrectReprFormatAlignOneArg {
1067-
span: meta_item.span,
1068-
});
1069-
} else if meta_item.has_name(sym::packed) {
1070-
recognised = true;
1071-
sess.emit_err(session_diagnostics::IncorrectReprFormatPackedOneOrZeroArg {
1072-
span: meta_item.span,
1073-
});
1074-
} else if matches!(
1075-
meta_item.name_or_empty(),
1076-
sym::C | sym::simd | sym::transparent
1077-
) || int_type_of_word(meta_item.name_or_empty()).is_some()
1078-
{
1079-
recognised = true;
1080-
sess.emit_err(session_diagnostics::InvalidReprHintNoParen {
1081-
span: meta_item.span,
1082-
name: meta_item.name_or_empty().to_ident_string(),
1083-
});
1063+
MetaItemKind::List(_) => {
1064+
if meta_item.has_name(sym::align) {
1065+
recognised = true;
1066+
sess.emit_err(session_diagnostics::IncorrectReprFormatAlignOneArg {
1067+
span: meta_item.span,
1068+
});
1069+
} else if meta_item.has_name(sym::packed) {
1070+
recognised = true;
1071+
sess.emit_err(
1072+
session_diagnostics::IncorrectReprFormatPackedOneOrZeroArg {
1073+
span: meta_item.span,
1074+
},
1075+
);
1076+
} else if matches!(
1077+
meta_item.name_or_empty(),
1078+
sym::C | sym::simd | sym::transparent
1079+
) || int_type_of_word(meta_item.name_or_empty()).is_some()
1080+
{
1081+
recognised = true;
1082+
sess.emit_err(session_diagnostics::InvalidReprHintNoParen {
1083+
span: meta_item.span,
1084+
name: meta_item.name_or_empty().to_ident_string(),
1085+
});
1086+
}
10841087
}
1088+
_ => (),
10851089
}
10861090
}
10871091
if !recognised {

compiler/rustc_borrowck/src/borrow_set.rs

+4-4
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

+5-5
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

+6-6
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

+8-8
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

+10-13
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() {

0 commit comments

Comments
 (0)