-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document that associated constants prevent a trait from being made into an object #48026
Conversation
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
1a3239b
to
78ea7ee
Compare
The reason is that because the trait object implements the trait too, and what would the constant be for that trait object? E.g. given a trait fn takes_trait_obj(t: &dyn Trait) -> i32 { <dyn Trait>::CONST } Or as another (I think it was @eddyb?) said on IRC, a constant is effectively a no-argument static (const) function, and static functions aren't allowed for the same reason. |
The explaination makes sense, especially when compared to static functions. It's a shame you can't add |
78ea7ee
to
498ef20
Compare
@Badel2 once the GAT work is fully done, we can probably support that, actually ( |
@bors r+ rollup |
📌 Commit 498ef20 has been approved by |
Wait, why does |
… r=nikomatsakis Document that associated constants prevent a trait from being made into an object Fixes rust-lang#47952 Add a short mention of associated constants to E0038
@eddyb it's not particularly dependent on GAT per se, but right now we don't have a notion of "where clauses that must be satisfied in order to project" -- I expect to be adding that as part of GAT, in which case it would apply here. Note the sort of subtle distinction between: trait Foo {
type Bar: Baz;
} This is a constraint on the impl that it supply a type that is trait Foo {
type Bar where Self: Sized;
} This is a constraint on the one doing the projection that |
@nikomatsakis We have them on methods and we check them when referring to those methods. |
Fixes #47952
Add a short mention of associated constants to E0038