daily pastebin goal
42%
SHARE
TWEET

Untitled

a guest May 16th, 2018 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top