-
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
Mini-fix double_must_use
for async functions
#10589
Conversation
r? @giraffate (rustbot has picked a reviewer for you, use r? to override) |
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.
Can this catch the case #[must_use] async fn async_result() -> Result<(), ()> { Ok(()) }
?
@@ -43,7 +44,7 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_> | |||
} | |||
|
|||
pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) { | |||
if let hir::ImplItemKind::Fn(ref sig, ref body_id) = item.kind { | |||
if let hir::ImplItemKind::Fn(ref sig, ref body_id) = item.kind && !sig.header.is_async() /* (#10486) */ { |
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.
Does this affect must_use_unit
? If so, it would seem to me that it should be limited to double_must_use
only.
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.
Fixed in the last commit.
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.
Thanks! I made one comment.
2781fc9
to
d602743
Compare
} | ||
|
||
#[must_use] | ||
async fn async_must_use_result() -> Result<(), ()> { |
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.
It looks like that this case is false negative. It would be better to check that the return type in async function already has #[must_use]
. I think we can get the type from Future::Output
like below:
let infcx = cx.tcx.infer_ctxt().build();
let Some(ret_ty) = infcx.get_impl_future_output_ty(return_ty(cx, item_id));
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.
Fixed
4b27377
to
f4b701e
Compare
f4b701e
to
a37eb4d
Compare
@bors r+ Thanks! |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
From Rust 1.67 onwards, the
#[must_use]
attribute also applies to theFuture::Output
(rust-lang/rust#100633). So the lintdouble_must_use
was linting all async functions. This PR changes thedouble_must_use
lint so it ignoresasync
functions.Closes #10486
changelog: [
double_must_use
]: Fix false positive in async function