Advertisement
Guest User

Untitled

a guest
May 25th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #![feature(stmt_expr_attributes)]
  2. use std::marker::PhantomData;
  3.  
  4. trait Foo<'a> {
  5. type Item;
  6. fn consume<F>(self, f: F) where F: Fn(Self::Item);
  7. }
  8. struct Consume<A>(PhantomData<A>);
  9.  
  10. impl<'a, A:'a> Foo<'a> for Consume<A> {
  11. type Item = &'a A;
  12.  
  13. fn consume<F>(self, _f: F) where F: Fn(Self::Item) {
  14. if blackbox() {
  15. #[cfg(not(removal_1))]
  16. _f(any());
  17. }
  18. }
  19. }
  20.  
  21. #[derive(Clone)]
  22. struct Wrap<T> { foo: T }
  23.  
  24. impl<T: for <'a> Foo<'a>> Wrap<T> {
  25. fn consume<F>(self, f: F) where F: for <'b> Fn(<T as Foo<'b>>::Item) {
  26. self.foo.consume(f);
  27. }
  28. }
  29.  
  30. fn main() {
  31. // This works
  32. Consume(PhantomData::<u32>).consume(|item| { let _a = item; });
  33.  
  34. // This does not (but is only noticed if you call the closure).
  35. let _wrap = Wrap { foo: Consume(PhantomData::<u32>,) };
  36. #[cfg(not(removal_2))]
  37. _wrap.consume(|item| { let _a = item; });
  38. }
  39.  
  40. pub static mut FLAG: bool = false;
  41. fn blackbox() -> bool { unsafe { FLAG } }
  42. fn any<T>() -> T { loop { } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement