Skip to content

Error on incomplete macro call could provide more context, specially for built-in macros like write! not receiving the Formatter #152493

@estebank

Description

@estebank

Code

struct S;
impl std::fmt::Display for S {
    fn fmt (&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            S => write!("S"),
        } 
               
    }
}

Current output

error: unexpected end of macro invocation
   --> src/lib.rs:5:28
    |
  5 |             S => write!("S"),
    |                            ^ missing tokens in macro arguments
    |
note: while trying to match `,`
   --> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/macros/mod.rs:611:15
    |
611 |     ($dst:expr, $($arg:tt)*) => {
    |               ^

Desired output

For println we mention when we're missing the formatting string:

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

We should do something similar for write and writeln. Potentially for macros in general (emit an error with "expected 2 comma separated arguments, only one passed" or the like).

Rust Version

Nightly channel
Build using the Nightly version: 1.95.0-nightly
(2026-02-10 9e79395f92bff6a8f536)

Anything else?

Initially reported at https://users.rust-lang.org/t/implementing-the-display-trait-for-an-enum/138218

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)P-lowLow priorityT-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