-
Notifications
You must be signed in to change notification settings - Fork 2k
fixes issue 17162 false positive for never type impls #17163
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
base: master
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -257,13 +257,21 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync { | |
| visitor.visit_nested_body(body_id); | ||
|
|
||
| if !visitor.found_await | ||
| && let Some(builtin_crate) = clippy_utils::std_or_core(cx) | ||
| && let Some(inner) = unpack_async_fn_body(cx, body) | ||
| // Find the tail expression contained in the async fn (if any), | ||
| // which will be wrapped in std::future::ready. | ||
| && let ExprKind::Block(block, _) = inner.kind | ||
| && let Some(tail_expr) = block.expr | ||
| && let Some(builtin_crate) = clippy_utils::std_or_core(cx) | ||
| && let Some(inner) = unpack_async_fn_body(cx, body) | ||
| // Find the tail expression contained in the async fn (if any), | ||
| // which will be wrapped in std::future::ready. | ||
| && let ExprKind::Block(block, _) = inner.kind | ||
| && let Some(tail_expr) = block.expr | ||
| { | ||
| let parent = cx.tcx.hir_get_parent_item(impl_item.hir_id()).def_id; | ||
| let item = cx.tcx.hir_expect_item(parent); | ||
| let self_ty = cx.tcx.type_of(item.owner_id).instantiate_identity().skip_norm_wip(); | ||
| //check if self.ty is never type ! if it is, then we don't want to lint because the function can | ||
| // never be called and thus doesn't need to be async | ||
| if self_ty.is_never() { | ||
| return; | ||
| } | ||
|
Comment on lines
+267
to
+274
Contributor
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. The actual important thing to check is if any of the input types are uninhabited. You can use
Contributor
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. That would mean that this check should be applied to freestanding functions as well, right? So it would probably make sense to extract it to a separate function, and call that both here and in
Contributor
Author
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. okay i will change the self_ty.is_never() to use is_inhabited_from instead.
Contributor
Author
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. could you perhaps explain that func? the is_inhabited_from? because there is only 1 reference of it in the whole codebase and that ref is very vague of what is expects imo
Contributor
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. Everything you need is in The function returns how the item passed views a type's inhabitedness. A struct containing a private uninhabited field can only be seen as uninhabited from items that can access that field. |
||
| span_lint_and_then( | ||
| cx, | ||
| UNUSED_ASYNC_TRAIT_IMPL, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
These shouldn't be changed.
View changes since the review
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.
idk why those got changed tbh maybe because of cargo dev fmt?