Skip to content

Format string parser does not fail on invalid input #71088

Closed
@strega-nil

Description

@strega-nil

This code:

struct Foo;

impl Display for Foo {
  fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
    write!(f, "{}", f.fill() as u32)
  }
}

fn main() {
  println!("{:\t}", Foo)
}

Compiles, and prints 32. According to the std::fmt docs,

[[fill]align][sign]['#']['0'][width]['.' precision][type]

is the syntax of format specifications; however, \t does not fulfill any of these elements. I assumed that it might accidentally be implementing the syntax

[fill][align][sign]['#']['0'][width]['.' precision][type]

however, if that were true, then this should print 9 (and not 32). I haven't looked into the parsing code, but will after filing this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions