Guest User

Untitled

a guest
Jan 19th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #![allow(unreachable_code)]
  2.  
  3.  
  4. fn main() {
  5. println!("{:?}", {
  6. trait AnyDebug { fn as_debug(&self) -> Option<&dyn std::fmt::Debug> { None } } #[derive(Debug)] struct S; impl AnyDebug for S { fn as_debug(&self) -> Option<&dyn std::fmt::Debug> { Some(self) } } let b: Box<dyn AnyDebug> = Box::new(S); println!("{:?}", b.as_debug().unwrap()); struct S2; let b: Box<dyn AnyDebug> = Box::new(S2); println!("{:?}", b.as_debug());
  7. });
  8. }
  9.  
  10.  
  11. /* ~~~~=== stderr ===~~~~
  12. Compiling playground v0.0.1 (/playground)
  13. error[E0277]: the trait bound `main::S2: main::AnyDebug` is not satisfied
  14. --> src/main.rs:6:324
  15. |
  16. 6 | trait AnyDebug { fn as_debug(&self) -> Option<&dyn std::fmt::Debug> { None } } #[derive(Debug)] struct S; impl AnyDebug for S { fn as_debug(&self) -> Option<&dyn std::fmt::Debug> { Some(self) } } let b: Box<dyn AnyDebug> = Box::new(S); println!("{:?}", b.as_debug().unwrap()); struct S2; let b: Box<dyn AnyDebug> = Box::new(S2); println!("{:?}", b.as_debug());
  17. | ^^^^^^^^^^^^ the trait `main::AnyDebug` is not implemented for `main::S2`
  18. |
  19. = note: required for the cast to the object type `dyn main::AnyDebug`
  20.  
  21. error: aborting due to previous error
  22.  
  23. For more information about this error, try `rustc --explain E0277`.
  24. error: Could not compile `playground`.
  25.  
  26. To learn more, run the command again with --verbose.
  27.  
  28. */
  29.  
  30. /* ~~~~=== stdout ===~~~~
  31.  
  32. */
Add Comment
Please, Sign In to add comment