Skip to content

Commit 8a90626

Browse files
committed
reduce borrowing and (de)referencing around match patterns (clippy::match_ref_pats)
1 parent 90ccf4f commit 8a90626

File tree

28 files changed

+89
-91
lines changed

28 files changed

+89
-91
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,9 @@ pub enum WherePredicate {
433433
impl WherePredicate {
434434
pub fn span(&self) -> Span {
435435
match self {
436-
&WherePredicate::BoundPredicate(ref p) => p.span,
437-
&WherePredicate::RegionPredicate(ref p) => p.span,
438-
&WherePredicate::EqPredicate(ref p) => p.span,
436+
WherePredicate::BoundPredicate(p) => p.span,
437+
WherePredicate::RegionPredicate(p) => p.span,
438+
WherePredicate::EqPredicate(p) => p.span,
439439
}
440440
}
441441
}

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,11 +1212,11 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12121212
}
12131213

12141214
fn visit_pat(&mut self, pat: &'a Pat) {
1215-
match pat.kind {
1216-
PatKind::Lit(ref expr) => {
1215+
match &pat.kind {
1216+
PatKind::Lit(expr) => {
12171217
self.check_expr_within_pat(expr, false);
12181218
}
1219-
PatKind::Range(ref start, ref end, _) => {
1219+
PatKind::Range(start, end, _) => {
12201220
if let Some(expr) = start {
12211221
self.check_expr_within_pat(expr, true);
12221222
}

compiler/rustc_builtin_macros/src/deriving/hash.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ pub fn expand_deriving_hash(
4848
}
4949

5050
fn hash_substructure(cx: &mut ExtCtxt<'_>, trait_span: Span, substr: &Substructure<'_>) -> P<Expr> {
51-
let state_expr = match &substr.nonself_args {
52-
&[o_f] => o_f,
51+
let state_expr = match substr.nonself_args {
52+
[o_f] => o_f,
5353
_ => cx.span_bug(trait_span, "incorrect number of arguments in `derive(Hash)`"),
5454
};
5555
let call_hash = |span, thing_expr| {
@@ -64,9 +64,9 @@ fn hash_substructure(cx: &mut ExtCtxt<'_>, trait_span: Span, substr: &Substructu
6464
};
6565
let mut stmts = Vec::new();
6666

67-
let fields = match *substr.fields {
68-
Struct(_, ref fs) | EnumMatching(_, 1, .., ref fs) => fs,
69-
EnumMatching(.., ref fs) => {
67+
let fields = match substr.fields {
68+
Struct(_, fs) | EnumMatching(_, 1, .., fs) => fs,
69+
EnumMatching(.., fs) => {
7070
let variant_value = deriving::call_intrinsic(
7171
cx,
7272
trait_span,

compiler/rustc_hir/src/hir.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,9 @@ impl GenericBound<'_> {
378378

379379
pub fn span(&self) -> Span {
380380
match self {
381-
&GenericBound::Trait(ref t, ..) => t.span,
382-
&GenericBound::LangItemTrait(_, span, ..) => span,
383-
&GenericBound::Outlives(ref l) => l.span,
381+
GenericBound::Trait(t, ..) => t.span,
382+
GenericBound::LangItemTrait(_, span, ..) => *span,
383+
GenericBound::Outlives(l) => l.span,
384384
}
385385
}
386386
}
@@ -538,9 +538,9 @@ pub enum WherePredicate<'hir> {
538538
impl WherePredicate<'_> {
539539
pub fn span(&self) -> Span {
540540
match self {
541-
&WherePredicate::BoundPredicate(ref p) => p.span,
542-
&WherePredicate::RegionPredicate(ref p) => p.span,
543-
&WherePredicate::EqPredicate(ref p) => p.span,
541+
WherePredicate::BoundPredicate(p) => p.span,
542+
WherePredicate::RegionPredicate(p) => p.span,
543+
WherePredicate::EqPredicate(p) => p.span,
544544
}
545545
}
546546
}

compiler/rustc_hir/src/intravisit.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -896,8 +896,8 @@ pub fn walk_where_predicate<'v, V: Visitor<'v>>(
896896
visitor: &mut V,
897897
predicate: &'v WherePredicate<'v>,
898898
) {
899-
match predicate {
900-
&WherePredicate::BoundPredicate(WhereBoundPredicate {
899+
match *predicate {
900+
WherePredicate::BoundPredicate(WhereBoundPredicate {
901901
ref bounded_ty,
902902
bounds,
903903
bound_generic_params,
@@ -907,11 +907,11 @@ pub fn walk_where_predicate<'v, V: Visitor<'v>>(
907907
walk_list!(visitor, visit_param_bound, bounds);
908908
walk_list!(visitor, visit_generic_param, bound_generic_params);
909909
}
910-
&WherePredicate::RegionPredicate(WhereRegionPredicate { ref lifetime, bounds, .. }) => {
910+
WherePredicate::RegionPredicate(WhereRegionPredicate { ref lifetime, bounds, .. }) => {
911911
visitor.visit_lifetime(lifetime);
912912
walk_list!(visitor, visit_param_bound, bounds);
913913
}
914-
&WherePredicate::EqPredicate(WhereEqPredicate {
914+
WherePredicate::EqPredicate(WhereEqPredicate {
915915
hir_id, ref lhs_ty, ref rhs_ty, ..
916916
}) => {
917917
visitor.visit_id(hir_id);

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,19 +2233,19 @@ impl<'a> State<'a> {
22332233
}
22342234

22352235
match predicate {
2236-
&hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate {
2237-
ref bound_generic_params,
2238-
ref bounded_ty,
2236+
hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate {
2237+
bound_generic_params,
2238+
bounded_ty,
22392239
bounds,
22402240
..
22412241
}) => {
22422242
self.print_formal_generic_params(bound_generic_params);
22432243
self.print_type(&bounded_ty);
2244-
self.print_bounds(":", bounds);
2244+
self.print_bounds(":", *bounds);
22452245
}
2246-
&hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
2247-
ref lifetime,
2248-
ref bounds,
2246+
hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
2247+
lifetime,
2248+
bounds,
22492249
..
22502250
}) => {
22512251
self.print_lifetime(lifetime);
@@ -2264,10 +2264,8 @@ impl<'a> State<'a> {
22642264
}
22652265
}
22662266
}
2267-
&hir::WherePredicate::EqPredicate(hir::WhereEqPredicate {
2268-
ref lhs_ty,
2269-
ref rhs_ty,
2270-
..
2267+
hir::WherePredicate::EqPredicate(hir::WhereEqPredicate {
2268+
lhs_ty, rhs_ty, ..
22712269
}) => {
22722270
self.print_type(lhs_ty);
22732271
self.s.space();

compiler/rustc_incremental/src/assert_dep_graph.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,13 +310,13 @@ fn filter_nodes<'q>(
310310
sources: &Option<FxHashSet<&'q DepNode>>,
311311
targets: &Option<FxHashSet<&'q DepNode>>,
312312
) -> FxHashSet<&'q DepNode> {
313-
if let &Some(ref sources) = sources {
314-
if let &Some(ref targets) = targets {
313+
if let Some(sources) = sources {
314+
if let Some(targets) = targets {
315315
walk_between(query, sources, targets)
316316
} else {
317317
walk_nodes(query, sources, OUTGOING)
318318
}
319-
} else if let &Some(ref targets) = targets {
319+
} else if let Some(targets) = targets {
320320
walk_nodes(query, targets, INCOMING)
321321
} else {
322322
query.nodes().into_iter().collect()

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
915915
self.highlight_outer(&mut t1_out, &mut t2_out, path, sub, i, &other_ty);
916916
return Some(());
917917
}
918-
if let &ty::Adt(def, _) = ta.kind() {
918+
if let ty::Adt(def, _) = ta.kind() {
919919
let path_ = self.tcx.def_path_str(def.did);
920920
if path_ == other_path {
921921
self.highlight_outer(&mut t1_out, &mut t2_out, path, sub, i, &other_ty);

compiler/rustc_lint/src/builtin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -938,8 +938,8 @@ impl EarlyLintPass for DeprecatedAttr {
938938
if attr.ident().map(|ident| ident.name) == Some(n) {
939939
if let &AttributeGate::Gated(
940940
Stability::Deprecated(link, suggestion),
941-
ref name,
942-
ref reason,
941+
name,
942+
reason,
943943
_,
944944
) = g
945945
{

compiler/rustc_lint/src/nonstandard_style.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
397397
}
398398

399399
fn check_pat(&mut self, cx: &LateContext<'_>, p: &hir::Pat<'_>) {
400-
if let &PatKind::Binding(_, hid, ident, _) = &p.kind {
400+
if let PatKind::Binding(_, hid, ident, _) = p.kind {
401401
if let hir::Node::Pat(parent_pat) = cx.tcx.hir().get(cx.tcx.hir().get_parent_node(hid))
402402
{
403403
if let PatKind::Struct(_, field_pats, _) = &parent_pat.kind {

0 commit comments

Comments
 (0)