Skip to content

Commit 392576b

Browse files
committed
Rollup merge of #25512 - peferron:doc-traits-error-fix, r=alexcrichton
The source code snippet uses `"whatever".as_bytes()` but the compilation error message uses `b"whatever"`. Both should be consistent with each other. r? @steveklabnik
2 parents fddd893 + a10d243 commit 392576b

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/doc/trpl/traits.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,17 +183,17 @@ won’t have its methods:
183183

184184
```rust,ignore
185185
let mut f = std::fs::File::open("foo.txt").ok().expect("Couldn’t open foo.txt");
186-
let result = f.write("whatever".as_bytes());
186+
let buf = b"whatever"; // byte string literal. buf: &[u8; 8]
187+
let result = f.write(buf);
187188
# result.unwrap(); // ignore the error
188189
```
189190

190191
Here’s the error:
191192

192193
```text
193194
error: type `std::fs::File` does not implement any method in scope named `write`
194-
195-
let result = f.write(b"whatever");
196-
^~~~~~~~~~~~~~~~~~
195+
let result = f.write(buf);
196+
^~~~~~~~~~
197197
```
198198

199199
We need to `use` the `Write` trait first:
@@ -202,7 +202,8 @@ We need to `use` the `Write` trait first:
202202
use std::io::Write;
203203
204204
let mut f = std::fs::File::open("foo.txt").ok().expect("Couldn’t open foo.txt");
205-
let result = f.write("whatever".as_bytes());
205+
let buf = b"whatever";
206+
let result = f.write(buf);
206207
# result.unwrap(); // ignore the error
207208
```
208209

0 commit comments

Comments
 (0)