Guest User

Untitled

a guest
Jul 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. fn main() {
  2. println!("{:?}", {
  3. fn foo(a: Option<i32>, b: Option<i32>) -> Option<i32> { let c = (|| a? + b?); c }
  4. });
  5. }
  6.  
  7.  
  8. /* ~~~~=== stderr ===~~~~
  9. Compiling playground v0.0.1 (file:///playground)
  10. warning: unnecessary parentheses around assigned value
  11. --> src/main.rs:5:73
  12. |
  13. 5 | fn foo(a: Option<i32>, b: Option<i32>) -> Option<i32> { let c = (|| a? + b?); c }
  14. | ^^^^^^^^^^^^ help: remove these parentheses
  15. |
  16. = note: #[warn(unused_parens)] on by default
  17.  
  18. error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
  19. --> src/main.rs:5:77
  20. |
  21. 5 | fn foo(a: Option<i32>, b: Option<i32>) -> Option<i32> { let c = (|| a? + b?); c }
  22. | ^^ cannot use the `?` operator in a function that returns `i32`
  23. |
  24. = help: the trait `std::ops::Try` is not implemented for `i32`
  25. = note: required by `std::ops::Try::from_error`
  26.  
  27. error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
  28. --> src/main.rs:5:82
  29. |
  30. 5 | fn foo(a: Option<i32>, b: Option<i32>) -> Option<i32> { let c = (|| a? + b?); c }
  31. | ^^ cannot use the `?` operator in a function that returns `i32`
  32. |
  33. = help: the trait `std::ops::Try` is not implemented for `i32`
  34. = note: required by `std::ops::Try::from_error`
  35.  
  36. error[E0308]: mismatched types
  37. --> src/main.rs:5:87
  38. |
  39. 5 | fn foo(a: Option<i32>, b: Option<i32>) -> Option<i32> { let c = (|| a? + b?); c }
  40. | ----------- ^ expected enum `std::option::Option`, found closure
  41. | |
  42. | expected `std::option::Option<i32>` because of return type
  43. |
  44. = note: expected type `std::option::Option<i32>`
  45. found type `[closure@src/main.rs:5:73: 5:85 a:_, b:_]`
  46.  
  47. error: aborting due to 3 previous errors
  48.  
  49. Some errors occurred: E0277, E0308.
  50. For more information about an error, try `rustc --explain E0277`.
  51. error: Could not compile `playground`.
  52.  
  53. To learn more, run the command again with --verbose.
  54.  
  55. */
  56.  
  57. /* ~~~~=== stdout ===~~~~
  58.  
  59. */
Add Comment
Please, Sign In to add comment