rust-lang / rust-lang/rust

An unused output of some macros in std (e.g., `format!()`) should produce a unused_must_use warning.

Open
#126,475 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
fn main() {
    format!("{}", 1);
}
Current output
No errors or warnings
Desired output
warning: unused return value of `format!()` that must be used
Rationale and extra context

The format!() macro could probably expand to code containing std::hint::must_use.

List of macros with similar issues:

  • cfg!()
  • column!(), line!(), file!(), module_path!()
  • concat!(), stringify!()
  • env!(), option_env!()
  • format!(), format_args!()
  • include_bytes!(), include_str!()
  • matches!()
  • vec!()
  • pin::pin!()
Other cases

No response

Rust Version
Nightly rust on playground: 1.81.0-nightly (2024-06-13 f1586001ace26df7cafe)
Anything else?

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Rust example and comparing its current output with the desired unused_must_use warning. Review the listed macros, beginning with format!(), and determine which expansions need the requested must-use behavior; done means unused outputs produce warnings without changing valid uses.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.