Skip to content

Commit 16b0499

Browse files
committed
Fix all occurences of needless_borrow internally
1 parent 81f9946 commit 16b0499

File tree

183 files changed

+2145
-2157
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

183 files changed

+2145
-2157
lines changed

clippy_dev/src/fmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub fn run(check: bool, verbose: bool) {
6868
continue;
6969
}
7070

71-
success &= rustfmt(context, &path)?;
71+
success &= rustfmt(context, path)?;
7272
}
7373

7474
Ok(success)

clippy_dev/src/lib.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl Lint {
101101
#[must_use]
102102
pub fn gen_lint_group_list<'a>(lints: impl Iterator<Item = &'a Lint>) -> Vec<String> {
103103
lints
104-
.map(|l| format!(" LintId::of(&{}::{}),", l.module, l.name.to_uppercase()))
104+
.map(|l| format!(" LintId::of({}::{}),", l.module, l.name.to_uppercase()))
105105
.sorted()
106106
.collect::<Vec<String>>()
107107
}
@@ -154,17 +154,17 @@ pub fn gen_register_lint_list<'a>(
154154
let header = " store.register_lints(&[".to_string();
155155
let footer = " ]);".to_string();
156156
let internal_lints = internal_lints
157-
.sorted_by_key(|l| format!(" &{}::{},", l.module, l.name.to_uppercase()))
157+
.sorted_by_key(|l| format!(" {}::{},", l.module, l.name.to_uppercase()))
158158
.map(|l| {
159159
format!(
160-
" #[cfg(feature = \"internal-lints\")]\n &{}::{},",
160+
" #[cfg(feature = \"internal-lints\")]\n {}::{},",
161161
l.module,
162162
l.name.to_uppercase()
163163
)
164164
});
165165
let other_lints = usable_lints
166-
.sorted_by_key(|l| format!(" &{}::{},", l.module, l.name.to_uppercase()))
167-
.map(|l| format!(" &{}::{},", l.module, l.name.to_uppercase()))
166+
.sorted_by_key(|l| format!(" {}::{},", l.module, l.name.to_uppercase()))
167+
.map(|l| format!(" {}::{},", l.module, l.name.to_uppercase()))
168168
.sorted();
169169
let mut lint_list = vec![header];
170170
lint_list.extend(internal_lints);
@@ -550,9 +550,9 @@ fn test_gen_lint_group_list() {
550550
Lint::new("internal", "internal_style", "abc", None, "module_name"),
551551
];
552552
let expected = vec![
553-
" LintId::of(&module_name::ABC),".to_string(),
554-
" LintId::of(&module_name::INTERNAL),".to_string(),
555-
" LintId::of(&module_name::SHOULD_ASSERT_EQ),".to_string(),
553+
" LintId::of(module_name::ABC),".to_string(),
554+
" LintId::of(module_name::INTERNAL),".to_string(),
555+
" LintId::of(module_name::SHOULD_ASSERT_EQ),".to_string(),
556556
];
557557
assert_eq!(expected, gen_lint_group_list(lints.iter()));
558558
}

clippy_lints/src/absurd_extreme_comparisons.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ declare_lint_pass!(AbsurdExtremeComparisons => [ABSURD_EXTREME_COMPARISONS]);
4444

4545
impl<'tcx> LateLintPass<'tcx> for AbsurdExtremeComparisons {
4646
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
47-
if let ExprKind::Binary(ref cmp, ref lhs, ref rhs) = expr.kind {
47+
if let ExprKind::Binary(ref cmp, lhs, rhs) = expr.kind {
4848
if let Some((culprit, result)) = detect_absurd_comparison(cx, cmp.node, lhs, rhs) {
4949
if !expr.span.from_expansion() {
5050
let msg = "this comparison involving the minimum or maximum element for this \
@@ -95,7 +95,7 @@ enum AbsurdComparisonResult {
9595
}
9696

9797
fn is_cast_between_fixed_and_target<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> bool {
98-
if let ExprKind::Cast(ref cast_exp, _) = expr.kind {
98+
if let ExprKind::Cast(cast_exp, _) = expr.kind {
9999
let precast_ty = cx.typeck_results().expr_ty(cast_exp);
100100
let cast_ty = cx.typeck_results().expr_ty(expr);
101101

clippy_lints/src/assertions_on_constants.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnConstants {
7171
return;
7272
}
7373
if_chain! {
74-
if let ExprKind::Unary(_, ref lit) = e.kind;
74+
if let ExprKind::Unary(_, lit) = e.kind;
7575
if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.typeck_results(), lit);
7676
if is_true;
7777
then {
@@ -82,7 +82,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnConstants {
8282
if assert_span.from_expansion() {
8383
return;
8484
}
85-
if let Some(assert_match) = match_assert_with_message(&cx, e) {
85+
if let Some(assert_match) = match_assert_with_message(cx, e) {
8686
match assert_match {
8787
// matched assert but not message
8888
AssertKind::WithoutMessage(false) => lint_false_without_message(),
@@ -113,17 +113,17 @@ enum AssertKind {
113113
/// where `message` is any expression and `c` is a constant bool.
114114
fn match_assert_with_message<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<AssertKind> {
115115
if_chain! {
116-
if let ExprKind::If(ref cond, ref then, _) = expr.kind;
117-
if let ExprKind::Unary(UnOp::Not, ref expr) = cond.kind;
116+
if let ExprKind::If(cond, then, _) = expr.kind;
117+
if let ExprKind::Unary(UnOp::Not, expr) = cond.kind;
118118
// bind the first argument of the `assert!` macro
119119
if let Some((Constant::Bool(is_true), _)) = constant(cx, cx.typeck_results(), expr);
120120
// block
121-
if let ExprKind::Block(ref block, _) = then.kind;
121+
if let ExprKind::Block(block, _) = then.kind;
122122
if block.stmts.is_empty();
123123
if let Some(block_expr) = &block.expr;
124124
// inner block is optional. unwrap it if it exists, or use the expression as is otherwise.
125125
if let Some(begin_panic_call) = match block_expr.kind {
126-
ExprKind::Block(ref inner_block, _) => &inner_block.expr,
126+
ExprKind::Block(inner_block, _) => &inner_block.expr,
127127
_ => &block.expr,
128128
};
129129
// function call

clippy_lints/src/atomic_ordering.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn match_ordering_def_path(cx: &LateContext<'_>, did: DefId, orderings: &[&str])
8585

8686
fn check_atomic_load_store(cx: &LateContext<'_>, expr: &Expr<'_>) {
8787
if_chain! {
88-
if let ExprKind::MethodCall(ref method_path, _, args, _) = &expr.kind;
88+
if let ExprKind::MethodCall(method_path, _, args, _) = &expr.kind;
8989
let method = method_path.ident.name.as_str();
9090
if type_is_atomic(cx, &args[0]);
9191
if method == "load" || method == "store";
@@ -120,7 +120,7 @@ fn check_atomic_load_store(cx: &LateContext<'_>, expr: &Expr<'_>) {
120120

121121
fn check_memory_fence(cx: &LateContext<'_>, expr: &Expr<'_>) {
122122
if_chain! {
123-
if let ExprKind::Call(ref func, ref args) = expr.kind;
123+
if let ExprKind::Call(func, args) = expr.kind;
124124
if let ExprKind::Path(ref func_qpath) = func.kind;
125125
if let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id();
126126
if ["fence", "compiler_fence"]
@@ -152,7 +152,7 @@ fn opt_ordering_defid(cx: &LateContext<'_>, ord_arg: &Expr<'_>) -> Option<DefId>
152152

153153
fn check_atomic_compare_exchange(cx: &LateContext<'_>, expr: &Expr<'_>) {
154154
if_chain! {
155-
if let ExprKind::MethodCall(ref method_path, _, args, _) = &expr.kind;
155+
if let ExprKind::MethodCall(method_path, _, args, _) = &expr.kind;
156156
let method = method_path.ident.name.as_str();
157157
if type_is_atomic(cx, &args[0]);
158158
if method == "compare_exchange" || method == "compare_exchange_weak" || method == "fetch_update";

clippy_lints/src/attrs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ fn check_mismatched_target_os(cx: &EarlyContext<'_>, attr: &Attribute) {
602602
if let NestedMetaItem::MetaItem(meta) = item {
603603
match &meta.kind {
604604
MetaItemKind::List(list) => {
605-
mismatched.extend(find_mismatched_target_os(&list));
605+
mismatched.extend(find_mismatched_target_os(list));
606606
},
607607
MetaItemKind::Word => {
608608
if_chain! {
@@ -629,7 +629,7 @@ fn check_mismatched_target_os(cx: &EarlyContext<'_>, attr: &Attribute) {
629629
then {
630630
let mess = "operating system used in target family position";
631631

632-
span_lint_and_then(cx, MISMATCHED_TARGET_OS, attr.span, &mess, |diag| {
632+
span_lint_and_then(cx, MISMATCHED_TARGET_OS, attr.span, mess, |diag| {
633633
// Avoid showing the unix suggestion multiple times in case
634634
// we have more than one mismatch for unix-like systems
635635
let mut unix_suggested = false;

clippy_lints/src/await_holding_invalid.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl LateLintPass<'_> for AwaitHolding {
101101
let typeck_results = cx.tcx.typeck_body(body_id);
102102
check_interior_types(
103103
cx,
104-
&typeck_results.generator_interior_types.as_ref().skip_binder(),
104+
typeck_results.generator_interior_types.as_ref().skip_binder(),
105105
body.value.span,
106106
);
107107
}

clippy_lints/src/bytecount.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ declare_lint_pass!(ByteCount => [NAIVE_BYTECOUNT]);
3838
impl<'tcx> LateLintPass<'tcx> for ByteCount {
3939
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
4040
if_chain! {
41-
if let ExprKind::MethodCall(ref count, _, ref count_args, _) = expr.kind;
41+
if let ExprKind::MethodCall(count, _, count_args, _) = expr.kind;
4242
if count.ident.name == sym!(count);
4343
if count_args.len() == 1;
44-
if let ExprKind::MethodCall(ref filter, _, ref filter_args, _) = count_args[0].kind;
44+
if let ExprKind::MethodCall(filter, _, filter_args, _) = count_args[0].kind;
4545
if filter.ident.name == sym!(filter);
4646
if filter_args.len() == 2;
4747
if let ExprKind::Closure(_, _, body_id, _, _) = filter_args[1].kind;
4848
let body = cx.tcx.hir().body(body_id);
4949
if body.params.len() == 1;
50-
if let Some(argname) = get_pat_name(&body.params[0].pat);
51-
if let ExprKind::Binary(ref op, ref l, ref r) = body.value.kind;
50+
if let Some(argname) = get_pat_name(body.params[0].pat);
51+
if let ExprKind::Binary(ref op, l, r) = body.value.kind;
5252
if op.node == BinOpKind::Eq;
5353
if match_type(cx,
5454
cx.typeck_results().expr_ty(&filter_args[0]).peel_refs(),
@@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for ByteCount {
6464
if ty::Uint(UintTy::U8) != *cx.typeck_results().expr_ty(needle).peel_refs().kind() {
6565
return;
6666
}
67-
let haystack = if let ExprKind::MethodCall(ref path, _, ref args, _) =
67+
let haystack = if let ExprKind::MethodCall(path, _, args, _) =
6868
filter_args[0].kind {
6969
let p = path.ident.name;
7070
if (p == sym::iter || p == sym!(iter_mut)) && args.len() == 1 {
@@ -98,10 +98,10 @@ fn check_arg(name: Symbol, arg: Symbol, needle: &Expr<'_>) -> bool {
9898

9999
fn get_path_name(expr: &Expr<'_>) -> Option<Symbol> {
100100
match expr.kind {
101-
ExprKind::Box(ref e) | ExprKind::AddrOf(BorrowKind::Ref, _, ref e) | ExprKind::Unary(UnOp::Deref, ref e) => {
101+
ExprKind::Box(e) | ExprKind::AddrOf(BorrowKind::Ref, _, e) | ExprKind::Unary(UnOp::Deref, e) => {
102102
get_path_name(e)
103103
},
104-
ExprKind::Block(ref b, _) => {
104+
ExprKind::Block(b, _) => {
105105
if b.stmts.is_empty() {
106106
b.expr.as_ref().and_then(|p| get_path_name(p))
107107
} else {

clippy_lints/src/casts/cast_ptr_alignment.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_target::abi::LayoutOf;
1010
use super::CAST_PTR_ALIGNMENT;
1111

1212
pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
13-
if let ExprKind::Cast(ref cast_expr, cast_to) = expr.kind {
13+
if let ExprKind::Cast(cast_expr, cast_to) = expr.kind {
1414
if is_hir_ty_cfg_dependant(cx, cast_to) {
1515
return;
1616
}

clippy_lints/src/casts/cast_sign_loss.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn should_lint(cx: &LateContext<'_>, cast_op: &Expr<'_>, cast_from: Ty<'_>, cast
3030
}
3131

3232
// Don't lint for positive constants.
33-
let const_val = constant(cx, &cx.typeck_results(), cast_op);
33+
let const_val = constant(cx, cx.typeck_results(), cast_op);
3434
if_chain! {
3535
if let Some((Constant::Int(n), _)) = const_val;
3636
if let ty::Int(ity) = *cast_from.kind();
@@ -41,14 +41,14 @@ fn should_lint(cx: &LateContext<'_>, cast_op: &Expr<'_>, cast_from: Ty<'_>, cast
4141
}
4242

4343
// Don't lint for the result of methods that always return non-negative values.
44-
if let ExprKind::MethodCall(ref path, _, _, _) = cast_op.kind {
44+
if let ExprKind::MethodCall(path, _, _, _) = cast_op.kind {
4545
let mut method_name = path.ident.name.as_str();
4646
let allowed_methods = ["abs", "checked_abs", "rem_euclid", "checked_rem_euclid"];
4747

4848
if_chain! {
4949
if method_name == "unwrap";
5050
if let Some(arglist) = method_chain_args(cast_op, &["unwrap"]);
51-
if let ExprKind::MethodCall(ref inner_path, _, _, _) = &arglist[0][0].kind;
51+
if let ExprKind::MethodCall(inner_path, _, _, _) = &arglist[0][0].kind;
5252
then {
5353
method_name = inner_path.ident.name.as_str();
5454
}

clippy_lints/src/casts/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ impl<'tcx> LateLintPass<'tcx> for Casts {
372372
return;
373373
}
374374

375-
if let ExprKind::Cast(ref cast_expr, cast_to) = expr.kind {
375+
if let ExprKind::Cast(cast_expr, cast_to) = expr.kind {
376376
if is_hir_ty_cfg_dependant(cx, cast_to) {
377377
return;
378378
}

clippy_lints/src/checked_conversions.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for CheckedConversions {
6464

6565
let result = if_chain! {
6666
if !in_external_macro(cx.sess(), item.span);
67-
if let ExprKind::Binary(op, ref left, ref right) = &item.kind;
67+
if let ExprKind::Binary(op, left, right) = &item.kind;
6868

6969
then {
7070
match op.node {
@@ -200,7 +200,7 @@ impl ConversionType {
200200
/// Check for `expr <= (to_type::MAX as from_type)`
201201
fn check_upper_bound<'tcx>(expr: &'tcx Expr<'tcx>) -> Option<Conversion<'tcx>> {
202202
if_chain! {
203-
if let ExprKind::Binary(ref op, ref left, ref right) = &expr.kind;
203+
if let ExprKind::Binary(ref op, left, right) = &expr.kind;
204204
if let Some((candidate, check)) = normalize_le_ge(op, left, right);
205205
if let Some((from, to)) = get_types_from_cast(check, INTS, "max_value", "MAX");
206206

@@ -219,7 +219,7 @@ fn check_lower_bound<'tcx>(expr: &'tcx Expr<'tcx>) -> Option<Conversion<'tcx>> {
219219
}
220220

221221
// First of we need a binary containing the expression & the cast
222-
if let ExprKind::Binary(ref op, ref left, ref right) = &expr.kind {
222+
if let ExprKind::Binary(ref op, left, right) = &expr.kind {
223223
normalize_le_ge(op, right, left).and_then(|(l, r)| check_function(l, r))
224224
} else {
225225
None
@@ -260,7 +260,7 @@ fn get_types_from_cast<'a>(
260260
// or `to_type::MAX as from_type`
261261
let call_from_cast: Option<(&Expr<'_>, &str)> = if_chain! {
262262
// to_type::max_value(), from_type
263-
if let ExprKind::Cast(ref limit, ref from_type) = &expr.kind;
263+
if let ExprKind::Cast(limit, from_type) = &expr.kind;
264264
if let TyKind::Path(ref from_type_path) = &from_type.kind;
265265
if let Some(from_sym) = int_ty_to_sym(from_type_path);
266266

@@ -275,7 +275,7 @@ fn get_types_from_cast<'a>(
275275
let limit_from: Option<(&Expr<'_>, &str)> = call_from_cast.or_else(|| {
276276
if_chain! {
277277
// `from_type::from, to_type::max_value()`
278-
if let ExprKind::Call(ref from_func, ref args) = &expr.kind;
278+
if let ExprKind::Call(from_func, args) = &expr.kind;
279279
// `to_type::max_value()`
280280
if args.len() == 1;
281281
if let limit = &args[0];
@@ -317,9 +317,9 @@ fn get_types_from_cast<'a>(
317317
/// Gets the type which implements the called function
318318
fn get_implementing_type<'a>(path: &QPath<'_>, candidates: &'a [&str], function: &str) -> Option<&'a str> {
319319
if_chain! {
320-
if let QPath::TypeRelative(ref ty, ref path) = &path;
320+
if let QPath::TypeRelative(ty, path) = &path;
321321
if path.ident.name.as_str() == function;
322-
if let TyKind::Path(QPath::Resolved(None, ref tp)) = &ty.kind;
322+
if let TyKind::Path(QPath::Resolved(None, tp)) = &ty.kind;
323323
if let [int] = &*tp.segments;
324324
then {
325325
let name = &int.ident.name.as_str();
@@ -333,7 +333,7 @@ fn get_implementing_type<'a>(path: &QPath<'_>, candidates: &'a [&str], function:
333333
/// Gets the type as a string, if it is a supported integer
334334
fn int_ty_to_sym<'tcx>(path: &QPath<'_>) -> Option<&'tcx str> {
335335
if_chain! {
336-
if let QPath::Resolved(_, ref path) = *path;
336+
if let QPath::Resolved(_, path) = *path;
337337
if let [ty] = &*path.segments;
338338
then {
339339
let name = &ty.ident.name.as_str();

clippy_lints/src/cognitive_complexity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl<'tcx> Visitor<'tcx> for CcHelper {
152152
ExprKind::If(_, _, _) => {
153153
self.cc += 1;
154154
},
155-
ExprKind::Match(_, ref arms, _) => {
155+
ExprKind::Match(_, arms, _) => {
156156
if arms.len() > 1 {
157157
self.cc += 1;
158158
}

clippy_lints/src/comparison_chain.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,8 @@ impl<'tcx> LateLintPass<'tcx> for ComparisonChain {
7171
}
7272

7373
for cond in conds.windows(2) {
74-
if let (
75-
&ExprKind::Binary(ref kind1, ref lhs1, ref rhs1),
76-
&ExprKind::Binary(ref kind2, ref lhs2, ref rhs2),
77-
) = (&cond[0].kind, &cond[1].kind)
74+
if let (&ExprKind::Binary(ref kind1, lhs1, rhs1), &ExprKind::Binary(ref kind2, lhs2, rhs2)) =
75+
(&cond[0].kind, &cond[1].kind)
7876
{
7977
if !kind_is_cmp(kind1.node) || !kind_is_cmp(kind2.node) {
8078
return;

clippy_lints/src/copies.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl<'tcx> LateLintPass<'tcx> for CopyAndPaste {
111111
if !expr.span.from_expansion() {
112112
// skip ifs directly in else, it will be checked in the parent if
113113
if let Some(&Expr {
114-
kind: ExprKind::If(_, _, Some(ref else_expr)),
114+
kind: ExprKind::If(_, _, Some(else_expr)),
115115
..
116116
}) = get_parent_expr(cx, expr)
117117
{

clippy_lints/src/create_dir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ declare_lint_pass!(CreateDir => [CREATE_DIR]);
3333
impl LateLintPass<'_> for CreateDir {
3434
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
3535
if_chain! {
36-
if let ExprKind::Call(ref func, ref args) = expr.kind;
36+
if let ExprKind::Call(func, args) = expr.kind;
3737
if let ExprKind::Path(ref path) = func.kind;
3838
if let Some(def_id) = cx.qpath_res(path, func.hir_id).opt_def_id();
3939
if match_def_path(cx, def_id, &paths::STD_FS_CREATE_DIR);

0 commit comments

Comments
 (0)