Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 4435474

Browse files
committed
Use reference patterns compatible with edition 2024
Reference patterns have become stricter in edition 2024. The binding modes cannot be mixed.
1 parent 67d5056 commit 4435474

12 files changed

+33
-33
lines changed

tests/ui/iter_overeager_cloned.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn main() {
5959
iter: impl Iterator<Item = &'a (&'a u32, String)> + 'a,
6060
target: String,
6161
) -> impl Iterator<Item = (&'a u32, String)> + 'a {
62-
iter.filter(move |&(&a, b)| a == 1 && b == &target).cloned()
62+
iter.filter(move |&&(&a, ref b)| a == 1 && b == &target).cloned()
6363
//~^ iter_overeager_cloned
6464
}
6565

tests/ui/iter_overeager_cloned.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn main() {
6060
iter: impl Iterator<Item = &'a (&'a u32, String)> + 'a,
6161
target: String,
6262
) -> impl Iterator<Item = (&'a u32, String)> + 'a {
63-
iter.cloned().filter(move |(&a, b)| a == 1 && b == &target)
63+
iter.cloned().filter(move |&(&a, ref b)| a == 1 && b == &target)
6464
//~^ iter_overeager_cloned
6565
}
6666

tests/ui/iter_overeager_cloned.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ LL | let _ = vec.iter().cloned().find(f);
120120
error: unnecessarily eager cloning of iterator items
121121
--> tests/ui/iter_overeager_cloned.rs:63:9
122122
|
123-
LL | iter.cloned().filter(move |(&a, b)| a == 1 && b == &target)
124-
| ^^^^-------------------------------------------------------
123+
LL | iter.cloned().filter(move |&(&a, ref b)| a == 1 && b == &target)
124+
| ^^^^------------------------------------------------------------
125125
| |
126-
| help: try: `.filter(move |&(&a, b)| a == 1 && b == &target).cloned()`
126+
| help: try: `.filter(move |&&(&a, ref b)| a == 1 && b == &target).cloned()`
127127

128128
error: unnecessarily eager cloning of iterator items
129129
--> tests/ui/iter_overeager_cloned.rs:75:13

tests/ui/manual_map_option.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ fn main() {
101101

102102
match &mut Some(String::new()) {
103103
//~^ manual_map
104-
Some(ref x) => Some(x.len()),
104+
&mut Some(ref x) => Some(x.len()),
105105
None => None,
106106
};
107107

tests/ui/manual_map_option.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ error: manual implementation of `Option::map`
127127
|
128128
LL | / match &mut Some(String::new()) {
129129
LL | |
130-
LL | | Some(ref x) => Some(x.len()),
130+
LL | | &mut Some(ref x) => Some(x.len()),
131131
LL | | None => None,
132132
LL | | };
133133
| |_____^ help: try: `Some(String::new()).as_ref().map(|x| x.len())`

tests/ui/manual_map_option_2.fixed

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ mod with_type_coercion {
115115
fn with_fn_ret(s: &Option<String>) -> Option<(String, &str)> {
116116
// Don't lint, `map` doesn't work as the return type is adjusted.
117117
match s {
118-
Some(x) => Some({ if let Some(ref s) = s { (x.clone(), s) } else { panic!() } }),
118+
Some(x) => Some({ if let Some(s) = s { (x.clone(), s) } else { panic!() } }),
119119
None => None,
120120
}
121121
}
@@ -124,7 +124,7 @@ mod with_type_coercion {
124124
if true {
125125
// Don't lint, `map` doesn't work as the return type is adjusted.
126126
return match s {
127-
Some(x) => Some({ if let Some(ref s) = s { (x.clone(), s) } else { panic!() } }),
127+
Some(x) => Some({ if let Some(s) = s { (x.clone(), s) } else { panic!() } }),
128128
None => None,
129129
};
130130
}
@@ -136,7 +136,7 @@ mod with_type_coercion {
136136
let x: Option<(String, &'a str)>;
137137
x = {
138138
match s {
139-
Some(x) => Some({ if let Some(ref s) = s { (x.clone(), s) } else { panic!() } }),
139+
Some(x) => Some({ if let Some(s) = s { (x.clone(), s) } else { panic!() } }),
140140
None => None,
141141
}
142142
};

tests/ui/manual_map_option_2.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ mod with_type_coercion {
143143
fn with_fn_ret(s: &Option<String>) -> Option<(String, &str)> {
144144
// Don't lint, `map` doesn't work as the return type is adjusted.
145145
match s {
146-
Some(x) => Some({ if let Some(ref s) = s { (x.clone(), s) } else { panic!() } }),
146+
Some(x) => Some({ if let Some(s) = s { (x.clone(), s) } else { panic!() } }),
147147
None => None,
148148
}
149149
}
@@ -152,7 +152,7 @@ mod with_type_coercion {
152152
if true {
153153
// Don't lint, `map` doesn't work as the return type is adjusted.
154154
return match s {
155-
Some(x) => Some({ if let Some(ref s) = s { (x.clone(), s) } else { panic!() } }),
155+
Some(x) => Some({ if let Some(s) = s { (x.clone(), s) } else { panic!() } }),
156156
None => None,
157157
};
158158
}
@@ -164,7 +164,7 @@ mod with_type_coercion {
164164
let x: Option<(String, &'a str)>;
165165
x = {
166166
match s {
167-
Some(x) => Some({ if let Some(ref s) = s { (x.clone(), s) } else { panic!() } }),
167+
Some(x) => Some({ if let Some(s) = s { (x.clone(), s) } else { panic!() } }),
168168
None => None,
169169
}
170170
};

tests/ui/manual_retain.fixed

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![warn(clippy::manual_retain)]
2-
#![allow(unused, clippy::redundant_clone)]
2+
#![allow(unused, clippy::needless_borrowed_reference, clippy::redundant_clone)]
33
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
44

55
fn main() {
@@ -31,7 +31,7 @@ fn binary_heap_retain() {
3131

3232
// Do lint, because we use pattern matching
3333
let mut tuples = BinaryHeap::from([(0, 1), (1, 2), (2, 3)]);
34-
tuples.retain(|(ref x, ref y)| *x == 0);
34+
tuples.retain(|&(ref x, ref y)| *x == 0);
3535
//~^ manual_retain
3636
tuples.retain(|(x, y)| *x == 0);
3737
//~^ manual_retain
@@ -99,7 +99,7 @@ fn btree_set_retain() {
9999

100100
// Do lint, because we use pattern matching
101101
let mut tuples = BTreeSet::from([(0, 1), (1, 2), (2, 3)]);
102-
tuples.retain(|(ref x, ref y)| *x == 0);
102+
tuples.retain(|&(ref x, ref y)| *x == 0);
103103
//~^ manual_retain
104104
tuples.retain(|(x, y)| *x == 0);
105105
//~^ manual_retain
@@ -166,7 +166,7 @@ fn hash_set_retain() {
166166

167167
// Do lint, because we use pattern matching
168168
let mut tuples = HashSet::from([(0, 1), (1, 2), (2, 3)]);
169-
tuples.retain(|(ref x, ref y)| *x == 0);
169+
tuples.retain(|&(ref x, ref y)| *x == 0);
170170
//~^ manual_retain
171171
tuples.retain(|(x, y)| *x == 0);
172172
//~^ manual_retain
@@ -220,7 +220,7 @@ fn vec_retain() {
220220

221221
// Do lint, because we use pattern matching
222222
let mut tuples = vec![(0, 1), (1, 2), (2, 3)];
223-
tuples.retain(|(ref x, ref y)| *x == 0);
223+
tuples.retain(|&(ref x, ref y)| *x == 0);
224224
//~^ manual_retain
225225
tuples.retain(|(x, y)| *x == 0);
226226
//~^ manual_retain

tests/ui/manual_retain.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![warn(clippy::manual_retain)]
2-
#![allow(unused, clippy::redundant_clone)]
2+
#![allow(unused, clippy::needless_borrowed_reference, clippy::redundant_clone)]
33
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
44

55
fn main() {
@@ -31,7 +31,7 @@ fn binary_heap_retain() {
3131

3232
// Do lint, because we use pattern matching
3333
let mut tuples = BinaryHeap::from([(0, 1), (1, 2), (2, 3)]);
34-
tuples = tuples.iter().filter(|(ref x, ref y)| *x == 0).copied().collect();
34+
tuples = tuples.iter().filter(|&&(ref x, ref y)| *x == 0).copied().collect();
3535
//~^ manual_retain
3636
tuples = tuples.iter().filter(|(x, y)| *x == 0).copied().collect();
3737
//~^ manual_retain
@@ -103,7 +103,7 @@ fn btree_set_retain() {
103103

104104
// Do lint, because we use pattern matching
105105
let mut tuples = BTreeSet::from([(0, 1), (1, 2), (2, 3)]);
106-
tuples = tuples.iter().filter(|(ref x, ref y)| *x == 0).copied().collect();
106+
tuples = tuples.iter().filter(|&&(ref x, ref y)| *x == 0).copied().collect();
107107
//~^ manual_retain
108108
tuples = tuples.iter().filter(|(x, y)| *x == 0).copied().collect();
109109
//~^ manual_retain
@@ -174,7 +174,7 @@ fn hash_set_retain() {
174174

175175
// Do lint, because we use pattern matching
176176
let mut tuples = HashSet::from([(0, 1), (1, 2), (2, 3)]);
177-
tuples = tuples.iter().filter(|(ref x, ref y)| *x == 0).copied().collect();
177+
tuples = tuples.iter().filter(|&&(ref x, ref y)| *x == 0).copied().collect();
178178
//~^ manual_retain
179179
tuples = tuples.iter().filter(|(x, y)| *x == 0).copied().collect();
180180
//~^ manual_retain
@@ -228,7 +228,7 @@ fn vec_retain() {
228228

229229
// Do lint, because we use pattern matching
230230
let mut tuples = vec![(0, 1), (1, 2), (2, 3)];
231-
tuples = tuples.iter().filter(|(ref x, ref y)| *x == 0).copied().collect();
231+
tuples = tuples.iter().filter(|&&(ref x, ref y)| *x == 0).copied().collect();
232232
//~^ manual_retain
233233
tuples = tuples.iter().filter(|(x, y)| *x == 0).copied().collect();
234234
//~^ manual_retain

tests/ui/manual_retain.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ LL | binary_heap = binary_heap.iter().filter(|&x| x % 2 == 0).cloned().colle
2222
error: this expression can be written more simply using `.retain()`
2323
--> tests/ui/manual_retain.rs:34:5
2424
|
25-
LL | tuples = tuples.iter().filter(|(ref x, ref y)| *x == 0).copied().collect();
26-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(ref x, ref y)| *x == 0)`
25+
LL | tuples = tuples.iter().filter(|&&(ref x, ref y)| *x == 0).copied().collect();
26+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|&(ref x, ref y)| *x == 0)`
2727

2828
error: this expression can be written more simply using `.retain()`
2929
--> tests/ui/manual_retain.rs:36:5
@@ -74,8 +74,8 @@ LL | btree_set = btree_set.into_iter().filter(|x| x % 2 == 0).collect();
7474
error: this expression can be written more simply using `.retain()`
7575
--> tests/ui/manual_retain.rs:106:5
7676
|
77-
LL | tuples = tuples.iter().filter(|(ref x, ref y)| *x == 0).copied().collect();
78-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(ref x, ref y)| *x == 0)`
77+
LL | tuples = tuples.iter().filter(|&&(ref x, ref y)| *x == 0).copied().collect();
78+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|&(ref x, ref y)| *x == 0)`
7979

8080
error: this expression can be written more simply using `.retain()`
8181
--> tests/ui/manual_retain.rs:108:5
@@ -126,8 +126,8 @@ LL | hash_set = hash_set.iter().filter(|&x| x % 2 == 0).cloned().collect();
126126
error: this expression can be written more simply using `.retain()`
127127
--> tests/ui/manual_retain.rs:177:5
128128
|
129-
LL | tuples = tuples.iter().filter(|(ref x, ref y)| *x == 0).copied().collect();
130-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(ref x, ref y)| *x == 0)`
129+
LL | tuples = tuples.iter().filter(|&&(ref x, ref y)| *x == 0).copied().collect();
130+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|&(ref x, ref y)| *x == 0)`
131131

132132
error: this expression can be written more simply using `.retain()`
133133
--> tests/ui/manual_retain.rs:179:5
@@ -162,8 +162,8 @@ LL | vec = vec.into_iter().filter(|x| x % 2 == 0).collect();
162162
error: this expression can be written more simply using `.retain()`
163163
--> tests/ui/manual_retain.rs:231:5
164164
|
165-
LL | tuples = tuples.iter().filter(|(ref x, ref y)| *x == 0).copied().collect();
166-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(ref x, ref y)| *x == 0)`
165+
LL | tuples = tuples.iter().filter(|&&(ref x, ref y)| *x == 0).copied().collect();
166+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|&(ref x, ref y)| *x == 0)`
167167

168168
error: this expression can be written more simply using `.retain()`
169169
--> tests/ui/manual_retain.rs:233:5

tests/ui/needless_borrowed_ref.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ fn should_not_lint(
8989
tuple_struct: TupleStruct,
9090
s: Struct,
9191
) {
92-
if let [ref a] = slice {}
92+
if let [a] = slice {}
9393
if let &[ref a, b] = slice {}
9494
if let &[ref a, .., b] = slice {}
9595

tests/ui/needless_borrowed_ref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ fn should_not_lint(
8989
tuple_struct: TupleStruct,
9090
s: Struct,
9191
) {
92-
if let [ref a] = slice {}
92+
if let [a] = slice {}
9393
if let &[ref a, b] = slice {}
9494
if let &[ref a, .., b] = slice {}
9595

0 commit comments

Comments
 (0)