Skip to content

Typoing dot instead of comma in println! gives a warning at the wrong place #75492

Closed
@vivia

Description

@vivia
use std::time::SystemTime;

fn main() {
    println!("Hello, {:?}!". SystemTime::now());
}

says:

error: expected token: `,`
 --> src/main.rs:4:40
  |
4 |     println!("Hello, {:?}!". SystemTime::now());
  |                                        ^^ expected `,`

... which isn't exactly where the , was expected.

(Playground)

Another variation is this code:

fn random_xkcd_number () -> i32 {
    4
}

fn main() {
    println!("Hello, {}!". random_xkcd_number());
}

which gives this result:

error: format argument must be a string literal
 --> src/main.rs:6:14
  |
6 |     println!("Hello, {}!". random_xkcd_number());
  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
help: you might be missing a string literal to format with
  |
6 |     println!("{}", "Hello, {}!". random_xkcd_number());
  |              ^^^^^

(Playground)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.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