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

std: Stabilize std::fmt #19040

Merged
merged 1 commit into from
Nov 20, 2014
Merged

std: Stabilize std::fmt #19040

merged 1 commit into from
Nov 20, 2014

Conversation

alexcrichton
Copy link
Member

This commit applies the stabilization of std::fmt as outlined in RFC 380.
There are a number of breaking changes as a part of this commit which will need
to be handled to migrated old code:

  • A number of formatting traits have been removed: String, Bool, Char, Unsigned,
    Signed, and Float. It is recommended to instead use Show wherever possible or
    to use adaptor structs to implement other methods of formatting.
  • The format specifier for Boolean has changed from t to b.
  • The enum FormatError has been renamed to Error as well as becoming a unit
    struct instead of an enum. The WriteError variant no longer exists.
  • The format_args_method! macro has been removed with no replacement. Alter
    code to use the format_args! macro instead.
  • The public fields of a Formatter have become read-only with no replacement.
    Use a new formatting string to alter the formatting flags in combination with
    the write! macro. The fields can be accessed through accessor methods on the
    Formatter structure.

Other than these breaking changes, the contents of std::fmt should now also all
contain stability markers. Most of them are still #[unstable] or #[experimental]

[breaking-change]

Closes #18904

@rust-highfive
Copy link
Collaborator

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!

@alexcrichton
Copy link
Member Author

r? @aturon

@aturon
Copy link
Member

aturon commented Nov 18, 2014

r=me after a rebase

@aturon
Copy link
Member

aturon commented Nov 19, 2014

Needs rebase.

This commit applies the stabilization of std::fmt as outlined in [RFC 380][rfc].
There are a number of breaking changes as a part of this commit which will need
to be handled to migrated old code:

* A number of formatting traits have been removed: String, Bool, Char, Unsigned,
  Signed, and Float. It is recommended to instead use Show wherever possible or
  to use adaptor structs to implement other methods of formatting.

* The format specifier for Boolean has changed from `t` to `b`.

* The enum `FormatError` has been renamed to `Error` as well as becoming a unit
  struct instead of an enum. The `WriteError` variant no longer exists.

* The `format_args_method!` macro has been removed with no replacement. Alter
  code to use the `format_args!` macro instead.

* The public fields of a `Formatter` have become read-only with no replacement.
  Use a new formatting string to alter the formatting flags in combination with
  the `write!` macro. The fields can be accessed through accessor methods on the
  `Formatter` structure.

Other than these breaking changes, the contents of std::fmt should now also all
contain stability markers. Most of them are still #[unstable] or #[experimental]

[rfc]: https://github.com/rust-lang/rfcs/blob/master/text/0380-stabilize-std-fmt.md
[breaking-change]

Closes rust-lang#18904
@@ -277,6 +281,7 @@ macro_rules! writeln(
/// Equivalent to the `println!` macro except that a newline is not printed at
/// the end of the message.
#[macro_export]
#[stable]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems premature to mark this as stable when the design of the stdio support is in question. It's not possible to either handle or ignore runtime errors from these functions like broken pipes. The handling of buffering has also been called out as confusing / inefficient, and I don't see why writing to stdout should involve virtual method calls.

@nikomatsakis
Copy link
Contributor

Moving response to #19040 (comment) out of the commit and onto the PR itself, so that notifications are sent out more generally.

I don't have time to read through all of the RFCs.

It does take a lot of time to keep up, I agree (though I find it much easier to track RFCs than individual PRs). What can I say, there's a lot going on!

It returning a value or having different buffering semantics would be a breaking change to the API.

Yes, I agree, and marking it stable is committing to not returning a value and performing buffering.

It doesn't just panic on I/O failure, it panics on broken pipes which is a completely normal part of *nix programming. Nearly every program used in shell pipelines has to cope with broken pipes when a program like head closes early.

It seems to me that panic is pretty reasonable (it's also what other languages do). Programs that do not require fine-grained error handling (like many command-line utilities) can thus use println! and recover from the panic in order to terminate gracefully.

In any case, this discussion has come up numerous times before (e.g., here). The arguments for/against have been made. I think it's time for this commit to move forward and this argument to be closed.

@Earnestly
Copy link

#include <stdio.h>

int
main(void)
{
        for(size_t i = 0; i < 100; ++i){
                printf("Hello\n");
                fflush(stdout);
        }
        return 0;
}
% ./pipe | head -n 2
Hello
Hello

@alexcrichton
Copy link
Member Author

@Earnestly it would be helpful for you to explain what you're trying to say instead of just posting code and assuming others will infer. C's behavior has been discussed in great detail on #13824 (which @nikomatsakis linked to), and I recommend reading when discussion the SIGPIPE issue.

@Earnestly
Copy link

Just thought it would be fair to include a language that is remotely related to Rust. People can read about your strace as you linked.

@bors bors merged commit 4af3494 into rust-lang:master Nov 20, 2014
@alexcrichton alexcrichton deleted the issue-18904 branch November 20, 2014 03:19
@thestinger
Copy link
Contributor

@nikomatsakis: Exceptions that can be caught are not compared to aborting the process / task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stabilize parts of std::fmt
7 participants