Skip to content
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

Unused results lint fails on trivial program #43806

Closed
milibopp opened this issue Aug 11, 2017 · 10 comments
Closed

Unused results lint fails on trivial program #43806

milibopp opened this issue Aug 11, 2017 · 10 comments
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@milibopp
Copy link
Contributor

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)
@Mark-Simulacrum Mark-Simulacrum added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 11, 2017
@Mark-Simulacrum
Copy link
Member

Bisected to #43728, cc @zackmdavis, @eddyb

@kennytm
Copy link
Member

kennytm commented Aug 11, 2017

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

#![deny(unused_results)]
fn g() {}
fn main() {
    g(); //~ ERROR unused result
}

@pengowen123
Copy link
Contributor

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

@zackmdavis
Copy link
Member

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.

@zackmdavis
Copy link
Member

@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?

@pengowen123
Copy link
Contributor

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

@zackmdavis
Copy link
Member

@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.

@alexcrichton
Copy link
Member

This is being fixed in #43813

bors added a commit that referenced this issue Aug 13, 2017
Fix unused_result lint triggering when a function returns `()`, `!` or an empty enum

Also added a test to prevent this from happening again.

Fixes #43806
@pengowen123
Copy link
Contributor

pengowen123 commented Aug 16, 2017

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

EDIT: Nevermind, this is intended behavior.

@briansmith
Copy link
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
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. 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

7 participants