Skip to content

Confusing error message with invalid format specifier #23476

Closed
@mrmonday

Description

@mrmonday

The following code:

fn main() {
    let _ = format!("{_foo}", _foo = 6u);
}

(Playpen: http://is.gd/me8pNE)

Gives the error:

<anon>:2:21: 2:29 error: invalid format string: expected `'}'`, found `'_'`
<anon>:2     let _ = format!("{_foo}", _foo = 6u);
                             ^~~~~~~~
error: aborting due to previous error

It is not too confusing in this short example, but in a longer string it is not obvious that named identifiers cannot start with an underscore.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-syntaxextArea: Syntax extensionsC-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions