Guest User

Untitled

a guest
May 16th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #![feature(specialization)]
  2.  
  3. use std::fmt::Debug;
  4.  
  5. trait CanDoFoo {
  6. fn do_foo(&mut self);
  7. }
  8.  
  9. fn foo() -> impl Debug {
  10. #[derive(Debug)]
  11. struct T;
  12. // Whether this impl is commented out or not decides whether hi is printed.
  13. // This documents impl Trait leakage of a property of the returned type
  14. /*
  15. impl CanDoFoo for T {
  16. fn do_foo(&mut self) {
  17. println!("hi");
  18. }
  19. }
  20. */
  21. T
  22. }
  23.  
  24. fn main() {
  25. trait MaybeDoFoo {
  26. fn maybe_do_foo(&mut self);
  27. }
  28. impl<T> MaybeDoFoo for T {
  29. default fn maybe_do_foo(&mut self) { }
  30. }
  31. impl<T: CanDoFoo> MaybeDoFoo for T {
  32. fn maybe_do_foo(&mut self) {
  33. self.do_foo();
  34. }
  35. }
  36. foo().maybe_do_foo();
  37. }
Add Comment
Please, Sign In to add comment