Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![feature(specialization)]
- use std::fmt::Debug;
- trait CanDoFoo {
- fn do_foo(&mut self);
- }
- fn foo() -> impl Debug {
- #[derive(Debug)]
- struct T;
- // Whether this impl is commented out or not decides whether hi is printed.
- // This documents impl Trait leakage of a property of the returned type
- /*
- impl CanDoFoo for T {
- fn do_foo(&mut self) {
- println!("hi");
- }
- }
- */
- T
- }
- fn main() {
- trait MaybeDoFoo {
- fn maybe_do_foo(&mut self);
- }
- impl<T> MaybeDoFoo for T {
- default fn maybe_do_foo(&mut self) { }
- }
- impl<T: CanDoFoo> MaybeDoFoo for T {
- fn maybe_do_foo(&mut self) {
- self.do_foo();
- }
- }
- foo().maybe_do_foo();
- }
Add Comment
Please, Sign In to add comment