-
Notifications
You must be signed in to change notification settings - Fork 13.3k
format!() should support the same set of \-escapes that regular string literals do #9970
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
Comments
I personally don't believe that the format-string format should not be conforming to what rust as a language uses as a string format. I believe that if we start recognizing What I do think, however, is that the error message could be improved in this case. It's no clear that the error is coming from the format string parser and not the rust string parser, and I believe that distinction would alleviate the problem. |
There were a few ambiguous error messages which look like they could have cropped up from either the rust compiler for the format string parser. To differentiate, the prefix 'invalid format string' is now added in front of all format string errors. cc rust-lang#9970
There were a few ambiguous error messages which look like they could have cropped up from either the rust compiler for the format string parser. To differentiate, the prefix 'invalid format string' is now added in front of all format string errors. cc #9970
Coming from a C/C++ and Ocaml background, rust's behavior is quite confusing. In C: printf("\\\n"); // Outputs: \<new-line> And in Ocaml, format-strings are special strings that enforce types of the arguments: Printf.printf "\\\n"; (* Outputs: \<new-line> *) In Python: print("\\\n") In Rust, we have to write: print!("\\\\\n"); // Outputs: \<new-line> Clearly, for format-strings, the escape character ought to be back-slash, but then
Given the goals of Rust 1.0, I think this issue should be resolved before 1.0 is released. |
I think this issue is already fixed -- |
I believe so as well, thanks @rprichard! |
As long as
format!()
treats\
as an escape character, it should handle all the same escapes that normal string literals do. This way a raw string literal can be passed toformat!()
and still use the expected escapes. Right now, attempting to do so:throws a compiler error:
The text was updated successfully, but these errors were encountered: