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

Make multiple_unsafe_ops_per_block ignore await desugaring #11646

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions clippy_lints/src/multiple_unsafe_ops_per_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty;
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::Span;
use rustc_span::{DesugaringKind, Span};

declare_clippy_lint! {
/// ### What it does
Expand Down Expand Up @@ -64,7 +64,10 @@ declare_lint_pass!(MultipleUnsafeOpsPerBlock => [MULTIPLE_UNSAFE_OPS_PER_BLOCK])

impl<'tcx> LateLintPass<'tcx> for MultipleUnsafeOpsPerBlock {
fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx hir::Block<'_>) {
if !matches!(block.rules, BlockCheckMode::UnsafeBlock(_)) || in_external_macro(cx.tcx.sess, block.span) {
if !matches!(block.rules, BlockCheckMode::UnsafeBlock(_))
|| in_external_macro(cx.tcx.sess, block.span)
|| block.span.is_desugaring(DesugaringKind::Await)
{
return;
}
let mut unsafe_ops = vec![];
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/multiple_unsafe_ops_per_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,11 @@ fn _field_fn_ptr(x: unsafe fn()) {
}
}

// await expands to an unsafe block with several operations, but this is fine.: #11312
async fn await_desugaring_silent() {
async fn helper() {}

helper().await;
}

fn main() {}