diff options
| author | bors <bors@rust-lang.org> | 2020-06-19 23:04:41 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-06-19 23:04:41 +0000 |
| commit | 34c5cd9a64d8537236626c4ccbed39a924cd38e2 (patch) | |
| tree | b9b73acf0895861bf6991337643170178e2c890d /src/liballoc/string.rs | |
| parent | 2d8bd9b74dc0cf06d881bac645698ccbcf9d9c5e (diff) | |
| parent | a88182f94b0141a8df54fe86aad07d857baff911 (diff) | |
| download | rust-34c5cd9a64d8537236626c4ccbed39a924cd38e2.tar.gz rust-34c5cd9a64d8537236626c4ccbed39a924cd38e2.zip | |
Auto merge of #73511 - Manishearth:rollup-3iffxd8, r=Manishearth
Rollup of 13 pull requests Successful merges: - #71568 (Document unsafety in slice/sort.rs) - #72709 (`#[deny(unsafe_op_in_unsafe_fn)]` in liballoc) - #73214 (Add asm!() support for hexagon) - #73248 (save_analysis: improve handling of enum struct variant) - #73257 (ty: projections in `transparent_newtype_field`) - #73261 (Suggest `?Sized` when applicable for ADTs) - #73300 (Implement crate-level-only lints checking.) - #73334 (Note numeric literals that can never fit in an expected type) - #73357 (Use `LocalDefId` for import IDs in trait map) - #73364 (asm: Allow multiple template string arguments; interpret them as newline-separated) - #73382 (Only display other method receiver candidates if they actually apply) - #73465 (Add specialization of `ToString for char`) - #73489 (Refactor hir::Place) Failed merges: r? @ghost
Diffstat (limited to 'src/liballoc/string.rs')
| -rw-r--r-- | src/liballoc/string.rs | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 0378ff5362a..64d9692244d 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -724,7 +724,7 @@ impl String { #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub unsafe fn from_raw_parts(buf: *mut u8, length: usize, capacity: usize) -> String { - String { vec: Vec::from_raw_parts(buf, length, capacity) } + unsafe { String { vec: Vec::from_raw_parts(buf, length, capacity) } } } /// Converts a vector of bytes to a `String` without checking that the @@ -1329,9 +1329,11 @@ impl String { let amt = bytes.len(); self.vec.reserve(amt); - ptr::copy(self.vec.as_ptr().add(idx), self.vec.as_mut_ptr().add(idx + amt), len - idx); - ptr::copy(bytes.as_ptr(), self.vec.as_mut_ptr().add(idx), amt); - self.vec.set_len(len + amt); + unsafe { + ptr::copy(self.vec.as_ptr().add(idx), self.vec.as_mut_ptr().add(idx + amt), len - idx); + ptr::copy(bytes.as_ptr(), self.vec.as_mut_ptr().add(idx), amt); + self.vec.set_len(len + amt); + } } /// Inserts a string slice into this `String` at a byte position. @@ -2228,6 +2230,14 @@ impl<T: fmt::Display + ?Sized> ToString for T { } } +#[stable(feature = "char_to_string_specialization", since = "1.46.0")] +impl ToString for char { + #[inline] + fn to_string(&self) -> String { + String::from(self.encode_utf8(&mut [0; 4])) + } +} + #[stable(feature = "str_to_string_specialization", since = "1.9.0")] impl ToString for str { #[inline] |
