-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Make Default
const and add some const Default
impls
#134628
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
base: master
Are you sure you want to change the base?
Conversation
r? @wesleywiser rustbot has assigned @wesleywiser. Use |
Made this for some experiments with default field values, might as well put it somewhere visible as it seems like an obvious next step for the const traits effort. |
Please make sure this is assigned to someone on @rust-lang/project-const-traits if you take this out of draft. |
This comment has been minimized.
This comment has been minimized.
f36f4d5
to
00b0c75
Compare
00b0c75
to
d7cfdf5
Compare
☔ The latest upstream changes (presumably #134716) made this pull request unmergeable. Please resolve the merge conflicts. |
d7cfdf5
to
4f6558b
Compare
r? @oli-obk Let me know what would be needed to make this merge-ready. |
I'd like to block this on #133999. |
3a03fb5
to
78db9d1
Compare
This comment has been minimized.
This comment has been minimized.
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
☔ The latest upstream changes (presumably #137752) made this pull request unmergeable. Please resolve the merge conflicts. |
This was blocked on #133999 (comment) which is now closed. @fee1-dead are you still interested in working on a follow-up to #133999 or are there other plans? Or no plans for now? Just to get a clearer picture of the progress here :-) Thanks cc @oli-obk |
Is it still blocked? |
Nope, ready again |
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
error: function call inside of `unwrap_or` | ||
--> tests/ui/or_fun_call.rs:409:21 | ||
| | ||
LL | let _ = opt_foo.unwrap_or(Foo { val: String::default() }); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_else(|| Foo { val: String::default() })` |
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.
Should this clippy lint have a check that the value is const constructable in a stable way (which would revert this output change)?
@@ -333,7 +333,8 @@ impl<T: Copy> Clone for Cell<T> { | |||
} | |||
|
|||
#[stable(feature = "rust1", since = "1.0.0")] | |||
impl<T: Default> Default for Cell<T> { | |||
#[rustc_const_unstable(feature = "const_default", issue = "67792")] | |||
impl<T: ~const Default> const Default for Cell<T> { |
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.
impl<T: ~const Default> const Default for Cell<T> { | |
impl<T: [const] Default> const Default for Cell<T> { |
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.
Not possible until the bootstrap bump because we use stage 0 rustfmt
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.
These are not parsed against the master branch I rebased on top of? Has the parser change already landed?
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.
The parser changes landed. But rustfmt is bumped when the bootstrap compiler is bumped. At that time everything will automatically be formatted from ~const
to [const]
This comment has been minimized.
This comment has been minimized.
Full list of `impl const Default` types: - () - bool - char - std::ascii::Char - usize - u8 - u16 - u32 - u64 - u128 - i8 - i16 - i32 - i64 - i128 - f16 - f32 - f64 - f128 - std::marker::PhantomData<T> - Option<T> - std::iter::Empty<T> - std::ptr::Alignment - &[T] - &mut [T] - &str - &mut str - String - Vec<T>
The lint should likely still trigger while the const Default impl is unstable.
Full list of
impl const Default
types: