Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![allow(unreachable_code)]
- fn main() {
- println!("{:?}", {
- 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());
- });
- }
- /* ~~~~=== stderr ===~~~~
- Compiling playground v0.0.1 (/playground)
- error[E0277]: the trait bound `main::S2: main::AnyDebug` is not satisfied
- --> src/main.rs:6:324
- |
- 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());
- | ^^^^^^^^^^^^ the trait `main::AnyDebug` is not implemented for `main::S2`
- |
- = note: required for the cast to the object type `dyn main::AnyDebug`
- error: aborting due to previous error
- For more information about this error, try `rustc --explain E0277`.
- error: Could not compile `playground`.
- To learn more, run the command again with --verbose.
- */
- /* ~~~~=== stdout ===~~~~
- */
Add Comment
Please, Sign In to add comment