{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreie5c2odjetd5a4ec6kq3ds2cbsoedi6i33sw6ctx5rkl3cp2b6c2m",
    "uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mi7v2ae4ai62"
  },
  "path": "/t/idea-must-use-inherit/24117#post_1",
  "publishedAt": "2026-03-29T19:19:33.000Z",
  "site": "https://internals.rust-lang.org",
  "tags": [
    "double_must_use"
  ],
  "textContent": "An ability to inherit _reason_ of `#[must_use]` (not _whether it is_ `#[must_use]`). If there is no `#[must_use]` to inherit, it errors.\n\n# Motivation\n\nSide note: I know there are other cases that `#[must_use]` gets triggered without putting `#[must_use]` on the function, but will mention only return types for briefness.\n\nThere is a clippy lint double_must_use, warn by default. The lint warns:\n\n\n    #[must_use] // warning!\n    fn f() -> Result<Thing, ()> {\n      todo!()\n    }\n\n\nThe point of the above is:\n\n  1. `Result<T, E>` is already marked as `#[must_use]` with some message.\n  2. `f` is marked as `#[must_use]`, with no message.\n  3.      1. and 2. are reported as separate diagnostic and `#[must_use]` on `f` is less informative, therefore `#[must_use]` on `f` should be removed.\n\n\n\nIt seems reasonable, but my concern is:\n\n\n    // Someday `Result<T, E>` became no longer needed, so got back to just `T`\n    // But I forgot to put `#[must_use]` again!\n    fn f() -> Thing {\n      todo!()\n    }\n\n\nI found that what we want is \"propagate the `#[must_use]` message\", not \"let's delegate whether the function is `#[must_use]`, to the return type\".\n\nDoes removing `#[must_use]` from `fn f() -> Result<Thing, ()>` mean the return value no longer must be used? No. It still must be used, but messages are taken from the return type. Explicit `#[must_use = inherit]` reflects this semantic well.\n\n# Additionally Needed Change\n\n>   3.      1. and 2. are reported as separate diagnostic and ...\n>\n\n\nWe need to change this behavior to emit single warning, before introducing this feature. If we leave it as it is, the output will be quite confusing as warnings will get doubled. I'm considering to make `#[must_use]` on a function to override `#[must_use]` on the return type as it seems rational behavior, but it is problematic because it _removes_ relatively more informative messages, not just confusing users a bit. Maybe we could make `#[must_use = inherit]` the default behavior for `#[must_use]`, but I'm not sure if it is a breaking change.",
  "title": "Idea: #[must_use = inherit]"
}