Closed
Description
These two code snippets should functionally be doing the same thing, but the type checker seems to think one has a destructor. The difference seems to be in the reliance on an associated type.
rustc
complains that myfoo
cannot be declared a mutable static because it has a desctructor:
pub trait Foo {
type FooAssoc;
}
pub struct Bar<F: Foo> {
id: F::FooAssoc
}
pub struct Baz;
impl Foo for Baz {
type FooAssoc = usize;
}
static mut myfoo : Bar<Baz> = Bar { id: 0 };
While this, unsurprisingly, works:
pub struct Bar<A> {
id: A
}
static mut myfoo : Bar<usize> = Bar { id: 0 };
Here are links to non-compiling/compiling examples on play.rust-lang:
- non-working: http://is.gd/BVUqfJ
- working: http://is.gd/lWbhzw