Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement