Update char::escape_debug_ext to handle different escapes in strings and chars#83079
Update char::escape_debug_ext to handle different escapes in strings and chars#83079bors merged 1 commit intorust-lang:masterfrom osa1:issue83046
Conversation
|
r? @m-ou-se (rust-highfive has picked a reviewer for you, use r? to override) |
|
I'll update docs of |
This comment has been minimized.
This comment has been minimized.
|
I'll add a test, which directory should I put it? |
This comment has been minimized.
This comment has been minimized.
library/core/src/char/methods.rs
Outdated
There was a problem hiding this comment.
Should I introduce a struct for these bool args?
This comment has been minimized.
This comment has been minimized.
|
I don't have time to tweak this more today, I'll get back to this later. |
library/core/src/fmt/mod.rs
Outdated
There was a problem hiding this comment.
Debug output of str now escapes " but not '.
library/core/src/fmt/mod.rs
Outdated
There was a problem hiding this comment.
Debug output of char not escapes ' but not ".
|
I believe this should currently be completely backwards compatible, other than For some reason |
library/core/src/char/methods.rs
Outdated
There was a problem hiding this comment.
Escapes both ' and ", as before.
library/core/src/str/mod.rs
Outdated
There was a problem hiding this comment.
Escapes both ' and ", as before.
library/core/src/str/mod.rs
Outdated
There was a problem hiding this comment.
Escapes both ' and ", as before.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@m-ou-se This is ready for reviews now. I'll squash the commits once all is done. |
|
This seems like a great idea. I think enum EscapeChars {
EscapeSingleQuote,
EscapeDoubleQuote,
EscapeBothQuotes,
}
impl EscapeChars {
fn escape_single_quote(&self) -> bool {
match self {
...
}
}
fn escape_double_quote(&self) -> bool {
match self {
...
}
}
}I'm hoping that'll produce generated code that's just as efficient. |
|
☔ The latest upstream changes (presumably #83301) made this pull request unmergeable. Please resolve the merge conflicts. |
|
@joshtriplett I didn't quite understand how that enum would work, but I added a struct for to give names to the bool args. I'll squash the commits before merge. Ping @m-ou-se |
|
Ping @m-ou-se |
|
Thanks! @bors r+ |
|
📌 Commit 52db9708dbb5fbfde615fa2c64c92656b6e610ac has been approved by |
…vs. chars Fixes #83046 The program fn main() { println!("{:?}", '"'); println!("{:?}", "'"); } would previously print '\"' "\'" With this patch it now prints: '"' "'"
|
@m-ou-se Thanks for the review. I squashed the commits, could you approve again please? |
|
@bors r+ |
|
📌 Commit 819247f has been approved by |
|
☀️ Test successful - checks-actions |
Free lunch is over, Debug representation for str has changed (rust-lang/rust#83079). Roll our own version based on the stable `escape_debug()` method instead. Also spell out all the enums while at it.
Run tarpaulin for code coverage on stable rust instead of nightly. Nightly rust has our test cases failing due to the changed debug printing of strings with single quotes "'" so our test cases using should_panic(expected = <error message>) are failing. See rust-lang/rust#83079
The change in [1] is now in stable. [1]: rust-lang/rust#83079
Run tarpaulin for code coverage on stable rust instead of nightly. Nightly rust has our test cases failing due to the changed debug printing of strings with single quotes "'" so our test cases using should_panic(expected = <error message>) are failing. See rust-lang/rust#83079
Fixes #83046
The program
would previously print
With this patch it now prints: