Skip to content

Commit 67a0891

Browse files
committed
Auto merge of #8880 - hellow554:rustfix_update, r=Manishearth
Add some testcases for recent rustfix update changelog: none This adds a testcase for a bugfix that has been fixed by https://github.com/rust-lang/rustfix/tree/v0.6.1 `rustfix` is pulled in by `compiletest_rs`. So to test that the correct rustfix version is used, I added one (and a half) testcase. I tried to add a testcase for #8734 as well, but interesting enough the rustfix is wrong: ```diff fn issue8734() { let _ = [0u8, 1, 2, 3] .into_iter() - .and_then(|n| match n { + .flat_map(|n| match n { + 1 => [n + .saturating_add(1) 1 => [n .saturating_add(1) .saturating_add(1) .saturating_add(1) .saturating_add(1) .saturating_add(1) .saturating_add(1) .saturating_add(1) .saturating_add(1)], n => [n], }); } ``` this needs some investigation and then this testcase needs to be enabled by commenting it out closes #8878 related to #8734
2 parents c41c410 + 04297de commit 67a0891

File tree

3 files changed

+100
-1
lines changed

3 files changed

+100
-1
lines changed

tests/ui/map_flatten_fixable.fixed

+37
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,41 @@ fn main() {
2828

2929
// mapping to Result on Result
3030
let _: Result<_, &str> = (Ok(Ok(1))).and_then(|x| x);
31+
32+
issue8734();
33+
issue8878();
34+
}
35+
36+
fn issue8734() {
37+
// let _ = [0u8, 1, 2, 3]
38+
// .into_iter()
39+
// .map(|n| match n {
40+
// 1 => [n
41+
// .saturating_add(1)
42+
// .saturating_add(1)
43+
// .saturating_add(1)
44+
// .saturating_add(1)
45+
// .saturating_add(1)
46+
// .saturating_add(1)
47+
// .saturating_add(1)
48+
// .saturating_add(1)],
49+
// n => [n],
50+
// })
51+
// .flatten();
52+
}
53+
54+
#[allow(clippy::bind_instead_of_map)] // map + flatten will be suggested to `and_then`, but afterwards `map` is suggested again
55+
#[rustfmt::skip] // whitespace is important for this one
56+
fn issue8878() {
57+
std::collections::HashMap::<u32, u32>::new()
58+
.get(&0)
59+
.and_then(|_| {
60+
// we need some newlines
61+
// so that the span is big enough
62+
// we need some newlines
63+
// so that the span is big enough
64+
// for a splitted output of the diagnostic
65+
Some("")
66+
// whitespace beforehand is important as well
67+
});
3168
}

tests/ui/map_flatten_fixable.rs

+36
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,40 @@ fn main() {
2828

2929
// mapping to Result on Result
3030
let _: Result<_, &str> = (Ok(Ok(1))).map(|x| x).flatten();
31+
32+
issue8734();
33+
issue8878();
34+
}
35+
36+
fn issue8734() {
37+
// let _ = [0u8, 1, 2, 3]
38+
// .into_iter()
39+
// .map(|n| match n {
40+
// 1 => [n
41+
// .saturating_add(1)
42+
// .saturating_add(1)
43+
// .saturating_add(1)
44+
// .saturating_add(1)
45+
// .saturating_add(1)
46+
// .saturating_add(1)
47+
// .saturating_add(1)
48+
// .saturating_add(1)],
49+
// n => [n],
50+
// })
51+
// .flatten();
52+
}
53+
54+
#[allow(clippy::bind_instead_of_map)] // map + flatten will be suggested to `and_then`, but afterwards `map` is suggested again
55+
#[rustfmt::skip] // whitespace is important for this one
56+
fn issue8878() {
57+
std::collections::HashMap::<u32, u32>::new()
58+
.get(&0)
59+
.map(|_| {
60+
// we need some newlines
61+
// so that the span is big enough
62+
// for a splitted output of the diagnostic
63+
Some("")
64+
// whitespace beforehand is important as well
65+
})
66+
.flatten();
3167
}

tests/ui/map_flatten_fixable.stderr

+27-1
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,31 @@ help: try replacing `map` with `and_then`, and remove the `.flatten()`
7676
LL | let _: Result<_, &str> = (Ok(Ok(1))).and_then(|x| x);
7777
| ~~~~~~~~~~~~~~~
7878

79-
error: aborting due to 7 previous errors
79+
error: called `map(..).flatten()` on `Option`
80+
--> $DIR/map_flatten_fixable.rs:59:10
81+
|
82+
LL | .map(|_| {
83+
| __________^
84+
LL | | // we need some newlines
85+
LL | | // so that the span is big enough
86+
LL | | // for a splitted output of the diagnostic
87+
... |
88+
LL | | })
89+
LL | | .flatten();
90+
| |__________________^
91+
|
92+
help: try replacing `map` with `and_then`
93+
|
94+
LL ~ .and_then(|_| {
95+
LL + // we need some newlines
96+
LL + // so that the span is big enough
97+
|
98+
help: and remove the `.flatten()`
99+
|
100+
LL + Some("")
101+
LL + // whitespace beforehand is important as well
102+
LL ~ });
103+
|
104+
105+
error: aborting due to 8 previous errors
80106

0 commit comments

Comments
 (0)