Skip to content

Unecessary Warning message #85913

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

Closed
andrewasd opened this issue Jun 1, 2021 · 3 comments · Fixed by #87607
Closed

Unecessary Warning message #85913

andrewasd opened this issue Jun 1, 2021 · 3 comments · Fixed by #87607
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`

Comments

@andrewasd
Copy link

andrewasd commented Jun 1, 2021

I tried this code:

#![allow(dead_code)]

fn fun() -> i32 {
    function() && return 1;

    panic!("stop");
}

fn function() -> bool {
    true
}

fn main() {}

where function is any function that returns a boolean , and it gives the warning
unused logical operator , but actually works as expected, so i think this warning should not come up.

@andrewasd andrewasd added the C-bug Category: This is a bug. label Jun 1, 2021
@asquared31415
Copy link
Contributor

The expression a && return val produces a value, though you will never observe it to be true, because if it is, it will return early. The logical operators are all set up so that it warns if they are not used because in most cases the programmer means to use the value for something. You are not actually using the returned value, since you never read it or assign it to any variable. An explicit discard let _ = a && return val; stops the warning because you indicate that you don't want to use the value and this is not a mistake.

@andrewasd
Copy link
Author

@asquared31415 thank you

@estebank estebank added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` and removed C-bug Category: This is a bug. labels Jun 3, 2021
@bors bors closed this as completed in 337181e Jul 31, 2021
@HKalbasi
Copy link
Member

Is my issue #88017 duplicate of this 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. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants