Skip to content

Instantly share code, notes, and snippets.

@pnkfelix
Last active May 25, 2016 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pnkfelix/74440e047d26c0a410ce5fc74204962c to your computer and use it in GitHub Desktop.
Save pnkfelix/74440e047d26c0a410ce5fc74204962c to your computer and use it in GitHub Desktop.
#![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 { } }
@pnkfelix
Copy link
Author

(i made some small edits but worked to make sure that lines 24 and 25 remain at the same spot, since they are the main things I want to discuss. I did alpha-rename the 'a in line 25 to 'b to hopefully make it easier to discuss the distinction between the two lines.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment