Guest User

Untitled

a guest
Jun 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. trait Closure<'t> {}
  2. impl<'t, F: Fn(&'t ())> Closure<'t> for F {}
  3.  
  4. fn restrict_fn(_: impl Fn(&'static ())) {}
  5. fn restrict_trait(_: impl Closure<'static>) {}
  6.  
  7. fn check(_: &'static ()) {}
  8.  
  9. fn main() {
  10. // OK 4/4
  11. restrict_fn(|r| check(r));
  12. restrict_fn(|r: &_| check(r));
  13. restrict_fn(|r: &()| check(r));
  14. restrict_fn(|r: &'static ()| check(r));
  15.  
  16. // OK 2/4
  17. restrict_trait(|r| check(r));
  18. restrict_trait(|r: &_| check(r)); // FAIL: lifetime of reference outlives lifetime of borrowed content
  19. // restrict_trait(|r: &()| check(r)); // also FAIL
  20. restrict_trait(|r: &'static ()| check(r));
  21. }
Add Comment
Please, Sign In to add comment