Skip to content

Commit 09485ea

Browse files
committed
rustc_hir_analysis: remove ref patterns
1 parent d60e772 commit 09485ea

19 files changed

+161
-168
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -569,17 +569,17 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
569569
.bindings
570570
.iter()
571571
.map(|binding| {
572-
let kind = match binding.kind {
573-
hir::TypeBindingKind::Equality { ref term } => match term {
574-
hir::Term::Ty(ref ty) => {
572+
let kind = match &binding.kind {
573+
hir::TypeBindingKind::Equality { term } => match term {
574+
hir::Term::Ty(ty) => {
575575
ConvertedBindingKind::Equality(self.ast_ty_to_ty(ty).into())
576576
}
577-
hir::Term::Const(ref c) => {
577+
hir::Term::Const(c) => {
578578
let c = Const::from_anon_const(self.tcx(), c.def_id);
579579
ConvertedBindingKind::Equality(c.into())
580580
}
581581
},
582-
hir::TypeBindingKind::Constraint { ref bounds } => {
582+
hir::TypeBindingKind::Constraint { bounds } => {
583583
ConvertedBindingKind::Constraint(bounds)
584584
}
585585
};
@@ -1928,7 +1928,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
19281928
) -> Result<(Ty<'tcx>, DefKind, DefId), ErrorGuaranteed> {
19291929
let tcx = self.tcx();
19301930
let assoc_ident = assoc_segment.ident;
1931-
let qself_res = if let hir::TyKind::Path(hir::QPath::Resolved(_, ref path)) = qself.kind {
1931+
let qself_res = if let hir::TyKind::Path(hir::QPath::Resolved(_, path)) = &qself.kind {
19321932
path.res
19331933
} else {
19341934
Res::Err
@@ -1971,8 +1971,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
19711971
return;
19721972
};
19731973
let (qself_sugg_span, is_self) = if let hir::TyKind::Path(
1974-
hir::QPath::Resolved(_, ref path)
1975-
) = qself.kind {
1974+
hir::QPath::Resolved(_, path)
1975+
) = &qself.kind {
19761976
// If the path segment already has type params, we want to overwrite
19771977
// them.
19781978
match &path.segments[..] {
@@ -2760,7 +2760,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
27602760
"generic `Self` types are currently not permitted in anonymous constants",
27612761
);
27622762
if let Some(hir::Node::Item(&hir::Item {
2763-
kind: hir::ItemKind::Impl(ref impl_),
2763+
kind: hir::ItemKind::Impl(impl_),
27642764
..
27652765
})) = tcx.hir().get_if_local(def_id)
27662766
{
@@ -2843,12 +2843,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
28432843
fn ast_ty_to_ty_inner(&self, ast_ty: &hir::Ty<'_>, borrowed: bool, in_path: bool) -> Ty<'tcx> {
28442844
let tcx = self.tcx();
28452845

2846-
let result_ty = match ast_ty.kind {
2847-
hir::TyKind::Slice(ref ty) => tcx.mk_slice(self.ast_ty_to_ty(ty)),
2848-
hir::TyKind::Ptr(ref mt) => {
2846+
let result_ty = match &ast_ty.kind {
2847+
hir::TyKind::Slice(ty) => tcx.mk_slice(self.ast_ty_to_ty(ty)),
2848+
hir::TyKind::Ptr(mt) => {
28492849
tcx.mk_ptr(ty::TypeAndMut { ty: self.ast_ty_to_ty(mt.ty), mutbl: mt.mutbl })
28502850
}
2851-
hir::TyKind::Ref(ref region, ref mt) => {
2851+
hir::TyKind::Ref(region, mt) => {
28522852
let r = self.ast_region_to_region(region, None);
28532853
debug!(?r);
28542854
let t = self.ast_ty_to_ty_inner(mt.ty, true, false);
@@ -2868,38 +2868,38 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
28682868
Some(ast_ty),
28692869
))
28702870
}
2871-
hir::TyKind::TraitObject(bounds, ref lifetime, repr) => {
2871+
hir::TyKind::TraitObject(bounds, lifetime, repr) => {
28722872
self.maybe_lint_bare_trait(ast_ty, in_path);
28732873
let repr = match repr {
28742874
TraitObjectSyntax::Dyn | TraitObjectSyntax::None => ty::Dyn,
28752875
TraitObjectSyntax::DynStar => ty::DynStar,
28762876
};
28772877
self.conv_object_ty_poly_trait_ref(ast_ty.span, bounds, lifetime, borrowed, repr)
28782878
}
2879-
hir::TyKind::Path(hir::QPath::Resolved(ref maybe_qself, ref path)) => {
2879+
hir::TyKind::Path(hir::QPath::Resolved(maybe_qself, path)) => {
28802880
debug!(?maybe_qself, ?path);
28812881
let opt_self_ty = maybe_qself.as_ref().map(|qself| self.ast_ty_to_ty(qself));
28822882
self.res_to_ty(opt_self_ty, path, false)
28832883
}
28842884
hir::TyKind::OpaqueDef(item_id, lifetimes, in_trait) => {
2885-
let opaque_ty = tcx.hir().item(item_id);
2885+
let opaque_ty = tcx.hir().item(*item_id);
28862886
let def_id = item_id.owner_id.to_def_id();
28872887

28882888
match opaque_ty.kind {
28892889
hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) => {
2890-
self.impl_trait_ty_to_ty(def_id, lifetimes, origin, in_trait)
2890+
self.impl_trait_ty_to_ty(def_id, lifetimes, origin, *in_trait)
28912891
}
28922892
ref i => bug!("`impl Trait` pointed to non-opaque type?? {:#?}", i),
28932893
}
28942894
}
2895-
hir::TyKind::Path(hir::QPath::TypeRelative(ref qself, ref segment)) => {
2895+
hir::TyKind::Path(hir::QPath::TypeRelative(qself, segment)) => {
28962896
debug!(?qself, ?segment);
28972897
let ty = self.ast_ty_to_ty_inner(qself, false, true);
28982898
self.associated_path_to_ty(ast_ty.hir_id, ast_ty.span, ty, qself, segment, false)
28992899
.map(|(ty, _, _)| ty)
29002900
.unwrap_or_else(|_| tcx.ty_error())
29012901
}
2902-
hir::TyKind::Path(hir::QPath::LangItem(lang_item, span, _)) => {
2902+
&hir::TyKind::Path(hir::QPath::LangItem(lang_item, span, _)) => {
29032903
let def_id = tcx.require_lang_item(lang_item, Some(span));
29042904
let (substs, _) = self.create_substs_for_ast_path(
29052905
span,
@@ -2913,7 +2913,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
29132913
);
29142914
EarlyBinder(tcx.at(span).type_of(def_id)).subst(tcx, substs)
29152915
}
2916-
hir::TyKind::Array(ref ty, ref length) => {
2916+
hir::TyKind::Array(ty, length) => {
29172917
let length = match length {
29182918
&hir::ArrayLen::Infer(_, span) => self.ct_infer(tcx.types.usize, None, span),
29192919
hir::ArrayLen::Body(constant) => {
@@ -2923,7 +2923,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
29232923

29242924
tcx.mk_ty(ty::Array(self.ast_ty_to_ty(ty), length))
29252925
}
2926-
hir::TyKind::Typeof(ref e) => {
2926+
hir::TyKind::Typeof(e) => {
29272927
let ty_erased = tcx.type_of(e.def_id);
29282928
let ty = tcx.fold_regions(ty_erased, |r, _| {
29292929
if r.is_erased() { tcx.lifetimes.re_static } else { r }

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
531531
DefKind::Fn => {} // entirely within check_item_body
532532
DefKind::Impl => {
533533
let it = tcx.hir().item(id);
534-
let hir::ItemKind::Impl(ref impl_) = it.kind else {
535-
return;
536-
};
534+
let hir::ItemKind::Impl(impl_) = it.kind else { return };
537535
debug!("ItemKind::Impl {} with id {:?}", it.ident, it.owner_id);
538536
if let Some(impl_trait_ref) = tcx.impl_trait_ref(it.owner_id) {
539537
check_impl_items_against_trait(
@@ -548,15 +546,15 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
548546
}
549547
DefKind::Trait => {
550548
let it = tcx.hir().item(id);
551-
let hir::ItemKind::Trait(_, _, _, _, ref items) = it.kind else {
549+
let hir::ItemKind::Trait(_, _, _, _, items) = it.kind else {
552550
return;
553551
};
554552
check_on_unimplemented(tcx, it);
555553

556554
for item in items.iter() {
557555
let item = tcx.hir().trait_item(item.id);
558-
match item.kind {
559-
hir::TraitItemKind::Fn(ref sig, _) => {
556+
match &item.kind {
557+
hir::TraitItemKind::Fn(sig, _) => {
560558
let abi = sig.header.abi;
561559
fn_maybe_err(tcx, item.ident.span, abi);
562560
}
@@ -652,8 +650,8 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
652650
}
653651

654652
let item = tcx.hir().foreign_item(item.id);
655-
match item.kind {
656-
hir::ForeignItemKind::Fn(ref fn_decl, _, _) => {
653+
match &item.kind {
654+
hir::ForeignItemKind::Fn(fn_decl, _, _) => {
657655
require_c_abi_if_c_variadic(tcx, fn_decl, abi, item.span);
658656
}
659657
hir::ForeignItemKind::Static(..) => {

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,8 +1513,7 @@ fn compare_synthetic_generics<'tcx>(
15131513
impl<'v> intravisit::Visitor<'v> for Visitor {
15141514
fn visit_ty(&mut self, ty: &'v hir::Ty<'v>) {
15151515
intravisit::walk_ty(self, ty);
1516-
if let hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) =
1517-
ty.kind
1516+
if let hir::TyKind::Path(hir::QPath::Resolved(None, path)) = ty.kind
15181517
&& let Res::Def(DefKind::TyParam, def_id) = path.res
15191518
&& def_id == self.1.to_def_id()
15201519
{

compiler/rustc_hir_analysis/src/check/intrinsicck.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
351351
}
352352

353353
match *op {
354-
hir::InlineAsmOperand::In { reg, ref expr } => {
354+
hir::InlineAsmOperand::In { reg, expr } => {
355355
self.check_asm_operand_type(
356356
idx,
357357
reg,
@@ -362,7 +362,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
362362
&target_features,
363363
);
364364
}
365-
hir::InlineAsmOperand::Out { reg, late: _, ref expr } => {
365+
hir::InlineAsmOperand::Out { reg, late: _, expr } => {
366366
if let Some(expr) = expr {
367367
self.check_asm_operand_type(
368368
idx,
@@ -375,7 +375,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
375375
);
376376
}
377377
}
378-
hir::InlineAsmOperand::InOut { reg, late: _, ref expr } => {
378+
hir::InlineAsmOperand::InOut { reg, late: _, expr } => {
379379
self.check_asm_operand_type(
380380
idx,
381381
reg,
@@ -386,7 +386,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
386386
&target_features,
387387
);
388388
}
389-
hir::InlineAsmOperand::SplitInOut { reg, late: _, ref in_expr, ref out_expr } => {
389+
hir::InlineAsmOperand::SplitInOut { reg, late: _, in_expr, out_expr } => {
390390
let in_ty = self.check_asm_operand_type(
391391
idx,
392392
reg,

compiler/rustc_hir_analysis/src/check/region.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ fn resolve_arm<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, arm: &'tcx hir
180180

181181
visitor.terminating_scopes.insert(arm.body.hir_id.local_id);
182182

183-
if let Some(hir::Guard::If(ref expr)) = arm.guard {
183+
if let Some(hir::Guard::If(expr)) = arm.guard {
184184
visitor.terminating_scopes.insert(expr.hir_id.local_id);
185185
}
186186

@@ -242,8 +242,8 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
242242
// This ensures fixed size stacks.
243243
hir::ExprKind::Binary(
244244
source_map::Spanned { node: hir::BinOpKind::And | hir::BinOpKind::Or, .. },
245-
ref l,
246-
ref r,
245+
l,
246+
r,
247247
) => {
248248
// expr is a short circuiting operator (|| or &&). As its
249249
// functionality can't be overridden by traits, it always
@@ -288,20 +288,20 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
288288
terminating(r.hir_id.local_id);
289289
}
290290
}
291-
hir::ExprKind::If(_, ref then, Some(ref otherwise)) => {
291+
hir::ExprKind::If(_, then, Some(otherwise)) => {
292292
terminating(then.hir_id.local_id);
293293
terminating(otherwise.hir_id.local_id);
294294
}
295295

296-
hir::ExprKind::If(_, ref then, None) => {
296+
hir::ExprKind::If(_, then, None) => {
297297
terminating(then.hir_id.local_id);
298298
}
299299

300-
hir::ExprKind::Loop(ref body, _, _, _) => {
300+
hir::ExprKind::Loop(body, _, _, _) => {
301301
terminating(body.hir_id.local_id);
302302
}
303303

304-
hir::ExprKind::DropTemps(ref expr) => {
304+
hir::ExprKind::DropTemps(expr) => {
305305
// `DropTemps(expr)` does not denote a conditional scope.
306306
// Rather, we want to achieve the same behavior as `{ let _t = expr; _t }`.
307307
terminating(expr.hir_id.local_id);
@@ -396,7 +396,7 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
396396
let body = visitor.tcx.hir().body(body);
397397
visitor.visit_body(body);
398398
}
399-
hir::ExprKind::AssignOp(_, ref left_expr, ref right_expr) => {
399+
hir::ExprKind::AssignOp(_, left_expr, right_expr) => {
400400
debug!(
401401
"resolve_expr - enabling pessimistic_yield, was previously {}",
402402
prev_pessimistic
@@ -447,7 +447,7 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
447447
}
448448
}
449449

450-
hir::ExprKind::If(ref cond, ref then, Some(ref otherwise)) => {
450+
hir::ExprKind::If(cond, then, Some(otherwise)) => {
451451
let expr_cx = visitor.cx;
452452
visitor.enter_scope(Scope { id: then.hir_id.local_id, data: ScopeData::IfThen });
453453
visitor.cx.var_parent = visitor.cx.parent;
@@ -457,7 +457,7 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h
457457
visitor.visit_expr(otherwise);
458458
}
459459

460-
hir::ExprKind::If(ref cond, ref then, None) => {
460+
hir::ExprKind::If(cond, then, None) => {
461461
let expr_cx = visitor.cx;
462462
visitor.enter_scope(Scope { id: then.hir_id.local_id, data: ScopeData::IfThen });
463463
visitor.cx.var_parent = visitor.cx.parent;
@@ -641,21 +641,21 @@ fn resolve_local<'tcx>(
641641
match pat.kind {
642642
PatKind::Binding(hir::BindingAnnotation(hir::ByRef::Yes, _), ..) => true,
643643

644-
PatKind::Struct(_, ref field_pats, _) => {
644+
PatKind::Struct(_, field_pats, _) => {
645645
field_pats.iter().any(|fp| is_binding_pat(&fp.pat))
646646
}
647647

648-
PatKind::Slice(ref pats1, ref pats2, ref pats3) => {
648+
PatKind::Slice(pats1, pats2, pats3) => {
649649
pats1.iter().any(|p| is_binding_pat(&p))
650650
|| pats2.iter().any(|p| is_binding_pat(&p))
651651
|| pats3.iter().any(|p| is_binding_pat(&p))
652652
}
653653

654-
PatKind::Or(ref subpats)
655-
| PatKind::TupleStruct(_, ref subpats, _)
656-
| PatKind::Tuple(ref subpats, _) => subpats.iter().any(|p| is_binding_pat(&p)),
654+
PatKind::Or(subpats)
655+
| PatKind::TupleStruct(_, subpats, _)
656+
| PatKind::Tuple(subpats, _) => subpats.iter().any(|p| is_binding_pat(&p)),
657657

658-
PatKind::Box(ref subpat) => is_binding_pat(&subpat),
658+
PatKind::Box(subpat) => is_binding_pat(&subpat),
659659

660660
PatKind::Ref(_, _)
661661
| PatKind::Binding(hir::BindingAnnotation(hir::ByRef::No, _), ..)
@@ -704,11 +704,11 @@ fn resolve_local<'tcx>(
704704
record_rvalue_scope_if_borrow_expr(visitor, &subexpr, blk_id);
705705
}
706706
}
707-
hir::ExprKind::Cast(ref subexpr, _) => {
707+
hir::ExprKind::Cast(subexpr, _) => {
708708
record_rvalue_scope_if_borrow_expr(visitor, &subexpr, blk_id)
709709
}
710-
hir::ExprKind::Block(ref block, _) => {
711-
if let Some(ref subexpr) = block.expr {
710+
hir::ExprKind::Block(block, _) => {
711+
if let Some(subexpr) = block.expr {
712712
record_rvalue_scope_if_borrow_expr(visitor, &subexpr, blk_id);
713713
}
714714
}

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) {
178178
//
179179
// won't be allowed unless there's an *explicit* implementation of `Send`
180180
// for `T`
181-
hir::ItemKind::Impl(ref impl_) => {
181+
hir::ItemKind::Impl(impl_) => {
182182
let is_auto = tcx
183183
.impl_trait_ref(def_id)
184184
.map_or(false, |trait_ref| tcx.trait_is_auto(trait_ref.skip_binder().def_id));
@@ -224,15 +224,15 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) {
224224
hir::ItemKind::Const(ty, ..) => {
225225
check_item_type(tcx, def_id, ty.span, false);
226226
}
227-
hir::ItemKind::Struct(_, ref ast_generics) => {
227+
hir::ItemKind::Struct(_, ast_generics) => {
228228
check_type_defn(tcx, item, false);
229229
check_variances_for_type_defn(tcx, item, ast_generics);
230230
}
231-
hir::ItemKind::Union(_, ref ast_generics) => {
231+
hir::ItemKind::Union(_, ast_generics) => {
232232
check_type_defn(tcx, item, true);
233233
check_variances_for_type_defn(tcx, item, ast_generics);
234234
}
235-
hir::ItemKind::Enum(_, ref ast_generics) => {
235+
hir::ItemKind::Enum(_, ast_generics) => {
236236
check_type_defn(tcx, item, true);
237237
check_variances_for_type_defn(tcx, item, ast_generics);
238238
}
@@ -1247,8 +1247,8 @@ fn check_impl<'tcx>(
12471247
constness: hir::Constness,
12481248
) {
12491249
enter_wf_checking_ctxt(tcx, item.span, item.owner_id.def_id, |wfcx| {
1250-
match *ast_trait_ref {
1251-
Some(ref ast_trait_ref) => {
1250+
match ast_trait_ref {
1251+
Some(ast_trait_ref) => {
12521252
// `#[rustc_reservation_impl]` impls are not real impls and
12531253
// therefore don't need to be WF (the trait's `Self: Trait` predicate
12541254
// won't hold).

compiler/rustc_hir_analysis/src/coherence/builtin.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -502,12 +502,11 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn
502502
return err_info;
503503
} else if diff_fields.len() > 1 {
504504
let item = tcx.hir().expect_item(impl_did);
505-
let span =
506-
if let ItemKind::Impl(hir::Impl { of_trait: Some(ref t), .. }) = item.kind {
507-
t.path.span
508-
} else {
509-
tcx.def_span(impl_did)
510-
};
505+
let span = if let ItemKind::Impl(hir::Impl { of_trait: Some(t), .. }) = &item.kind {
506+
t.path.span
507+
} else {
508+
tcx.def_span(impl_did)
509+
};
511510

512511
struct_span_err!(
513512
tcx.sess,

compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl<'tcx> InherentCollect<'tcx> {
182182
}
183183

184184
let item = self.tcx.hir().item(id);
185-
let hir::ItemKind::Impl(hir::Impl { of_trait: None, self_ty: ty, ref items, .. }) = item.kind else {
185+
let hir::ItemKind::Impl(hir::Impl { of_trait: None, self_ty: ty, items, .. }) = item.kind else {
186186
return;
187187
};
188188

0 commit comments

Comments
 (0)