Rollup merge of #40763 - pirate:patch-2, r=steveklabnik

Add helpful hint in io docs about how ? is not allowed in main()

This is my effort to help alleviate the confusion caused by the error message:
```rust
error[E0277]: the trait bound `(): std::ops::Carrier` is not satisfied
  --> hello_world.rs:72:5
   |
72 |     io::stdin().read_line(&mut d_input)?;
   |     ------------------------------------
   |     |
   |     the trait `std::ops::Carrier` is not implemented for `()`
   |     in this macro invocation
   |
   = note: required by `std::ops::Carrier::from_error`

error: aborting due to previous error
```
This has been discussed at length in https://github.com/rust-lang/rust/issues/35946, but I figured it would be helpful to mention in the docs.
Reading user input is one of the first things beginners will look up in the docs, so my thinking was they'd see this warning here and not have to deal with the [tricky error message](https://blog.rust-lang.org/2017/03/02/lang-ergonomics.html).

If you think this isn't the right place to put this in the docs, that's understandable, I'm open to suggestions for putting it elsewhere or removing it entirely.
This commit is contained in:
Corey Farwell 2017-03-31 16:48:26 -04:00 committed by GitHub
commit 6edab01499

View file

@ -145,6 +145,18 @@
//! # }
//! ```
//!
//! Note that you cannot use the `?` operator in functions that do not return
//! a `Result<T, E>` (e.g. `main`). Instead, you can call `.unwrap()` or `match`
//! on the return value to catch any possible errors:
//!
//! ```
//! use std::io;
//!
//! let mut input = String::new();
//!
//! io::stdin().read_line(&mut input).unwrap();
//! ```
//!
//! And a very common source of output is standard output:
//!
//! ```