Skip to content

Commit

Permalink
add more test for manual_repeat_n
Browse files Browse the repository at this point in the history
  • Loading branch information
lapla-cogito committed Dec 20, 2024
1 parent 87082a2 commit 546bbf1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
8 changes: 5 additions & 3 deletions tests/ui/manual_repeat_n.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ fn main() {
let _ = std::iter::repeat_n(vec![1, 2], 2);
}

mod external_lib {
mod foo_lib {
pub fn iter() -> std::iter::Take<std::iter::Repeat<&'static [u8]>> {
todo!()
}
}

fn foo() {
let _ = match 1 {
1 => external_lib::iter(),
2 => std::iter::repeat_n([1, 2].as_slice(), 2), // can't really change this to repeat_n
1 => foo_lib::iter(),
// Shouldn't lint because `external_lib::iter` doesn't return `std::iter::RepeatN`.
2 => std::iter::repeat([1, 2].as_slice()).take(2),
_ => todo!(),
};
}
4 changes: 2 additions & 2 deletions tests/ui/manual_repeat_n.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ mod foo_lib {
fn foo() {
let _ = match 1 {
1 => foo_lib::iter(),
2 => std::iter::repeat([1, 2].as_slice()).take(2), /* Shouldn't lint because `external_lib::iter` doesn't */
// return `std::iter::RepeatN`.
// Shouldn't lint because `external_lib::iter` doesn't return `std::iter::RepeatN`.
2 => std::iter::repeat([1, 2].as_slice()).take(2),
_ => todo!(),
};
}
8 changes: 1 addition & 7 deletions tests/ui/manual_repeat_n.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,5 @@ error: this `.repeat().take()` can be written more concisely
LL | let _ = repeat(vec![1, 2]).take(2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `repeat_n()` instead: `std::iter::repeat_n(vec![1, 2], 2)`

error: this `.repeat().take()` can be written more concisely
--> tests/ui/manual_repeat_n.rs:25:14
|
LL | 2 => std::iter::repeat([1, 2].as_slice()).take(2), // can't really change this to repeat_n
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `repeat_n()` instead: `std::iter::repeat_n([1, 2].as_slice(), 2)`

error: aborting due to 6 previous errors
error: aborting due to 5 previous errors

0 comments on commit 546bbf1

Please sign in to comment.