-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Make some Clone
impls const
#91804
Make some Clone
impls const
#91804
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
r? @oli-obk maybe? |
#[rustc_const_unstable(feature = "const_clone", issue = "91805")] | ||
impl<T> const Clone for Option<T> | ||
where | ||
T: ~const Clone + ~const Drop, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this change the way rustdoc renders it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yea, there's a pending fix for the missing space, but the additional Drop
bound is really confusing for users and we should probably figure out out story there (both for documentation and explanation) before we expose it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will all such cases need to be explained in the future? It seems a bit hard... I think it would be nice if we could switch displaying of ~const
(and ~const Drop
) bound...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I'm unsure about ~const
bounds in general, we should probably talk to the rustdoc team to figure out how it should display.
For ~const Drop
I think we should just hide it from rustdoc. That bound is pretty much useless to see for anyone. We could potentially add a small symbol to the generic param that has a ~const Drop
bound. Otherwise I fear that the useful bounds may get drowned out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
T: ~const Drop
seems to mean "T doesn't require non-const Drop
to destruct the value", not "T implements ~const Drop
". For example, primitive types don't implement const Drop
but are destructible at compile-time. Anyway, the point is that this is mostly needed in code that destructs values at compile-time and is implemented using generics.
The determination seems to be implemented here:
https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs#L140
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
T: ~const Drop
seems to mean "T doesn't require non-constDrop
to destruct the value"
I'm a bit confused about what you mean. Do you mean "T
must be able to be Drop
ed at compile-time"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I'm sorry for confusing you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does the ~
mean? I thought ~const
meant "maybe const" rather than "definitely const", but I may have misunderstood.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It means "const if whatever the bound is on is in a const context". So if it's on a generic param of a const fn, calling that const fn in a const item or other const context requires the generic param to implement the trait constly, in regular runtime code it just requires the trait to be implemented with no requirement about constness at all
This should be hidden from rustdoc now, and it doesn't introduce any new bounds that would not be hidden, so @bors r+ rollup |
📌 Commit 6620244 has been approved by |
Make some `Clone` impls `const` Tracking issue: rust-lang#91805 `Clone::clone_from` and some impls (Option, Result) bounded on `~const Drop`. ```rust // core::clone impl const Clone for INTEGER impl const Clone for FLOAT impl const Clone for bool impl const Clone for char impl const Clone for ! impl<T: ?Sized> const Clone for *const T impl<T: ?Sized> const Clone for *mut T impl<T: ?Sized> const Clone for &T // core::option impl<T> const Clone for Option<T> where T: ~const Clone + ~const Drop // core::result impl<T, E> const Clone for Result<T, E> where T: ~const Clone + ~const Drop, E: ~const Clone + ~const Drop, // core::convert impl const Clone for Infallible // core::ptr impl<T: ?Sized> const Clone for NonNull<T> impl<T: ?Sized> const Clone for Unique<T> ```
Make some `Clone` impls `const` Tracking issue: rust-lang#91805 `Clone::clone_from` and some impls (Option, Result) bounded on `~const Drop`. ```rust // core::clone impl const Clone for INTEGER impl const Clone for FLOAT impl const Clone for bool impl const Clone for char impl const Clone for ! impl<T: ?Sized> const Clone for *const T impl<T: ?Sized> const Clone for *mut T impl<T: ?Sized> const Clone for &T // core::option impl<T> const Clone for Option<T> where T: ~const Clone + ~const Drop // core::result impl<T, E> const Clone for Result<T, E> where T: ~const Clone + ~const Drop, E: ~const Clone + ~const Drop, // core::convert impl const Clone for Infallible // core::ptr impl<T: ?Sized> const Clone for NonNull<T> impl<T: ?Sized> const Clone for Unique<T> ```
Make some `Clone` impls `const` Tracking issue: rust-lang#91805 `Clone::clone_from` and some impls (Option, Result) bounded on `~const Drop`. ```rust // core::clone impl const Clone for INTEGER impl const Clone for FLOAT impl const Clone for bool impl const Clone for char impl const Clone for ! impl<T: ?Sized> const Clone for *const T impl<T: ?Sized> const Clone for *mut T impl<T: ?Sized> const Clone for &T // core::option impl<T> const Clone for Option<T> where T: ~const Clone + ~const Drop // core::result impl<T, E> const Clone for Result<T, E> where T: ~const Clone + ~const Drop, E: ~const Clone + ~const Drop, // core::convert impl const Clone for Infallible // core::ptr impl<T: ?Sized> const Clone for NonNull<T> impl<T: ?Sized> const Clone for Unique<T> ```
…askrgr Rollup of 8 pull requests Successful merges: - rust-lang#91804 (Make some `Clone` impls `const`) - rust-lang#92541 (Mention intent of `From` trait in its docs) - rust-lang#93057 (Add Iterator::collect_into) - rust-lang#94739 (Suggest `if let`/`let_else` for refutable pat in `let`) - rust-lang#94754 (Warn users about `||` in let chain expressions) - rust-lang#94763 (Add documentation about lifetimes to thread::scope.) - rust-lang#94768 (Ignore `close_read_wakes_up` test on SGX platform) - rust-lang#94772 (Add miri to the well known conditional compilation names and values) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
…st Clone` `Clone::clone_from` gained `#[default_method_body_is_const]` in [rust-lang/rust#91804][1]. n.b. `vec.rs` is shared by `r3_core` and `r3_kernel` (via a symbolic link), hence the lack of a scope in the commit message headline. [1]: rust-lang/rust#91804
Tracking issue: #91805
Clone::clone_from
and some impls (Option, Result) bounded on~const Drop
.