-
Notifications
You must be signed in to change notification settings - Fork 271
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
Adjust Vec to build on stable Rust #223
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,20 +7,17 @@ ask Rust if `T` `needs_drop` and omit the calls to `pop`. However in practice | |
LLVM is *really* good at removing simple side-effect free code like this, so I | ||
wouldn't bother unless you notice it's not being stripped (in this case it is). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that the above is only true if LLVM can prove that the loop is finite. This is true in the case of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. And based on the docs for needs_drop it sounds like even in the
I would lean toward option 4, since currently this section is very short and could benefit from more discussion and examples to illustrate the usage of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that option 4 sounds like the best way to go. It's fine to do this in a separate PR. |
||
|
||
We must not call `Global.deallocate` when `self.cap == 0`, as in this case we | ||
We must not call `alloc::dealloc` when `self.cap == 0`, as in this case we | ||
haven't actually allocated any memory. | ||
|
||
|
||
```rust,ignore | ||
impl<T> Drop for Vec<T> { | ||
fn drop(&mut self) { | ||
if self.cap != 0 { | ||
while let Some(_) = self.pop() { } | ||
|
||
let layout = Layout::array::<T>(self.cap).unwrap(); | ||
unsafe { | ||
let c: NonNull<T> = self.ptr.into(); | ||
Global.deallocate(c.cast(), | ||
Layout::array::<T>(self.cap).unwrap()); | ||
alloc::dealloc(self.ptr.as_ptr() as *mut u8, layout); | ||
} | ||
} | ||
} | ||
|
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.
At some point I really want to implement rust-lang/rust#77974.