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

Irritating "unused" warning #108885

Closed
FlorianDyck opened this issue Mar 8, 2023 · 4 comments · Fixed by #109158
Closed

Irritating "unused" warning #108885

FlorianDyck opened this issue Mar 8, 2023 · 4 comments · Fixed by #109158
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@FlorianDyck
Copy link

FlorianDyck commented Mar 8, 2023

Code

fn main() {
    let mut vec = vec![[0].iter(), [1].iter()];
    vec.remove(0);
}

Current output

warning: unused `std::slice::Iter` that must be used
  --> src\main.rs:52:5
   |
52 |     vec.remove(0);
   |     ^^^^^^^^^^^^^^
   |
   = note: iterators are lazy and do nothing unless consumed

Desired output

No warning when nothing is done to an iterator or similar when they are returned from a function with side effects.

If a warning is shown, it should be like this:

warning: unused return value.
You can use `let _ = vec.remove(0)` to signify that dropping it without usage is the intended behavior.

Rationale and extra context

rustc finds that remove returns an iterator.
Obviously I am not doing anything with it.
But the of the line is not to do something with the iterator, but to remove it from the list.

Other cases

No response

Anything else?

No response

@FlorianDyck FlorianDyck added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 8, 2023
@workingjubilee
Copy link
Member

You may silence the warning with let _ = vec.remove(0);

@workingjubilee workingjubilee added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. labels Mar 8, 2023
@workingjubilee
Copy link
Member

This diagnostic should recommend that.

@FlorianDyck
Copy link
Author

FlorianDyck commented Mar 8, 2023

In this case I think the output could be improved to:

warning: unused return value.
You can use "let _ = ..." to signify that dropping it without usage is the intended behavior.

@Ezrashaw
Copy link
Contributor

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants