Last active
May 25, 2016 15:48
-
-
Save pnkfelix/74440e047d26c0a410ce5fc74204962c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![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 { } } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(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.)