-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
RFC: Stabilize std::fmt
#380
Conversation
I think some of the mechanisms for formatting (including some proposed to be stable here) are too specific and could be made more general purpose. In particular, the concepts of annotated arguments and of printing are too closely coupled. I started some refactoring ages ago to try and make the arguments stuff more general purpose. I'll dig out the branch and see if I can come up with some specific recommendations. |
I think disallowing f!(x = ()); // basic syntax
f!(()); // implicitly set x to ()
let mut a;
f!(a = 1); // illegal, no such argument
f!({a = 1}); // implicitly set x to the result of a = 1
f!(x = a = 1); // explicitly set x to the result of a = 1 I imagine the same can be done for Rust's grammar in general. |
-1 for marking (or 'recommending') anything There has been at least one case where we had to change stable code due to language changes (rust-lang/rust/pull/17745), so how can we guarantee this will not happen again? |
@nick29581, I would be curious to here some more detail about your thoughts, I'm not sure I quite know what you're alluding to. @SiegeLord, that is indeed one possibility! I personally would rather have a consistent grammar than keyword arguments, however, as opposed to special-casing the grammar for expressions in function arguments for a hypothetical use case. @sinistersnare, if we took that route, then nothing would be stable by the time we hit 1.0, and even if we didn't mark anything as The usage of stability markers is to help track our progress through the standard library as we review APIs, and if we didn't use |
I don't find that convincing. You are already changing the grammar is a negative way for that hypthetical use case, so it's just a matter of choosing the way of doing it. Rust's grammar is already inconsistent. For example, take struct literals and |
One other thing to note is that the named argument syntax is basically unused (I couldn't find a single usage of it glancing through the Rust repository), and its usefulness seems questionable to begin with (it was a lot more useful in the days when formatting syntax was to be used for internationalization). I, for one, would rather support this kind of syntax: let some_var = 1;
format!("{some_var}"); Or: let some_var = 1;
format!("some_var = "some_var" and that's all I have to say about it"); I.e. similarly to how |
Thanks so much for this effort! We'll definitely have to sort out the named argument syntax stuff, but I'm going to focus on the rest of the API for now. Here are some questions I had when reading the RFC and looking at the public API:
I suppose in the end my basic concern here is that a fair amount of implementation detail is exposed in this module. The most worrisome part of that is the stuff that shows up in |
Aha, thanks! I've listed the remaining pieces and suggested
I agree! I've switched the recommendation to
Can do, I've added a few words here. Do they look ok to you?
Do you think that we should only expose
That's a good point! I've switched the recommendation to
That is a good point that I hadn't though much about before. The original intention for this was to actually expose all the implementation details to create formatting strings at runtime, but this was never truly manifested and we should probably optimize for removal of as many of these bits as possible. For now I think |
We were using named format arguments in gl-rs before we moved to a syntax extension, and found them helpful (to reduce argument repeats, and clarity). That may or may not be a useful data point though... |
I've updated the RFC to allow |
It's better, but I guess the whole thing is just a bit confusing because in the end you expect the
Ah, I think I just meant the In any case, I agree in general that by marking most of this as |
The only way I can think of to currently manage this is to have the error type of a writer be an associated type, in which case this is an obvious step to take (I think). Specifically about
Yeah this was introduced with the facade, and moving the traits to core would help a lot in this case. This was one of the largest pain points in creating the facade and I think that
Yeah the precise feature gating story will play out over time, but my goal is to hide as much of this as possible as it doesn't feel right from a stability standpoint (but |
Accepted. Discussion. Tracking. |
|
||
This RFC proposes removing the following traits: | ||
|
||
* `Signed` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's an example in the liblog that currently uses the ability to format as a String or a Signed: https://github.com/rust-lang/rust/blob/master/src/liblog/lib.rs#L234-L249
This allows someone to show the log level as the string INFO
or integer 3
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it's definitely true that you can use {}
and {:d}
to differentiate ways to format the same structure today, but from what I've seen it's quite rare. I've also started seeing a number of precedents for functions like path.display()
where some anonymous struct is returned that only implements one of the formatting traits so you can basically always use {}
and not have to worry much about it.
High-level summary:
Rendered