daily pastebin goal
22%
SHARE
TWEET

Untitled

a guest Mar 22nd, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct ImmutableCovariant;
  2. impl<'s> ImmutableCovariant {
  3.    
  4.     fn smaller<'a>(v: &'s &'a i32) {
  5.     }
  6.    
  7.     fn bigger(v: &'s &'static i32) {
  8.         Self::smaller(v);
  9.     }
  10. }
  11.  
  12. struct ImmutableContravariantFAILS;
  13. impl<'s> ImmutableContravariantFAILS {
  14.     fn smaller<'a>(v: &'s &'a i32) {
  15.         Self::bigger(v);
  16.     }
  17.  
  18.     fn bigger(v: &'s &'static i32) {
  19.     }
  20. }
  21.  
  22. // This should fail!
  23. struct MutableCovariantSUCCEEDS;
  24. impl<'s> MutableCovariantSUCCEEDS {
  25.    
  26.     fn smaller<'a>(v: &'s mut &'a i32) {
  27.     }
  28.    
  29.     fn bigger(v: &'s mut &'static i32) {
  30.         Self::smaller(v);
  31.     }
  32. }
  33.  
  34. struct MutableContravariantFAILS;
  35. impl<'s> MutableContravariantFAILS {
  36.     fn smaller<'a>(v: &'s mut &'a i32) {
  37.         Self::bigger(v);
  38.     }
  39.  
  40.     fn bigger(v: &'s mut &'static i32) {
  41.     }
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top