]> git.lizzy.rs Git - rust.git/commit
Allow any identifier as format arg name
authorDavid Tolnay <dtolnay@gmail.com>
Thu, 28 Nov 2019 18:49:13 +0000 (10:49 -0800)
committerDavid Tolnay <dtolnay@gmail.com>
Thu, 28 Nov 2019 19:24:51 +0000 (11:24 -0800)
commit423a5d3e858630e549640763d9022c18bdd68f7a
tree4ab6ba5fa78b57af343e3d16401007b8925eef99
parentf453d1127d9095cf3c3356655d9e8502ceeb8373
Allow any identifier as format arg name

Previously:

    error: invalid format string: invalid argument name `_x`
     --> src/main.rs:2:16
      |
    2 |     println!("{_x}", a=0);
      |                ^^ invalid argument name in format string
      |
      = note: argument names cannot start with an underscore

Not supporting identifiers starting with underscore appears to have been
an arbitrary limitation from 2013 in code that was most likely never
reviewed:
https://github.com/rust-lang/rust/pull/8245/files#diff-0347868ef389c805e97636623e4a4ea6R277

The error message was dutifully improved in #50610 but is there any
reason that leading underscore would be a special case?

This commit updates the format_args parser to accept identifiers with
leading underscores.
src/libfmt_macros/lib.rs
src/test/ui/fmt/format-string-error.rs
src/test/ui/fmt/format-string-error.stderr
src/test/ui/ifmt.rs