Last active
September 6, 2015 20:29
-
-
Save iximeow/a88b75187dabbe9af83e to your computer and use it in GitHub Desktop.
high quality rust: beware
This file contains hidden or 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
| fn main() { | |
| let x: &Expr<&ValT> = &Unit::<&ValT> { | |
| expr: &IntValue { size: 5 } | |
| }; | |
| } | |
| trait ValT {} | |
| trait Expr<T> {} | |
| struct Unit<T> { | |
| expr: T | |
| } | |
| struct IntValue { | |
| size: i32 | |
| } | |
| impl<T> Expr<T> for Unit<T> {} | |
| impl ValT for IntValue {} |
This file contains hidden or 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
| fn main() { | |
| let x = &Unit { | |
| expr: Box::new(IntValue { size: 5 }) | |
| }; | |
| // I want to be able to forget about the contained type but | |
| // error: the trait `core::marker::Sized` is not implemented for the type `ValT` | |
| // error: non-scalar cast: `&Unit<IntValue>` as `&Unit<ValT>` | |
| let y = x as &Unit<ValT>; | |
| } | |
| trait ValT {} | |
| trait Expr<T> {} | |
| struct Unit<T> { | |
| expr: Box<T> | |
| } | |
| struct IntValue { | |
| size: i32 | |
| } | |
| impl<T: ValT> Expr<T> for Unit<T> {} | |
| impl ValT for IntValue {} |
This file contains hidden or 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
| fn main() { | |
| // error: the trait `core::marker::Sized` is not implemented for the type `ValT` | |
| // note: `ValT` does not have a constant size known at compile-time | |
| let x: &Expr<ValT> = &Unit::<ValT> { | |
| // ^~~~~~~~~~~~ | |
| expr: &IntValue { size: 5 } | |
| }; | |
| } | |
| trait ValT {} | |
| trait Expr<T> {} | |
| struct Unit<'a, T: 'a> { | |
| expr: &'a T | |
| } | |
| struct IntValue { | |
| size: i32 | |
| } | |
| impl<'a, T> Expr<T> for Unit<'a, T> {} | |
| impl ValT for IntValue {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment