diff options
| author | bors <bors@rust-lang.org> | 2020-07-01 14:45:56 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-07-01 14:45:56 +0000 |
| commit | f781babf87dea29c44f93842b7ac9eb809549d29 (patch) | |
| tree | fcb575eda0c6d0e786d9b42d1b6559b4865f3ff6 /src/liballoc | |
| parent | 1505c1239554fd8c9a5f7a6f4823c7384a0c29e3 (diff) | |
| parent | c9b3e869771e7944719e139a327422726f7529de (diff) | |
| download | rust-f781babf87dea29c44f93842b7ac9eb809549d29.tar.gz rust-f781babf87dea29c44f93842b7ac9eb809549d29.zip | |
Auto merge of #73924 - Manishearth:rollup-8r51ld9, r=Manishearth
Rollup of 17 pull requests Successful merges: - #72071 (Added detailed error code explanation for issue E0687 in Rust compiler.) - #72369 (Bring net/parser.rs up to modern up to date with modern rust patterns) - #72445 (Stabilize `#[track_caller]`.) - #73466 (impl From<char> for String) - #73548 (remove rustdoc warnings) - #73649 (Fix sentence structure) - #73678 (Update Box::from_raw example to generalize better) - #73705 (stop taking references in Relate) - #73716 (Document the static keyword) - #73752 (Remap Windows ERROR_INVALID_PARAMETER to ErrorKind::InvalidInput from Other) - #73776 (Move terminator to new module) - #73778 (Make `likely` and `unlikely` const, gated by feature `const_unlikely`) - #73805 (Document the type keyword) - #73806 (Use an 'approximate' universal upper bound when reporting region errors) - #73828 (Fix wording for anonymous parameter name help) - #73846 (Fix comma in debug_assert! docs) - #73847 (Edit cursor.prev() method docs in lexer) Failed merges: r? @ghost
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/boxed.rs | 5 | ||||
| -rw-r--r-- | src/liballoc/string.rs | 8 | ||||
| -rw-r--r-- | src/liballoc/tests/string.rs | 7 |
3 files changed, 19 insertions, 1 deletions
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index f1b560b9b96..3320ebdf821 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -384,7 +384,10 @@ impl<T: ?Sized> Box<T> { /// /// unsafe { /// let ptr = alloc(Layout::new::<i32>()) as *mut i32; - /// *ptr = 5; + /// // In general .write is required to avoid attempting to destruct + /// // the (uninitialized) previous contents of `ptr`, though for this + /// // simple example `*ptr = 5` would have worked as well. + /// ptr.write(5); /// let x = Box::from_raw(ptr); /// } /// ``` diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 64d9692244d..13ef94dee23 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -2518,3 +2518,11 @@ impl DoubleEndedIterator for Drain<'_> { #[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for Drain<'_> {} + +#[stable(feature = "from_char_for_string", since = "1.46.0")] +impl From<char> for String { + #[inline] + fn from(c: char) -> Self { + c.to_string() + } +} diff --git a/src/liballoc/tests/string.rs b/src/liballoc/tests/string.rs index 9ea020d2d19..d38655af78c 100644 --- a/src/liballoc/tests/string.rs +++ b/src/liballoc/tests/string.rs @@ -714,3 +714,10 @@ fn test_try_reserve_exact() { } } } + +#[test] +fn test_from_char() { + assert_eq!(String::from('a'), 'a'.to_string()); + let s: String = 'x'.into(); + assert_eq!(s, 'x'.to_string()); +} |
