Skip to content

Commit 672d7c0

Browse files
committed
add more tests for manual_repeat_n
1 parent 87082a2 commit 672d7c0

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

tests/ui/manual_repeat_n.fixed

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ fn main() {
1414
let _ = std::iter::repeat_n(vec![1, 2], 2);
1515
}
1616

17-
mod external_lib {
17+
mod foo_lib {
1818
pub fn iter() -> std::iter::Take<std::iter::Repeat<&'static [u8]>> {
1919
todo!()
2020
}
2121
}
22+
2223
fn foo() {
2324
let _ = match 1 {
24-
1 => external_lib::iter(),
25-
2 => std::iter::repeat_n([1, 2].as_slice(), 2), // can't really change this to repeat_n
25+
1 => foo_lib::iter(),
26+
// Shouldn't lint because `external_lib::iter` doesn't return `std::iter::RepeatN`.
27+
2 => std::iter::repeat([1, 2].as_slice()).take(2),
2628
_ => todo!(),
2729
};
2830
}

tests/ui/manual_repeat_n.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ mod foo_lib {
2323
fn foo() {
2424
let _ = match 1 {
2525
1 => foo_lib::iter(),
26-
2 => std::iter::repeat([1, 2].as_slice()).take(2), /* Shouldn't lint because `external_lib::iter` doesn't */
27-
// return `std::iter::RepeatN`.
26+
// Shouldn't lint because `external_lib::iter` doesn't return `std::iter::RepeatN`.
27+
2 => std::iter::repeat([1, 2].as_slice()).take(2),
2828
_ => todo!(),
2929
};
3030
}

tests/ui/manual_repeat_n.stderr

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,5 @@ error: this `.repeat().take()` can be written more concisely
3131
LL | let _ = repeat(vec![1, 2]).take(2);
3232
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `repeat_n()` instead: `std::iter::repeat_n(vec![1, 2], 2)`
3333

34-
error: this `.repeat().take()` can be written more concisely
35-
--> tests/ui/manual_repeat_n.rs:25:14
36-
|
37-
LL | 2 => std::iter::repeat([1, 2].as_slice()).take(2), // can't really change this to repeat_n
38-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `repeat_n()` instead: `std::iter::repeat_n([1, 2].as_slice(), 2)`
39-
40-
error: aborting due to 6 previous errors
34+
error: aborting due to 5 previous errors
4135

0 commit comments

Comments
 (0)