Skip to content

Commit a018a5c

Browse files
committed
Parse underscores in identifiers for format!
Closes #9119
1 parent 03ca1be commit a018a5c

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/libstd/fmt/parse.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ impl<'self> Parser<'self> {
554554
/// characters.
555555
fn word(&mut self) -> &'self str {
556556
let start = match self.cur.clone().next() {
557-
Some((pos, c)) if char::is_alphabetic(c) => {
557+
Some((pos, c)) if char::is_XID_start(c) => {
558558
self.cur.next();
559559
pos
560560
}
@@ -563,7 +563,7 @@ impl<'self> Parser<'self> {
563563
let mut end;
564564
loop {
565565
match self.cur.clone().next() {
566-
Some((_, c)) if char::is_alphanumeric(c) => {
566+
Some((_, c)) if char::is_XID_continue(c) => {
567567
self.cur.next();
568568
}
569569
Some((pos, _)) => { end = pos; break }

src/test/run-pass/ifmt.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ pub fn main() {
8282
t!(format!("{foo} {1} {bar} {0}", 0, 1, foo=2, bar=3), "2 1 3 0");
8383
t!(format!("{} {0:s}", "a"), "a a");
8484
t!(format!("{} {0}", "a"), "a a");
85+
t!(format!("{foo_bar}", foo_bar=1), "1");
8586

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

0 commit comments

Comments
 (0)