Is it possible to give the compiler type hints in this example using only macros?
Using two macros assert_eq!
and vec!
compiler gives this error:
error[E0282]: type annotations needed
--> src/lib.rs:6:9
|
6 | assert_eq!(chop(&vec![]), vec![]); // error[E0282]: type annotations needed
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
Here is the example code (https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=83886decff48ece2aca3bdb37f7f4d0e):
#[cfg(test)]
mod tests {
#[test]
fn test_chop() {
assert_eq!(chop(&vec![]), Vec::<&[u32]>::new()); // this works
assert_eq!(chop(&vec![]), vec![]); // error[E0282]: type annotations needed
assert_eq!(chop(&vec![1, 1]), vec![[1, 1]]);
assert_eq!(chop(&vec![1, 2, 3, 4]), vec![[1, 2], [3, 4]]);
}
fn chop(rolls: &Vec<u32>) -> Vec<&[u32]> {
rolls.chunks(2).collect()
}
}