-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Fix syntax extensions for #![no_std] #21912
Conversation
I think we may want to hold off on this until the outcome of #21833 is decided. This has some surprising semantics if |
let mut output = String::new(); | ||
let _ = write!(&mut output, "{}", args); | ||
output | ||
} |
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.
This should avoid adding new APIs to String
for now, if necessary then it's likely that the entire std::fmt
module can live in libcollections
and this function need not be added just yet.
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.
I think String::format
is a better, more descriptive name. Is there a specific reason we can't revisit this API choice?
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.
It's fine to revisit, but that change requires an RFC (due to String
being in the prelude).
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.
Okay, I'll prepare one.
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.
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.
Do you want to back out this change to now to wait for that resolution?
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.
Er, back out this change to land the rest of this PR ahead of the RFC
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, I can do that.
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.
Yes, I think String::format is a better, more descriptive name.
On Feb 4, 2015 6:46 AM, "Keegan McAllister" notifications@github.com
wrote:
In src/libcollections/string.rs
#21912 (comment):
- ///
- /// # Example
- ///
- /// ```rust
- /// let s = String::format(format_args!("Hello, {}!", "world"));
- /// assert_eq!(s, "Hello, world!".to_string());
- /// ```
- #[unstable(feature = "collections",
reason = "duplicates std::fmt::format, only needed when libstd is missing")]
- pub fn format(args: fmt::Arguments) -> String {
// FIXME #21826
use core::fmt::Writer;
let mut output = String::new();
let _ = write!(&mut output, "{}", args);
output
- }
I think String::format is a better, more descriptive name. Is there a
specific reason we can't revisit this API choice?—
Reply to this email directly or view it on GitHub
https://github.com/rust-lang/rust/pull/21912/files#r24047873.
If you're using In no case does the syntax extension insert an I agree that |
…] crate Fixes rust-lang#16803. Fixes rust-lang#14342. Fixes half of rust-lang#21827 -- slice syntax is still broken.
7296902
to
419bce4
Compare
Rebased, and changed to the |
fwiw, gating |
Folding this into #21988. |
Fixes #21833. [breaking-change] r? @alexcrichton The tests in #21912 will also need `#[feature(no_std)]`. If you're okay with both PRs, I can merge and test them.
This fixes
derive
(for most traits, c.f. #21880),format!
, and for loops. Slice syntax is still broken because the desugar happens in the parser. I'll follow up on that bug (#21827).This duplicates the functionality of
std::fmt::format
asString::format
, which works whether libstd or just libcollections is available.fmt::format
is marked as stable but that's not a hard requirement until 1.0-final. So I'd like to stabilizeString::format
and deprecatefmt::format
to be removed before 1.0. I can prepare an RFC for that if necessary. There's no visible change for users of theformat!
macro, except that it works without libstd.This is based on my old PR #17100.
r? @alexcrichton
cc @huonw, @sfackler