Skip to content

Commit e2e363f

Browse files
committed
Move needless_borrow from the nursery. The bug that moved it there was fixed over two years ago in d4370f8.
1 parent c530608 commit e2e363f

15 files changed

+48
-38
lines changed

clippy_dev/src/fmt.rs

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

70-
success &= rustfmt(context, &path)?;
70+
success &= rustfmt(context, path)?;
7171
}
7272

7373
Ok(success)

clippy_lints/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
16301630
LintId::of(&needless_arbitrary_self_type::NEEDLESS_ARBITRARY_SELF_TYPE),
16311631
LintId::of(&needless_bool::BOOL_COMPARISON),
16321632
LintId::of(&needless_bool::NEEDLESS_BOOL),
1633+
LintId::of(&needless_borrow::NEEDLESS_BORROW),
16331634
LintId::of(&needless_borrowed_ref::NEEDLESS_BORROWED_REFERENCE),
16341635
LintId::of(&needless_question_mark::NEEDLESS_QUESTION_MARK),
16351636
LintId::of(&needless_update::NEEDLESS_UPDATE),
@@ -1900,6 +1901,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
19001901
LintId::of(&needless_arbitrary_self_type::NEEDLESS_ARBITRARY_SELF_TYPE),
19011902
LintId::of(&needless_bool::BOOL_COMPARISON),
19021903
LintId::of(&needless_bool::NEEDLESS_BOOL),
1904+
LintId::of(&needless_borrow::NEEDLESS_BORROW),
19031905
LintId::of(&needless_borrowed_ref::NEEDLESS_BORROWED_REFERENCE),
19041906
LintId::of(&needless_question_mark::NEEDLESS_QUESTION_MARK),
19051907
LintId::of(&needless_update::NEEDLESS_UPDATE),
@@ -2055,7 +2057,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
20552057
LintId::of(&missing_const_for_fn::MISSING_CONST_FOR_FN),
20562058
LintId::of(&mutable_debug_assertion::DEBUG_ASSERT_WITH_MUT_CALL),
20572059
LintId::of(&mutex_atomic::MUTEX_INTEGER),
2058-
LintId::of(&needless_borrow::NEEDLESS_BORROW),
20592060
LintId::of(&path_buf_push_overwrite::PATH_BUF_PUSH_OVERWRITE),
20602061
LintId::of(&redundant_pub_crate::REDUNDANT_PUB_CRATE),
20612062
LintId::of(&regex::TRIVIAL_REGEX),

clippy_lints/src/needless_borrow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ declare_clippy_lint! {
2929
/// let x: &i32 = &5;
3030
/// ```
3131
pub NEEDLESS_BORROW,
32-
nursery,
32+
complexity,
3333
"taking a reference that is going to be automatically dereferenced"
3434
}
3535

tests/ui/borrow_interior_mutable_const/others.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#![warn(clippy::borrow_interior_mutable_const)]
2-
#![allow(clippy::declare_interior_mutable_const, clippy::ref_in_deref)]
2+
#![allow(
3+
clippy::declare_interior_mutable_const,
4+
clippy::ref_in_deref,
5+
clippy::needless_borrow
6+
)]
37
#![allow(const_item_mutation)]
48

59
use std::borrow::Cow;

tests/ui/borrow_interior_mutable_const/others.stderr

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: a `const` item with interior mutability should not be borrowed
2-
--> $DIR/others.rs:54:5
2+
--> $DIR/others.rs:58:5
33
|
44
LL | ATOMIC.store(1, Ordering::SeqCst); //~ ERROR interior mutability
55
| ^^^^^^
@@ -8,103 +8,103 @@ LL | ATOMIC.store(1, Ordering::SeqCst); //~ ERROR interior mutability
88
= help: assign this const to a local or static variable, and use the variable here
99

1010
error: a `const` item with interior mutability should not be borrowed
11-
--> $DIR/others.rs:55:16
11+
--> $DIR/others.rs:59:16
1212
|
1313
LL | assert_eq!(ATOMIC.load(Ordering::SeqCst), 5); //~ ERROR interior mutability
1414
| ^^^^^^
1515
|
1616
= help: assign this const to a local or static variable, and use the variable here
1717

1818
error: a `const` item with interior mutability should not be borrowed
19-
--> $DIR/others.rs:58:22
19+
--> $DIR/others.rs:62:22
2020
|
2121
LL | let _once_ref = &ONCE_INIT; //~ ERROR interior mutability
2222
| ^^^^^^^^^
2323
|
2424
= help: assign this const to a local or static variable, and use the variable here
2525

2626
error: a `const` item with interior mutability should not be borrowed
27-
--> $DIR/others.rs:59:25
27+
--> $DIR/others.rs:63:25
2828
|
2929
LL | let _once_ref_2 = &&ONCE_INIT; //~ ERROR interior mutability
3030
| ^^^^^^^^^
3131
|
3232
= help: assign this const to a local or static variable, and use the variable here
3333

3434
error: a `const` item with interior mutability should not be borrowed
35-
--> $DIR/others.rs:60:27
35+
--> $DIR/others.rs:64:27
3636
|
3737
LL | let _once_ref_4 = &&&&ONCE_INIT; //~ ERROR interior mutability
3838
| ^^^^^^^^^
3939
|
4040
= help: assign this const to a local or static variable, and use the variable here
4141

4242
error: a `const` item with interior mutability should not be borrowed
43-
--> $DIR/others.rs:61:26
43+
--> $DIR/others.rs:65:26
4444
|
4545
LL | let _once_mut = &mut ONCE_INIT; //~ ERROR interior mutability
4646
| ^^^^^^^^^
4747
|
4848
= help: assign this const to a local or static variable, and use the variable here
4949

5050
error: a `const` item with interior mutability should not be borrowed
51-
--> $DIR/others.rs:72:14
51+
--> $DIR/others.rs:76:14
5252
|
5353
LL | let _ = &ATOMIC_TUPLE; //~ ERROR interior mutability
5454
| ^^^^^^^^^^^^
5555
|
5656
= help: assign this const to a local or static variable, and use the variable here
5757

5858
error: a `const` item with interior mutability should not be borrowed
59-
--> $DIR/others.rs:73:14
59+
--> $DIR/others.rs:77:14
6060
|
6161
LL | let _ = &ATOMIC_TUPLE.0; //~ ERROR interior mutability
6262
| ^^^^^^^^^^^^
6363
|
6464
= help: assign this const to a local or static variable, and use the variable here
6565

6666
error: a `const` item with interior mutability should not be borrowed
67-
--> $DIR/others.rs:74:19
67+
--> $DIR/others.rs:78:19
6868
|
6969
LL | let _ = &(&&&&ATOMIC_TUPLE).0; //~ ERROR interior mutability
7070
| ^^^^^^^^^^^^
7171
|
7272
= help: assign this const to a local or static variable, and use the variable here
7373

7474
error: a `const` item with interior mutability should not be borrowed
75-
--> $DIR/others.rs:75:14
75+
--> $DIR/others.rs:79:14
7676
|
7777
LL | let _ = &ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
7878
| ^^^^^^^^^^^^
7979
|
8080
= help: assign this const to a local or static variable, and use the variable here
8181

8282
error: a `const` item with interior mutability should not be borrowed
83-
--> $DIR/others.rs:76:13
83+
--> $DIR/others.rs:80:13
8484
|
8585
LL | let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); //~ ERROR interior mutability
8686
| ^^^^^^^^^^^^
8787
|
8888
= help: assign this const to a local or static variable, and use the variable here
8989

9090
error: a `const` item with interior mutability should not be borrowed
91-
--> $DIR/others.rs:82:13
91+
--> $DIR/others.rs:86:13
9292
|
9393
LL | let _ = ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
9494
| ^^^^^^^^^^^^
9595
|
9696
= help: assign this const to a local or static variable, and use the variable here
9797

9898
error: a `const` item with interior mutability should not be borrowed
99-
--> $DIR/others.rs:87:5
99+
--> $DIR/others.rs:91:5
100100
|
101101
LL | CELL.set(2); //~ ERROR interior mutability
102102
| ^^^^
103103
|
104104
= help: assign this const to a local or static variable, and use the variable here
105105

106106
error: a `const` item with interior mutability should not be borrowed
107-
--> $DIR/others.rs:88:16
107+
--> $DIR/others.rs:92:16
108108
|
109109
LL | assert_eq!(CELL.get(), 6); //~ ERROR interior mutability
110110
| ^^^^

tests/ui/collapsible_match2.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#![warn(clippy::collapsible_match)]
2-
#![allow(clippy::needless_return, clippy::no_effect, clippy::single_match)]
2+
#![allow(
3+
clippy::needless_return,
4+
clippy::no_effect,
5+
clippy::single_match,
6+
clippy::needless_borrow
7+
)]
38

49
fn lint_cases(opt_opt: Option<Option<u32>>, res_opt: Result<Option<u32>, String>) {
510
// if guards on outer match

tests/ui/collapsible_match2.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: unnecessary nested match
2-
--> $DIR/collapsible_match2.rs:8:34
2+
--> $DIR/collapsible_match2.rs:13:34
33
|
44
LL | Ok(val) if make() => match val {
55
| __________________________________^
@@ -10,15 +10,15 @@ LL | | },
1010
|
1111
= note: `-D clippy::collapsible-match` implied by `-D warnings`
1212
help: the outer pattern can be modified to include the inner pattern
13-
--> $DIR/collapsible_match2.rs:8:16
13+
--> $DIR/collapsible_match2.rs:13:16
1414
|
1515
LL | Ok(val) if make() => match val {
1616
| ^^^ replace this binding
1717
LL | Some(n) => foo(n),
1818
| ^^^^^^^ with this pattern
1919

2020
error: unnecessary nested match
21-
--> $DIR/collapsible_match2.rs:15:24
21+
--> $DIR/collapsible_match2.rs:20:24
2222
|
2323
LL | Ok(val) => match val {
2424
| ________________________^
@@ -28,15 +28,15 @@ LL | | },
2828
| |_____________^
2929
|
3030
help: the outer pattern can be modified to include the inner pattern
31-
--> $DIR/collapsible_match2.rs:15:16
31+
--> $DIR/collapsible_match2.rs:20:16
3232
|
3333
LL | Ok(val) => match val {
3434
| ^^^ replace this binding
3535
LL | Some(n) => foo(n),
3636
| ^^^^^^^ with this pattern
3737

3838
error: unnecessary nested match
39-
--> $DIR/collapsible_match2.rs:29:29
39+
--> $DIR/collapsible_match2.rs:34:29
4040
|
4141
LL | $pat => match $e {
4242
| _____________________________^
@@ -49,7 +49,7 @@ LL | mac!(res_opt => Ok(val), val => Some(n), foo(n));
4949
| ------------------------------------------------- in this macro invocation
5050
|
5151
help: the outer pattern can be modified to include the inner pattern
52-
--> $DIR/collapsible_match2.rs:41:28
52+
--> $DIR/collapsible_match2.rs:46:28
5353
|
5454
LL | mac!(res_opt => Ok(val), val => Some(n), foo(n));
5555
| ^^^ ^^^^^^^ with this pattern
@@ -58,7 +58,7 @@ LL | mac!(res_opt => Ok(val), val => Some(n), foo(n));
5858
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
5959

6060
error: unnecessary nested match
61-
--> $DIR/collapsible_match2.rs:46:20
61+
--> $DIR/collapsible_match2.rs:51:20
6262
|
6363
LL | Some(s) => match *s {
6464
| ____________________^
@@ -68,15 +68,15 @@ LL | | },
6868
| |_________^
6969
|
7070
help: the outer pattern can be modified to include the inner pattern
71-
--> $DIR/collapsible_match2.rs:46:14
71+
--> $DIR/collapsible_match2.rs:51:14
7272
|
7373
LL | Some(s) => match *s {
7474
| ^ replace this binding
7575
LL | [n] => foo(n),
7676
| ^^^ with this pattern
7777

7878
error: unnecessary nested match
79-
--> $DIR/collapsible_match2.rs:55:24
79+
--> $DIR/collapsible_match2.rs:60:24
8080
|
8181
LL | Some(ref s) => match &*s {
8282
| ________________________^
@@ -86,7 +86,7 @@ LL | | },
8686
| |_________^
8787
|
8888
help: the outer pattern can be modified to include the inner pattern
89-
--> $DIR/collapsible_match2.rs:55:14
89+
--> $DIR/collapsible_match2.rs:60:14
9090
|
9191
LL | Some(ref s) => match &*s {
9292
| ^^^^^ replace this binding

tests/ui/escape_analysis.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ fn warn_match() {
101101
let x = box A;
102102
match &x {
103103
// not moved
104-
ref y => (),
104+
y => (),
105105
}
106106
}
107107

@@ -111,7 +111,7 @@ fn nowarn_large_array() {
111111
let x = box [1; 10000];
112112
match &x {
113113
// not moved
114-
ref y => (),
114+
y => (),
115115
}
116116
}
117117

tests/ui/implicit_clone.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn main() {
6666
let _ = vec.to_vec();
6767

6868
let vec_ref = &vec;
69-
let _ = return_owned_from_slice(&vec_ref);
69+
let _ = return_owned_from_slice(vec_ref);
7070
let _ = vec_ref.to_owned();
7171
let _ = vec_ref.to_vec();
7272

tests/ui/into_iter_on_ref.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-rustfix
2-
#![allow(clippy::useless_vec)]
2+
#![allow(clippy::useless_vec, clippy::needless_borrow)]
33
#![warn(clippy::into_iter_on_ref)]
44

55
struct X;

tests/ui/into_iter_on_ref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-rustfix
2-
#![allow(clippy::useless_vec)]
2+
#![allow(clippy::useless_vec, clippy::needless_borrow)]
33
#![warn(clippy::into_iter_on_ref)]
44

55
struct X;

tests/ui/ref_option_ref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
static THRESHOLD: i32 = 10;
1010
static REF_THRESHOLD: &Option<&i32> = &Some(&THRESHOLD);
1111
const CONST_THRESHOLD: &i32 = &10;
12-
const REF_CONST: &Option<&i32> = &Some(&CONST_THRESHOLD);
12+
const REF_CONST: &Option<&i32> = &Some(CONST_THRESHOLD);
1313

1414
type RefOptRefU32<'a> = &'a Option<&'a u32>;
1515
type RefOptRef<'a, T> = &'a Option<&'a T>;

tests/ui/ref_option_ref.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | static REF_THRESHOLD: &Option<&i32> = &Some(&THRESHOLD);
99
error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>`
1010
--> $DIR/ref_option_ref.rs:12:18
1111
|
12-
LL | const REF_CONST: &Option<&i32> = &Some(&CONST_THRESHOLD);
12+
LL | const REF_CONST: &Option<&i32> = &Some(CONST_THRESHOLD);
1313
| ^^^^^^^^^^^^^ help: try: `Option<&i32>`
1414

1515
error: since `&` implements the `Copy` trait, `&Option<&T>` can be simplified to `Option<&T>`

tests/ui/stable_sort_primitive.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn main() {
2020
// Negative examples: behavior changes if made unstable
2121
let mut vec = vec![1, 3, 2];
2222
vec.sort_by_key(|i| i / 2);
23-
vec.sort_by(|a, b| (a + b).cmp(&b));
23+
vec.sort_by(|&a, &b| (a + b).cmp(&b));
2424
// negative examples - Not of a primitive type
2525
let mut vec_of_complex = vec![String::from("hello"), String::from("world!")];
2626
vec_of_complex.sort();

tests/ui/stable_sort_primitive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn main() {
2020
// Negative examples: behavior changes if made unstable
2121
let mut vec = vec![1, 3, 2];
2222
vec.sort_by_key(|i| i / 2);
23-
vec.sort_by(|a, b| (a + b).cmp(&b));
23+
vec.sort_by(|&a, &b| (a + b).cmp(&b));
2424
// negative examples - Not of a primitive type
2525
let mut vec_of_complex = vec![String::from("hello"), String::from("world!")];
2626
vec_of_complex.sort();

0 commit comments

Comments
 (0)