Skip to content

unused_must_use lint after write! fails to note its origin #54288

New issue

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

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

Already on GitHub? Sign in to your account

Open
pnkfelix opened this issue Sep 17, 2018 · 2 comments
Open

unused_must_use lint after write! fails to note its origin #54288

pnkfelix opened this issue Sep 17, 2018 · 2 comments
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@pnkfelix
Copy link
Member

Consider the following code (play):

// Uncomment the `cfg` to see expected output noting `#[warn(unused_must_use)]`
// #[cfg(without_write)]
pub fn encode_json<T: std::fmt::Display>(val: &T, wr: &mut Vec<u8>) {
    use std::io::Write;
    write!(wr, "{}", val);
}

pub fn after_write_macro() {
    Result::Ok::<_, ()>(());
}

fn main() {
}

It generates the following warning:

warning: unused `std::result::Result` which must be used
 --> src/main.rs:9:5
  |
9 |     Result::Ok::<_, ()>(());
  |     ^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this `Result` may be an `Err` variant, which should be handled

which is almost, but not quite, what I expect to see.

Namely, I expect to see this:

warning: unused `std::result::Result` which must be used
 --> src/main.rs:9:5
  |
9 |     Result::Ok::<_, ()>(());
  |     ^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(unused_must_use)] on by default
  = note: this `Result` may be an `Err` variant, which should be handled

which includes the useful note: #[warn(unused_must_use)] on by default

As far as I can tell, the choice whether or not to include that note is based on the presence/absence of the earlier write! invocation.

(Hypothesis: perhaps there is an occurrence of an unused must_use within that macros expansion that we are silencing, but even though it is silenced, it is erroneously counted in whatever mechanism we are using to avoid printing out multiple redundant instances of notes like note: #[warn(unused_must_use)] on by default?)

@zackmdavis zackmdavis added the A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. label Sep 17, 2018
@zackmdavis
Copy link
Member

whatever mechanism we are using to avoid printing out multiple redundant instances of notes

(The deduplication is done by checking a one_time_diagnostics field on the Session that gets populated by appropriate methods.)

@pnkfelix pnkfelix added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Sep 19, 2018
pnkfelix added a commit to pnkfelix/rust that referenced this issue Sep 21, 2018
…ontinue under ui test mode.

(One of them led me to file rust-lang#54288.)
@Enselic
Copy link
Member

Enselic commented Oct 15, 2023

Triage: Still reproduces despite various fixes related to this (see e.g. most recently linked issue).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. 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

3 participants