Skip to content

Parse underscores in identifiers for format! #9140

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libstd/fmt/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ impl<'self> Parser<'self> {
/// characters.
fn word(&mut self) -> &'self str {
let start = match self.cur.clone().next() {
Some((pos, c)) if char::is_alphabetic(c) => {
Some((pos, c)) if char::is_XID_start(c) => {
self.cur.next();
pos
}
Expand All @@ -563,7 +563,7 @@ impl<'self> Parser<'self> {
let mut end;
loop {
match self.cur.clone().next() {
Some((_, c)) if char::is_alphanumeric(c) => {
Some((_, c)) if char::is_XID_continue(c) => {
self.cur.next();
}
Some((pos, _)) => { end = pos; break }
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/ifmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub fn main() {
t!(format!("{foo} {1} {bar} {0}", 0, 1, foo=2, bar=3), "2 1 3 0");
t!(format!("{} {0:s}", "a"), "a a");
t!(format!("{} {0}", "a"), "a a");
t!(format!("{foo_bar}", foo_bar=1), "1");

// Methods should probably work
t!(format!("{0, plural, =1{a#} =2{b#} zero{c#} other{d#}}", 0u), "c0");
Expand Down