-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Make map_err_ignore
lint more precise
#6376
Conversation
…dated map_err.rs ui test to make sure we only fail on '.map_err(|_| Unit::Enum)'
I understand that this lint is producing a large amount of unwanted warns, but this is an arbitrary reduction IMHO. A unit enum very well may provide all the context that is needed for a particular error. And with a non-unit-enum, the error is still discarded and context is potentially lost. Idea: What if we allowed on Or maybe it should just be a restriction lint. |
The lint will indeed pass if you have:
|
Yes, I think we should hint to the user that that option available. Though I wonder if we should "officially" only support |
…closure parameter (e.g. _ignored) to convey they are intentionally ignoring the original error and avoid this lint without needing an allow attribute
IMO we should treat I would go for moving this lint to |
FWIW, I got the idea from IntelliJ which does not lint on an empty |
I would be personally more open to that if it was a convention, not sure if it is in Java. But to me, identifiers are "very personal territory", i.e. flame war assured :) |
Well I think it's a convention imposed by IntelliJ... |
There is a difference between My feeling is that this lint is less useful if it only lints unit enums. My impression of this lint is that it's for users who want to include as much information in their error reports as possible and users who want help avoiding accidentally discarding errors, catching errors that they discarded in the past before when they weren't be careful about error handling. To me using strings as errors and discarding the source falls squarely into the "probably wasn't caring about error handling earlier" case where someone might want to enable this lint to clean up all instances of the old error handling style. My preference would be to do the following:
|
I definitely agree with @yaahc, if we cannot keep this in I am going to do this in a new MR since this one's intention will now change. |
I'm not sure that supports the way this lint works because that tells me I should prefer |
I don't think it actually matters in function arguments, as far as I can tell arguments don't drop early if not bound the same way they do in let statements. #[derive(Debug)]
struct DropPrint(&'static str);
impl Drop for DropPrint {
fn drop(&mut self) {
println!("dropped {:?}", self)
}
}
fn main() {
let _ignored = DropPrint("first");
let _ = DropPrint("second");
print_ignore(DropPrint("third"));
print_nobind(DropPrint("fourth"));
}
fn print_ignore(_ignore: DropPrint) {
println!("print ignore");
}
fn print_nobind(_: DropPrint) {
println!("print nobind");
} Running this prints the following:
So there's no actual difference between them in this context. Imo |
In case someone was subscribed to this PR the new one is here: #6416 |
Thanks @ebroto :) |
@lopopolo Noticed the that
map_err_ignore
lint was not as precise as it should be and gave some good examples in their codebase.This now checks the body of the closure is a unit enum variant (as the original intent of the lint) and updates the uitest for
map_err
to make sure we only warn on this case.I have also tested on their code, and appears good (after removing all
#![allow(clippy::map_err_ignore)]
s)!r? @yaahc
Please write a short comment explaining your change (or "none" for internal only changes)
changelog: Make
map_err_ignore
lint more precise