Skip to content
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

Rollup of 6 pull requests #70878

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d730bf9
link with "libssp" on *-sun-solaris systems
jclulow Mar 31, 2020
2c9d857
Miri leak_report: do not report leaks of allocations that are reachab…
RalfJung Apr 4, 2020
fbdff51
avoid printing allocations twice
RalfJung Apr 4, 2020
aecaeab
share more alloc printing code between Miri and MIR dumping
RalfJung Apr 4, 2020
1f3e247
indicate better which kind of memory got leaked
RalfJung Apr 4, 2020
c8b83ba
Keep codegen units unmerged when building compiler builtins
tmiasko Apr 6, 2020
e1a36e8
Bump nomicon submodule
faern Apr 6, 2020
d0a78ea
Bump rust-by-example submodule
faern Apr 6, 2020
01b3293
Bump stdarch submodule
faern Apr 6, 2020
65e10e3
Use assoc const f32::NAN in liballoc
faern Apr 6, 2020
cf1c7ed
Use assoc float consts in libcore
faern Apr 6, 2020
ebcf1e7
Stop importing float module in libserialize
faern Apr 6, 2020
09b5d66
Stop importing float module in libtest
faern Apr 6, 2020
e4fc04b
Use usize::MAX as assoc const in liballoc
faern Apr 6, 2020
3e4396b
Use integer assoc consts in libcore
faern Apr 6, 2020
68b1af6
Don't import integer module in libstd
faern Apr 6, 2020
cf8df01
Use assoc integer constants in libserialize
faern Apr 6, 2020
f7778d3
Use assoc integer constants in librustc_*
faern Apr 6, 2020
e8339e8
Use split_at in slice's ToOwned::clone_into
cuviper Mar 20, 2020
b80fa76
Implement ToOwned::clone_into for CStr
cuviper Mar 20, 2020
f854070
Forward OsStr::clone_into to the inner Vec
cuviper Mar 20, 2020
c966511
Rollup merge of #70201 - cuviper:clone_into, r=dtolnay
Centril Apr 7, 2020
94d4c0e
Rollup merge of #70682 - jclulow:illumos-libssp, r=nagisa
Centril Apr 7, 2020
5b7a874
Rollup merge of #70762 - RalfJung:miri-leak-check, r=oli-obk
Centril Apr 7, 2020
ea29e7b
Rollup merge of #70846 - tmiasko:compiler-builtins-codegen-units, r=a…
Centril Apr 7, 2020
61cd420
Rollup merge of #70854 - faern:use-assoc-int-submodules, r=dtolnay
Centril Apr 7, 2020
17c5a81
Rollup merge of #70857 - faern:use-assoc-int-float-consts, r=dtolnay
Centril Apr 7, 2020
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
12 changes: 6 additions & 6 deletions src/liballoc/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,14 +733,14 @@ impl<T: Clone> ToOwned for [T] {
fn clone_into(&self, target: &mut Vec<T>) {
// drop anything in target that will not be overwritten
target.truncate(self.len());
let len = target.len();

// reuse the contained values' allocations/resources.
target.clone_from_slice(&self[..len]);

// target.len <= self.len due to the truncate above, so the
// slice here is always in-bounds.
target.extend_from_slice(&self[len..]);
// slices here are always in-bounds.
let (init, tail) = self.split_at(target.len());

// reuse the contained values' allocations/resources.
target.clone_from_slice(init);
target.extend_from_slice(tail);
}
}

Expand Down
17 changes: 17 additions & 0 deletions src/libstd/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1329,6 +1329,12 @@ impl ToOwned for CStr {
fn to_owned(&self) -> CString {
CString { inner: self.to_bytes_with_nul().into() }
}

fn clone_into(&self, target: &mut CString) {
let mut b = Vec::from(mem::take(&mut target.inner));
self.to_bytes_with_nul().clone_into(&mut b);
target.inner = b.into_boxed_slice();
}
}

#[stable(feature = "cstring_asref", since = "1.7.0")]
Expand Down Expand Up @@ -1510,6 +1516,17 @@ mod tests {
assert_eq!(boxed.to_bytes_with_nul(), &[0]);
}

#[test]
fn test_c_str_clone_into() {
let mut c_string = CString::new("lorem").unwrap();
let c_ptr = c_string.as_ptr();
let c_str = CStr::from_bytes_with_nul(b"ipsum\0").unwrap();
c_str.clone_into(&mut c_string);
assert_eq!(c_str, c_string.as_c_str());
// The exact same size shouldn't have needed to move its allocation
assert_eq!(c_ptr, c_string.as_ptr());
}

#[test]
fn into_rc() {
let orig: &[u8] = b"Hello, world!\0";
Expand Down
3 changes: 1 addition & 2 deletions src/libstd/ffi/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1120,8 +1120,7 @@ impl ToOwned for OsStr {
self.to_os_string()
}
fn clone_into(&self, target: &mut OsString) {
target.clear();
target.push(self);
self.inner.clone_into(&mut target.inner)
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/libstd/sys/windows/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ impl Slice {
Buf { inner: buf }
}

pub fn clone_into(&self, buf: &mut Buf) {
self.inner.clone_into(&mut buf.inner)
}

#[inline]
pub fn into_box(&self) -> Box<Slice> {
unsafe { mem::transmute(self.inner.into_box()) }
Expand Down
4 changes: 4 additions & 0 deletions src/libstd/sys_common/os_str_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ impl Slice {
Buf { inner: self.inner.to_vec() }
}

pub fn clone_into(&self, buf: &mut Buf) {
self.inner.clone_into(&mut buf.inner)
}

#[inline]
pub fn into_box(&self) -> Box<Slice> {
let boxed: Box<[u8]> = self.inner.into();
Expand Down
4 changes: 4 additions & 0 deletions src/libstd/sys_common/wtf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,10 @@ impl Wtf8 {
}
}

pub fn clone_into(&self, buf: &mut Wtf8Buf) {
self.bytes.clone_into(&mut buf.bytes)
}

/// Boxes this `Wtf8`.
#[inline]
pub fn into_box(&self) -> Box<Wtf8> {
Expand Down