Skip to content

Commit b474275

Browse files
committed
Fix turbofish tests to do what they say they do, and add negative variants to make sure the logic is correct
1 parent 966dadc commit b474275

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

tests/ui/unnecessary_fold.fixed

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,17 @@ fn issue10000() {
8787

8888
smoketest_map(HashMap::new());
8989

90-
fn add_no_turbofish_necessary() -> i32 {
90+
fn add_turbofish_not_necessary() -> i32 {
9191
(0..3).sum()
9292
}
93-
fn mul_no_turbofish_necessary() -> i32 {
94-
(0..3).sum()
93+
fn mul_turbofish_not_necessary() -> i32 {
94+
(0..3).product()
95+
}
96+
fn add_turbofish_necessary() -> impl Add {
97+
(0..3).sum::<i32>()
98+
}
99+
fn mul_turbofish_necessary() -> impl Mul {
100+
(0..3).product::<i32>()
95101
}
96102
}
97103

tests/ui/unnecessary_fold.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,18 @@ fn issue10000() {
8787

8888
smoketest_map(HashMap::new());
8989

90-
fn add_no_turbofish_necessary() -> i32 {
90+
fn add_turbofish_not_necessary() -> i32 {
9191
(0..3).fold(0, |acc, x| acc + x)
9292
}
93-
fn mul_no_turbofish_necessary() -> i32 {
93+
fn mul_turbofish_not_necessary() -> i32 {
94+
(0..3).fold(1, |acc, x| acc * x)
95+
}
96+
fn add_turbofish_necessary() -> impl Add {
9497
(0..3).fold(0, |acc, x| acc + x)
9598
}
99+
fn mul_turbofish_necessary() -> impl Mul {
100+
(0..3).fold(1, |acc, x| acc * x)
101+
}
96102
}
97103

98104
fn main() {}

tests/ui/unnecessary_fold.stderr

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,20 @@ LL | (0..3).fold(0, |acc, x| acc + x)
169169
error: this `.fold` can be written more succinctly using another method
170170
--> tests/ui/unnecessary_fold.rs:94:16
171171
|
172+
LL | (0..3).fold(1, |acc, x| acc * x)
173+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `product()`
174+
175+
error: this `.fold` can be written more succinctly using another method
176+
--> tests/ui/unnecessary_fold.rs:97:16
177+
|
172178
LL | (0..3).fold(0, |acc, x| acc + x)
173-
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `sum()`
179+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `sum::<i32>()`
180+
181+
error: this `.fold` can be written more succinctly using another method
182+
--> tests/ui/unnecessary_fold.rs:100:16
183+
|
184+
LL | (0..3).fold(1, |acc, x| acc * x)
185+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `product::<i32>()`
174186

175-
error: aborting due to 28 previous errors
187+
error: aborting due to 30 previous errors
176188

0 commit comments

Comments
 (0)