Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upMake `Vec::new` a `const fn` #50233
Conversation
rust-highfive
assigned
kennytm
Apr 25, 2018
This comment has been minimized.
This comment has been minimized.
|
r? @kennytm (rust_highfive has picked a reviewer for you, use r? to override) |
rust-highfive
added
the
S-waiting-on-review
label
Apr 25, 2018
This comment has been minimized.
This comment has been minimized.
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
oli-obk
reviewed
Apr 26, 2018
| @@ -324,7 +324,7 @@ impl<T> Vec<T> { | |||
| #[stable(feature = "rust1", since = "1.0.0")] | |||
| pub fn new() -> Vec<T> { | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
kennytm
reviewed
Apr 26, 2018
| @@ -322,9 +322,9 @@ impl<T> Vec<T> { | |||
| /// ``` | |||
| #[inline] | |||
| #[stable(feature = "rust1", since = "1.0.0")] | |||
| pub fn new() -> Vec<T> { | |||
| pub const fn new() -> Vec<T> { | |||
This comment has been minimized.
This comment has been minimized.
kennytm
Apr 26, 2018
Member
Please mark this with #[rustc_const_unstable(feature = "const_vec_new")] so we don't need to insta-stable this.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
This comment has been minimized.
This comment has been minimized.
|
The test needs |
This comment has been minimized.
This comment has been minimized.
|
This changes the behavior for zero-sized types. Before this change, If we want to preserve the current optimization for zero-sized types, then instead of getting rid of the |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@alexreg would it be possible to get an ETA on that? What does "very soon" mean exactly? If it will be in the next few weeks or so, then I think it would be worth it to wait for that. Otherwise, we could use the |
This comment has been minimized.
This comment has been minimized.
|
@mbrubeck That approach doesn't quite work:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
If you don't use an intermediate const, then the trick should work. Const if is still ways off. So use the array trick |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Still. the trick works now. No need to block this PR |
This comment has been minimized.
This comment has been minimized.
|
Yeah, I don't dispute that. ;-) |
This comment has been minimized.
This comment has been minimized.
|
Hmm... tidy is segfaulting on my machine, so I can't run tests at the moment... |
mark-i-m
changed the title
[WIP] Make `Vec::new` a `const fn`
Make `Vec::new` a `const fn`
Apr 29, 2018
This comment has been minimized.
This comment has been minimized.
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
This comment has been minimized.
This comment has been minimized.
|
Oh |
This comment has been minimized.
This comment has been minimized.
|
@kennytm I think this is ready for another review |
This comment has been minimized.
This comment has been minimized.
|
@bors r+ |
This comment has been minimized.
This comment has been minimized.
|
|
bors
added
S-waiting-on-bors
and removed
S-waiting-on-review
labels
Apr 30, 2018
kennytm
added a commit
to kennytm/rust
that referenced
this pull request
Apr 30, 2018
bors
added a commit
that referenced
this pull request
Apr 30, 2018
bors
merged commit f9f9923
into
rust-lang:master
Apr 30, 2018
1 check passed
This comment has been minimized.
This comment has been minimized.
impl String {
pub fn new() -> String {
String { vec: Vec::new() }
}
}Given that |
This comment has been minimized.
This comment has been minimized.
|
Good idea! |
mark-i-m commentedApr 25, 2018
RawVec::empty/_inare a hack. They're there becauseif size_of::<T> == 0 { !0 } else { 0 }is not allowed inconstyet. However, becauseRawVecis unstable, theempty/empty_inconstructors can be removed when #49146 is done...