|
1 |
| -- Start Date: (fill me in with today's date, YYYY-MM-DD) |
| 1 | +- Start Date: 2015-03-25 |
2 | 2 | - RFC PR: (leave this empty)
|
3 | 3 | - Rust Issue: (leave this empty)
|
4 | 4 |
|
5 | 5 | # Summary
|
6 | 6 |
|
7 |
| -One para explanation of the feature. |
| 7 | +When calling `println!` it currently causes a panic if `stdout` does not exist. Change this to ignore this specific error and simply void the output. |
8 | 8 |
|
9 | 9 | # Motivation
|
10 | 10 |
|
11 |
| -Why are we doing this? What use cases does it support? What is the expected outcome? |
| 11 | +On linux `stdout` almost always exists, so when people write games and turn off the terminal there is still an `stdout` that they write to. Then when getting the code to run on Windows, when the console is disabled, suddenly `stdout` doesn't exist and `println!` panicks. This behavior difference is frustrating to developers trying to move to Windows. |
| 12 | + |
| 13 | +There is also precedent with C and C++. On both Linux and Windows, if `stdout` is closed or doesn't exist, neither platform will error when printing to the console. |
12 | 14 |
|
13 | 15 | # Detailed design
|
14 | 16 |
|
15 |
| -This is the bulk of the RFC. Explain the design in enough detail for somebody familiar |
16 |
| -with the language to understand, and for somebody familiar with the compiler to implement. |
17 |
| -This should get into specifics and corner-cases, and include examples of how the feature is used. |
| 17 | +Change the internal implementation of `println!` `print!` `panic!` and `assert!` to not `panic!` when `stdout` or `stderr` doesn't exist. When getting `stdout` or `stderr` through the `std::io` methods, those versions should continue to return an error if `stdout` or `stderr` doesn't exist. |
18 | 18 |
|
19 | 19 | # Drawbacks
|
20 | 20 |
|
21 |
| -Why should we *not* do this? |
| 21 | +Hides an error from the user which we may want to expose and may lead to people missing panicks occuring in threads. |
22 | 22 |
|
23 | 23 | # Alternatives
|
24 | 24 |
|
25 |
| -What other designs have been considered? What is the impact of not doing this? |
| 25 | +* Make `println!` `print!` `panic!` `assert!` return errors that the user has to handle. |
| 26 | +* Continue with the status quo and panic if `stdout` or `stderr` doesn't exist. |
26 | 27 |
|
27 | 28 | # Unresolved questions
|
28 | 29 |
|
29 |
| -What parts of the design are still TBD? |
| 30 | +* Should `std::io::stdout` return `Err` or `None` when there is no `stdout` instead of unconditionally returning `Stdout`? |
0 commit comments