Conversation
|
r? @kennytm (rust_highfive has picked a reviewer for you, use r? to override) |
|
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 |
src/liballoc/vec.rs
Outdated
| @@ -324,7 +324,7 @@ impl<T> Vec<T> { | |||
| #[stable(feature = "rust1", since = "1.0.0")] | |||
| pub fn new() -> Vec<T> { | |||
There was a problem hiding this comment.
You forgot the actual change of this PR 😆
| #[inline] | ||
| #[stable(feature = "rust1", since = "1.0.0")] | ||
| pub fn new() -> Vec<T> { | ||
| pub const fn new() -> Vec<T> { |
There was a problem hiding this comment.
Please mark this with #[rustc_const_unstable(feature = "const_vec_new")] so we don't need to insta-stable this.
|
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 |
|
The test needs |
|
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 |
|
|
|
@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 |
|
@mbrubeck That approach doesn't quite work: |
|
If you don't use an intermediate const, then the trick should work. Const if is still ways off. So use the array trick |
|
Still. the trick works now. No need to block this PR |
|
Yeah, I don't dispute that. ;-) |
|
Hmm... tidy is segfaulting on my machine, so I can't run tests at the moment... |
|
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 |
|
Oh 🤦♂️ |
|
@kennytm I think this is ready for another review |
|
@bors r+ |
|
📌 Commit f9f9923 has been approved by |
Make `Vec::new` a `const fn`
`RawVec::empty/_in` are a hack. They're there because `if size_of::<T> == 0 { !0 } else { 0 }` is not allowed in `const` yet. However, because `RawVec` is unstable, the `empty/empty_in` constructors can be removed when rust-lang#49146 is done...
Rollup of 7 pull requests Successful merges: - #50233 (Make `Vec::new` a `const fn`) - #50312 (Add more links in panic docs) - #50316 (Fix some broken links in docs.) - #50325 (Add a few more tests for proc macro feature gating) - #50327 (Display correct unused field suggestion for nested struct patterns) - #50330 (check that #[used] is used only on statics) - #50344 (Update Cargo to 2018-04-28 122fd5be5201913d42e219e132d6569493583bca) Failed merges:
impl String {
pub fn new() -> String {
String { vec: Vec::new() }
}
}Given that |
|
Good idea! |
Make `String::new()` const Following the steps of rust-lang#50233 , make `String::new()` a `const fn`.
Initially, rust-lang#50233 accidentally changed the capacity of empty ZST. This was pointed out during code review. This commit adds a test to prevent capacity of ZST vectors from accidentally changing to prevent that from happening again.
Test capacity of ZST vector Initially, rust-lang#50233 accidentally changed the capacity of empty ZST. This was pointed out during code review. This commit adds a test to prevent capacity of ZST vectors from accidentally changing to prevent that from happening again.
Test capacity of ZST vector Initially, rust-lang#50233 accidentally changed the capacity of empty ZST. This was pointed out during code review. This commit adds a test to prevent capacity of ZST vectors from accidentally changing to prevent that from happening again.
Test capacity of ZST vector Initially, rust-lang#50233 accidentally changed the capacity of empty ZST. This was pointed out during code review. This commit adds a test to prevent capacity of ZST vectors from accidentally changing to prevent that from happening again.
Test capacity of ZST vector Initially, rust-lang#50233 accidentally changed the capacity of empty ZST. This was pointed out during code review. This commit adds a test to prevent capacity of ZST vectors from accidentally changing to prevent that from happening again.
Test capacity of ZST vector Initially, rust-lang#50233 accidentally changed the capacity of empty ZST. This was pointed out during code review. This commit adds a test to prevent capacity of ZST vectors from accidentally changing to prevent that from happening again.
Test capacity of ZST vector Initially, rust-lang#50233 accidentally changed the capacity of empty ZST. This was pointed out during code review. This commit adds a test to prevent capacity of ZST vectors from accidentally changing to prevent that from happening again.
Test capacity of ZST vector Initially, rust-lang#50233 accidentally changed the capacity of empty ZST. This was pointed out during code review. This commit adds a test to prevent capacity of ZST vectors from accidentally changing to prevent that from happening again.
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...