-
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
redundant_closure
fix FP on coerced closure
#8431
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,12 +24,6 @@ error: redundant closure | |
LL | all(&[1, 2, 3], &&2, |x, y| below(x, y)); //is adjusted | ||
| ^^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `below` | ||
|
||
error: redundant closure | ||
--> $DIR/eta.rs:40:27 | ||
| | ||
LL | let e = Some(1u8).map(|a| divergent(a)); | ||
| ^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `divergent` | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like a false negative because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I definitely misunderstood the bug in the example. I will take a further look. Thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like checking for coerced closure is not enough. In the case above, it seems like the closure is coerced to Ignoring coerced closures is not hard, but it does produce false negatives such as the case above. Although I'd say that this is still an improvement over all the false positives. A full solution would be to check if type-check is resolvable for the call/method-call taking |
||
error: redundant closure | ||
--> $DIR/eta.rs:41:27 | ||
| | ||
|
@@ -122,11 +116,5 @@ error: redundant closure | |
LL | Some(1).map(|n| in_loop(n)); | ||
| ^^^^^^^^^^^^^^ help: replace the closure with the function itself: `in_loop` | ||
|
||
error: redundant closure | ||
--> $DIR/eta.rs:236:21 | ||
| | ||
LL | map_str_to_path(|s| s.as_ref()); | ||
| ^^^^^^^^^^^^^^ help: replace the closure with the method itself: `std::convert::AsRef::as_ref` | ||
|
||
error: aborting due to 21 previous errors | ||
error: aborting due to 19 previous errors | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that
is_adjusted
is a bit too restrictive. The example cases all are related to the never type. Therefore, I would only suppress the lint if the wrapped function returns the never type, in all other cases it seems like the normal adjustment has worked its magic.Have you tried the following two options?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is not
never
type, but it's when the wrapped function can only be resolved by typechecks by adjusting it to return()
type.It gets adjusted to
()
type.Yes, the only way that I see for a complete solution is to check if the function typecheck can be resolved to accept the original return type of the closure. I'm not sure this is trivial to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like I also misunderstood the issue at first. The type adjustment to
()
sounds like a quirk of the type checking system.In that case, I think that your fix is the correct one. It will have some FNs but those are better than FPs IMO. 🙃