Skip to content

Unused results lint fails on trivial program #43806

Closed

Description

@milibopp

The unused_results lint appears to be somewhat overzealous on the current nightly compiler. I managed to reduce the issue down to a simple hello world-program, so something is definitely broken.

I tried this code:

#![deny(unused_results)]

fn main() {
    println!("hello world!");
}

I expected to see the code compile successfully without any warnings.

Instead, the following error message showed up.

error: unused result
 --> src/main.rs:4:5
  |
4 |     println!("hello world!");
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^
  |
note: lint level defined here
 --> src/main.rs:1:9
  |
1 | #![deny(unused_results)]
  |         ^^^^^^^^^^^^^^
  = note: this error originates in a macro outside of the current crate

Meta

$ rustc --version
rustc 1.21.0-nightly (13d94d5fa 2017-08-10)

Activity

  1. added
    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
    C-bugCategory: This is a bug.
    P-highHigh priority
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Aug 11, 2017
  2. Mark-Simulacrum commented on Aug 11, 2017

    @Mark-Simulacrum
    Member

    Bisected to #43728, cc @zackmdavis, @eddyb

  3. kennytm commented on Aug 11, 2017

    @kennytm
    Member

    Every function call, even those returning () or !, are considered unused now. 😕

    #![deny(unused_results)]
    fn g() {}
    fn main() {
        g(); //~ ERROR unused result
    }
  4. pengowen123 commented on Aug 11, 2017

    @pengowen123
    Contributor

    I would like to work on this if no one else wants to.

  5. zackmdavis commented on Aug 11, 2017

    @zackmdavis
    Contributor

    I see. During #43728, I put the new ununsed-for-functions code after the existing unused-must-use code but before the unused-results check, and modified the unused-must-use code to not return early for types that couldn't be results (including, notably, () and !), because I wanted to "fall through" to the unused-for-functions code. But () and ! shouldn't furthermore "fall through" and be seen as unused results.

    😰 😢 😞 Sorry, I can submit a fix this afternoon. Thanks for the report, @aepsil0n.

  6. zackmdavis commented on Aug 11, 2017

    @zackmdavis
    Contributor

    @pengowen123 I think I'm morally obligated to do everything in my power to minimize the number of nightlies that are contaminated with my mistake, so I should probably take this unless you're really enthusiastic about fixing it today?

  7. pengowen123 commented on Aug 11, 2017

    @pengowen123
    Contributor

    @zackmdavis I should be able to fix it today. Don't worry about it being your mistake, I will work on it.

  8. zackmdavis commented on Aug 11, 2017

    @zackmdavis
    Contributor

    @pengowen123 Works for me. I think returning early before the unused-results check if t.sty is ty::TyNever or the empty tuple should suffice? And we'd also want a UI test of the unused_result lint working as expected to make sure this can never happen again.

  9. alexcrichton commented on Aug 12, 2017

    @alexcrichton
    Member

    This is being fixed in #43813

  10. added a commit that references this issue on Aug 13, 2017
    d4fbc7a
  11. pengowen123 commented on Aug 16, 2017

    @pengowen123
    Contributor

    This is still broken for functions returning structs or non-empty enums. I am working on fixing this.

    EDIT: Nevermind, this is intended behavior.

  12. briansmith commented on Aug 28, 2017

    @briansmith
    Contributor

    See also #44119. It seems the unused_results lint is stricter now, including for example on functions returning boolean results like PathBuf::set_extension().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions