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

trpl/traits: Make error message consistent with source code snippet #25512

Merged
merged 2 commits into from
May 19, 2015
Merged
Changes from all commits
Commits
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
11 changes: 6 additions & 5 deletions src/doc/trpl/traits.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,17 @@ won’t have its methods:

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

Here’s the error:

```text
error: type `std::fs::File` does not implement any method in scope named `write`

let result = f.write(b"whatever");
^~~~~~~~~~~~~~~~~~
let result = f.write(buf);
^~~~~~~~~~
```

We need to `use` the `Write` trait first:
Expand All @@ -202,7 +202,8 @@ We need to `use` the `Write` trait first:
use std::io::Write;

let mut f = std::fs::File::open("foo.txt").ok().expect("Couldn’t open foo.txt");
let result = f.write("whatever".as_bytes());
let buf = b"whatever";
let result = f.write(buf);
# result.unwrap(); // ignore the error
```

Expand Down