Skip to content

Rollup of 9 pull requests #64427

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

Closed
wants to merge 22 commits into from
Closed
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5287885
use randSecure and randABytes
bpangWR Sep 10, 2019
83e7976
Merge pull request #20 from Wind-River/rand
BaoshanPang Sep 11, 2019
5e8bf87
Merge pull request #21 from rust-lang/master
BaoshanPang Sep 11, 2019
b731e11
declare EnvKey before use to fix build error
bpangWR Sep 11, 2019
a8c5f90
Fix inconsistent link formatting.
tomasz-rozanski Sep 11, 2019
223600a
Guarantee vec.clear/truncate is O(1) for trivial types
kornelski Sep 11, 2019
08fa803
Merge pull request #22 from Wind-River/master_002
BaoshanPang Sep 12, 2019
612c394
Trim rustc-workspace-hack
mati865 Sep 11, 2019
baf97b7
Add long error explanation for E0493
GuillaumeGomez Sep 11, 2019
0ad141c
update tests
GuillaumeGomez Sep 12, 2019
34d71f1
Ban non-extern rust intrinsics
Mark-Simulacrum Sep 12, 2019
a47a5c3
typo fix
Sep 9, 2019
69112a2
Add self to .mailmap
ollie27 Sep 13, 2019
3f920e5
Rollup merge of #64372 - Wind-River:master, r=alexcrichton
Centril Sep 13, 2019
51ea8e6
Rollup merge of #64375 - kornelski:vecdrop, r=rkruppe
Centril Sep 13, 2019
1059ddd
Rollup merge of #64377 - GuillaumeGomez:E0493, r=estebank
Centril Sep 13, 2019
f4ec1f0
Rollup merge of #64378 - Rosto75:master, r=jonas-schievink
Centril Sep 13, 2019
1fb1b93
Rollup merge of #64384 - mati865:tools_hack, r=alexcrichton
Centril Sep 13, 2019
12ee41c
Rollup merge of #64393 - Wind-River:master_002_envKey, r=alexcrichton
Centril Sep 13, 2019
0bba7ad
Rollup merge of #64406 - Mark-Simulacrum:error-unknown-intrinsic, r=C…
Centril Sep 13, 2019
6143b15
Rollup merge of #64423 - ollie27:mailmap, r=Mark-Simulacrum
Centril Sep 13, 2019
bdc6271
Rollup merge of #64425 - guanqun:typo-fix, r=matthewjasper
Centril Sep 13, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,21 +685,25 @@ impl<T> Vec<T> {
/// [`drain`]: #method.drain
#[stable(feature = "rust1", since = "1.0.0")]
pub fn truncate(&mut self, len: usize) {
let current_len = self.len;
unsafe {
let mut ptr = self.as_mut_ptr().add(self.len);
// Set the final length at the end, keeping in mind that
// dropping an element might panic. Works around a missed
// optimization, as seen in the following issue:
// https://github.com/rust-lang/rust/issues/51802
let mut local_len = SetLenOnDrop::new(&mut self.len);
if mem::needs_drop::<T>() {
let current_len = self.len;
unsafe {
let mut ptr = self.as_mut_ptr().add(self.len);
// Set the final length at the end, keeping in mind that
// dropping an element might panic. Works around a missed
// optimization, as seen in the following issue:
// https://github.com/rust-lang/rust/issues/51802
let mut local_len = SetLenOnDrop::new(&mut self.len);

// drop any extra elements
for _ in len..current_len {
local_len.decrement_len(1);
ptr = ptr.offset(-1);
ptr::drop_in_place(ptr);
// drop any extra elements
for _ in len..current_len {
local_len.decrement_len(1);
ptr = ptr.offset(-1);
ptr::drop_in_place(ptr);
}
}
} else if len <= self.len {
self.len = len;
}
}

Expand Down