Skip to content

Instantly share code, notes, and snippets.

@iximeow
Last active September 6, 2015 20:29
Show Gist options
  • Select an option

  • Save iximeow/a88b75187dabbe9af83e to your computer and use it in GitHub Desktop.

Select an option

Save iximeow/a88b75187dabbe9af83e to your computer and use it in GitHub Desktop.
high quality rust: beware
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 {}
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 {}
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