Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![feature(stmt_expr_attributes)]
- use std::marker::PhantomData;
- trait Foo<'a> {
- type Item;
- fn consume<F>(self, f: F) where F: Fn(Self::Item);
- }
- struct Consume<A>(PhantomData<A>);
- impl<'a, A:'a> Foo<'a> for Consume<A> {
- type Item = &'a A;
- fn consume<F>(self, _f: F) where F: Fn(Self::Item) {
- if blackbox() {
- #[cfg(not(removal_1))]
- _f(any());
- }
- }
- }
- #[derive(Clone)]
- struct Wrap<T> { foo: T }
- impl<T: for <'a> Foo<'a>> Wrap<T> {
- fn consume<F>(self, f: F) where F: for <'b> Fn(<T as Foo<'b>>::Item) {
- self.foo.consume(f);
- }
- }
- fn main() {
- // This works
- Consume(PhantomData::<u32>).consume(|item| { let _a = item; });
- // This does not (but is only noticed if you call the closure).
- let _wrap = Wrap { foo: Consume(PhantomData::<u32>,) };
- #[cfg(not(removal_2))]
- _wrap.consume(|item| { let _a = item; });
- }
- pub static mut FLAG: bool = false;
- fn blackbox() -> bool { unsafe { FLAG } }
- fn any<T>() -> T { loop { } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement