about summary refs log tree commit diff
path: root/src/doc
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-03-23 15:11:10 -0700
committerAlex Crichton <alex@alexcrichton.com>2015-03-23 15:11:10 -0700
commit5e06ebbfc0d7c3655656dba1f3255e34fa711b68 (patch)
tree2edc08f5002c1b5c1c562b929cea54174da08e6e /src/doc
parentca7f7cf3d3bbac5dc3e35a28d89def398b6ec988 (diff)
parent1be8fcb4a955457b9ec6e16e34bdfbb7e4d849c7 (diff)
downloadrust-5e06ebbfc0d7c3655656dba1f3255e34fa711b68.tar.gz
rust-5e06ebbfc0d7c3655656dba1f3255e34fa711b68.zip
rollup merge of #23639: steveklabnik/gh21305
Fixes #21305

Not sure if we should include more than this here, but it should be good to have at least this.
Diffstat (limited to 'src/doc')
-rw-r--r--src/doc/trpl/more-strings.md33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/doc/trpl/more-strings.md b/src/doc/trpl/more-strings.md
index 6567cd448f9..0f19b9249f5 100644
--- a/src/doc/trpl/more-strings.md
+++ b/src/doc/trpl/more-strings.md
@@ -12,7 +12,7 @@ Additionally, strings are not null-terminated and can contain null bytes.
 
 Rust has two main types of strings: `&str` and `String`.
 
-# &str
+# `&str`
 
 The first kind is a `&str`. This is pronounced a 'string slice'.
 String literals are of the type `&str`:
@@ -36,7 +36,36 @@ Like vector slices, string slices are simply a pointer plus a length. This
 means that they're a 'view' into an already-allocated string, such as a
 string literal or a `String`.
 
-# String
+## `str`
+
+You may occasionally see references to a `str` type, without the `&`. While
+this type does exist, it’s not something you want to use yourself. Sometimes,
+people confuse `str` for `String`, and write this:
+
+```rust
+struct S {
+    s: str,
+}
+```
+
+This leads to ugly errors:
+
+```text
+error: the trait `core::marker::Sized` is not implemented for the type `str` [E0277]
+note: `str` does not have a constant size known at compile-time
+```
+
+Instead, this `struct` should be
+
+```rust
+struct S {
+    s: String,
+}
+```
+
+So let’s talk about `String`s.
+
+# `String`
 
 A `String` is a heap-allocated string. This string is growable, and is
 also guaranteed to be UTF-8. `String`s are commonly created by