Guest User

Untitled

a guest
Jun 23rd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. fn main() {
  2. println!("{:?}", {
  3. (&[1, 2, 3]).iter().map(|&x: usize| x*2).sum() as usize
  4. });
  5. }
  6.  
  7.  
  8. /* ~~~~=== stderr ===~~~~
  9. Compiling playground v0.0.1 (file:///playground)
  10. error[E0308]: mismatched types
  11. --> src/main.rs:5:34
  12. |
  13. 5 | (&[1, 2, 3]).iter().map(|&x: usize| x*2).sum() as usize
  14. | ^^ expected usize, found reference
  15. |
  16. = note: expected type `usize`
  17. found type `&_`
  18. = help: did you mean `x: &usize`?
  19.  
  20. error[E0631]: type mismatch in closure arguments
  21. --> src/main.rs:5:29
  22. |
  23. 5 | (&[1, 2, 3]).iter().map(|&x: usize| x*2).sum() as usize
  24. | ^^^ --------------- found signature of `fn(usize) -> _`
  25. | |
  26. | expected signature of `fn(&{integer}) -> _`
  27.  
  28. 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
  29. --> src/main.rs:5:50
  30. |
  31. 5 | (&[1, 2, 3]).iter().map(|&x: usize| x*2).sum() as usize
  32. | ^^^
  33. |
  34. = note: the method `sum` exists but the following trait bounds were not satisfied:
  35. `std::iter::Map<std::slice::Iter<'_, {integer}>, [closure@src/main.rs:5:33: 5:48]> : std::iter::Iterator`
  36. `&mut std::iter::Map<std::slice::Iter<'_, {integer}>, [closure@src/main.rs:5:33: 5:48]> : std::iter::Iterator`
  37.  
  38. error: aborting due to 3 previous errors
  39.  
  40. Some errors occurred: E0308, E0599, E0631.
  41. For more information about an error, try `rustc --explain E0308`.
  42. error: Could not compile `playground`.
  43.  
  44. To learn more, run the command again with --verbose.
  45.  
  46. */
  47.  
  48. /* ~~~~=== stdout ===~~~~
  49.  
  50. */
Add Comment
Please, Sign In to add comment