Experiment: mark derived Clone impls as const#93255
Experiment: mark derived Clone impls as const#93255clarfonthey wants to merge 1 commit intorust-lang:masterfrom
Conversation
|
r? @estebank (rust-highfive has picked a reviewer for you, use r? to override) |
9de2ef0 to
5c46ec4
Compare
This comment has been minimized.
This comment has been minimized.
5c46ec4 to
eaef54d
Compare
|
Even though it currently builds and the test passes, I'm going to leave this marked as a draft since I think it still could use some feedback in terms of how it's done (this is my first time changing any compiler code) and also just, the way it works in general. |
|
r? @oli-obk |
library/core/src/clone.rs
Outdated
There was a problem hiding this comment.
does this show up in rustdoc?
oli-obk
left a comment
There was a problem hiding this comment.
The main problem with this approach is that it is a breaking change for
struct Foo;
impl Clone for Foo {
fn clone(&self) -> Self { Foo }
}
#[derive(Clone)]
struct Bar(Foo);Thus the only way we can ever really make derives work, is by opting in, meaning something like #[derive(const Clone)]. This has been discussed in https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/syntax.2Fgrammar.3A.20deriving.20const.20traits
The discussion there isn't yet clear on the syntax, so I'm not sure how to proceed here.
|
That's very fair; I think that the As you probably noticed in the code itself, what is probably a bigger concern is how to annotate the derived |
eaef54d to
9fd85da
Compare
This comment has been minimized.
This comment has been minimized.
|
(Will properly rebase later; am glad the error messages improved.) |
9fd85da to
3068dcc
Compare
|
☔ The latest upstream changes (presumably #94787) made this pull request unmergeable. Please resolve the merge conflicts. |
|
Gonna close since this needs a redesign anyway. |
This is an attempt to lay the foundation for marking
#[derive]d trait impls as const. Right now, only trivialCloneimpls (*self) are marked as const, but in the future, more complicated impls likePartialEqandPartialOrdcould be marked asconstas well.This mostly just modifies the
TraitDefstruct inrustc_builtin_macrosto allow marking traits as const. For now, only theCloneimplementations are marked as const since they're the simplest, to prove that the feature works.This also augments the existing
Clonederive test to check that the generated impls can be const.