Github Tracking Issue for fmt::Arguments::as_str() · Issue #74442 · rust-lang/ru...
source link: https://github.com/rust-lang/rust/issues/74442
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Tracking Issue for fmt::Arguments::as_str() #74442
m-ou-se opened this issue on Jul 17, 2020 · 11 comments
Comments
Member
m-ou-se commented on Jul 17, 2020
Tracking issue for fmt::Arguments::as_str()
(#74056), gated by #![feature(fmt_as_str)]
.
I don't quite understand fmt internals, but Make fmt::Arguments::as_str() return a 'static str. seems unnecessarily restrictive. And it breaks runtime-fmt which depends on hidden apis e.g. Arguments::new_v1
Contributor
lzutao commented on Aug 7, 2020
Arguments
cannot be generated at runtime because it cannot safely be done. So as_str
returns &'static str
makes sense.
Member
sfackler commented 6 days ago
I'd like to be able to use this in the log crate to correctly implement a codegen optimization that doesn't really work otherwise: rust-lang/log#446
@rfcbot fcp merge
rfcbot commented 6 days ago •
Team member @sfackler has proposed to merge this. The next step is review by the rest of the tagged team members:
No concerns currently listed.
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!
See this document for info about what commands tagged team members can give me.
Member
BurntSushi commented 6 days ago
This SGTM. One question though. Are we sure that the 'static
bound will always be correct here?
Member
Author
m-ou-se commented 6 days ago
fmt::Arguments
is the result from parsing a formatting string at compile time. In the future, this might not always be a literal but might be a const
too. But a non-static/constant format string will be a very different beast.
Member
BurntSushi commented 6 days ago
That's what I figured, but wanted to make sure it was explicitly addressed.
rfcbot commented 6 days ago
This is now entering its final comment period, as per the review above.
Contributor
jhpratt commented 5 days ago
Does this make any guarantees about when Some
is returned? I've been interested in redoing the format_args!
macro to be much more intelligent (and thus performant), but obviously don't know when it's possible to return something statically knowable.
Member
Author
m-ou-se commented 5 days ago
Currently it returns Some for format_args!("string literal")
only. But my plan is to extend that also to format_args!("{}", "literal")
, format_args!("{}", constant)
, and possibly also things like format_args!("a {} b {} c", const, format_args!("..."))
, etc. See #78356
Contributor
jhpratt commented 4 days ago
Yeah, I see that from looking at the source code. I was more inquiring about whether it would be considered breaking to go from returning Some
to returning None
. I don't suspect anything would be out-of-reach when reimplementing the macro, but you never know.
No one assigned
None yet
No milestone
Successfully merging a pull request may close this issue.
None yet
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK