Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
theemathas opened this issue Jun 14, 2024 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@theemathas
Copy link
Contributor

theemathas commented Jun 14, 2024

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

@theemathas theemathas added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 14, 2024
@theemathas theemathas changed the title An unused output of format!() and some other macros should produce a unused_must_use warning. An unused output of some macros in std (e.g., format!()) should produce a unused_must_use warning. Jun 15, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jul 8, 2024
Mark format! with must_use hint

Uses unstable feature rust-lang#94745

Part of rust-lang#126475

First contribution to rust, please let me know if the blessing of tests is correct
Thanks `@bjorn3` for the help
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jul 8, 2024
Rollup merge of rust-lang#127355 - aceArt-GmbH:126475, r=oli-obk

Mark format! with must_use hint

Uses unstable feature rust-lang#94745

Part of rust-lang#126475

First contribution to rust, please let me know if the blessing of tests is correct
Thanks `@bjorn3` for the help
flip1995 pushed a commit to flip1995/rust that referenced this issue Jul 11, 2024
Mark format! with must_use hint

Uses unstable feature rust-lang#94745

Part of rust-lang#126475

First contribution to rust, please let me know if the blessing of tests is correct
Thanks `@bjorn3` for the help
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

1 participant