Closed
Description
Here's a program that we expect to fail to compile, and happily it does fail to compile:
trait Foo {}
struct Bar(Vec<Foo>); // uh-oh
fn main() {}
Here's the happy error message:
error[E0277]: the trait bound `Foo + 'static: std::marker::Sized` is not satisfied
--> src/main.rs:2:12
|
2 | struct Bar(Vec<Foo>);
| ^^^^^^^^^ `Foo + 'static` does not have a constant size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `Foo + 'static`
= note: required by `std::vec::Vec`
Here's the actual bug: if we use a type alias here rather than a newtype, this does not fail to compile:
trait Foo {}
type Bar = Vec<Foo>; // compiles!
fn main() {}
Fortunately it appears to be impossible to actually instantiate this, but surely this should fail to compile just as the first example does.
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
bstrie commentedon Nov 16, 2017
While mentioning this on IRC @thepowersgang noted that mrustc deliberately doesn't typecheck type alias declarations because it encountered unexpected compilation failures while testing against crates.io. I'm still hopeful that such an invalid declaration would be impossible to instantiate, but it's possible that the failures mrustc encountered were more insidious than the simple test case here. Because of this discovery, nominating for discussion based on the backcompat hazard this might present.
thepowersgang commentedon Nov 16, 2017
Note for the above - The failing code was along the lines of
type Foo<T> = RequiresSomeTrait<T>;
- which failed when trait bounds were checked.petrochenkov commentedon Nov 17, 2017
From RFC 1214:
bstrie commentedon Nov 17, 2017
Interesting. RFC 1214 is tracked at #27579, would be good to know if there's any more clarity since 2015 on how we ought to be handling this.
michaelwoerister commentedon Nov 30, 2017
Discussed during compiler triage. We are closing this as a duplicate of #44075. Thanks, @bstrie!