Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn main() {
- println!("{:?}", {
- (&[1, 2, 3]).iter().map(|&x: usize| x*2).sum() as usize
- });
- }
- /* ~~~~=== stderr ===~~~~
- Compiling playground v0.0.1 (file:///playground)
- error[E0308]: mismatched types
- --> src/main.rs:5:34
- |
- 5 | (&[1, 2, 3]).iter().map(|&x: usize| x*2).sum() as usize
- | ^^ expected usize, found reference
- |
- = note: expected type `usize`
- found type `&_`
- = help: did you mean `x: &usize`?
- error[E0631]: type mismatch in closure arguments
- --> src/main.rs:5:29
- |
- 5 | (&[1, 2, 3]).iter().map(|&x: usize| x*2).sum() as usize
- | ^^^ --------------- found signature of `fn(usize) -> _`
- | |
- | expected signature of `fn(&{integer}) -> _`
- error[E0599]: no method named `sum` found for type `std::iter::Map<std::slice::Iter<'_, {integer}>, [closure@src/main.rs:5:33: 5:48]>` in the current scope
- --> src/main.rs:5:50
- |
- 5 | (&[1, 2, 3]).iter().map(|&x: usize| x*2).sum() as usize
- | ^^^
- |
- = note: the method `sum` exists but the following trait bounds were not satisfied:
- `std::iter::Map<std::slice::Iter<'_, {integer}>, [closure@src/main.rs:5:33: 5:48]> : std::iter::Iterator`
- `&mut std::iter::Map<std::slice::Iter<'_, {integer}>, [closure@src/main.rs:5:33: 5:48]> : std::iter::Iterator`
- error: aborting due to 3 previous errors
- Some errors occurred: E0308, E0599, E0631.
- For more information about an error, try `rustc --explain E0308`.
- error: Could not compile `playground`.
- To learn more, run the command again with --verbose.
- */
- /* ~~~~=== stdout ===~~~~
- */
Add Comment
Please, Sign In to add comment