Skip to content

Commit 2cf708d

Browse files
committed
Auto merge of #11646 - Nilstrieb:compiler-does-not-comply-with-the-lints!!, r=giraffate
Make `multiple_unsafe_ops_per_block` ignore await desugaring The await desugaring contains two calls (`Poll::new_unchecked` and `get_context`) inside a single unsafe block. That violates the lint. fixes #11312 changelog: [`multiple_unsafe_ops_per_block`]: fix false positives in `.await`
2 parents 9f27b15 + 6ed04af commit 2cf708d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

clippy_lints/src/multiple_unsafe_ops_per_block.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_lint::{LateContext, LateLintPass};
99
use rustc_middle::lint::in_external_macro;
1010
use rustc_middle::ty;
1111
use rustc_session::{declare_lint_pass, declare_tool_lint};
12-
use rustc_span::Span;
12+
use rustc_span::{DesugaringKind, Span};
1313

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

6565
impl<'tcx> LateLintPass<'tcx> for MultipleUnsafeOpsPerBlock {
6666
fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx hir::Block<'_>) {
67-
if !matches!(block.rules, BlockCheckMode::UnsafeBlock(_)) || in_external_macro(cx.tcx.sess, block.span) {
67+
if !matches!(block.rules, BlockCheckMode::UnsafeBlock(_))
68+
|| in_external_macro(cx.tcx.sess, block.span)
69+
|| block.span.is_desugaring(DesugaringKind::Await)
70+
{
6871
return;
6972
}
7073
let mut unsafe_ops = vec![];

tests/ui/multiple_unsafe_ops_per_block.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,11 @@ fn _field_fn_ptr(x: unsafe fn()) {
147147
}
148148
}
149149

150+
// await expands to an unsafe block with several operations, but this is fine.: #11312
151+
async fn await_desugaring_silent() {
152+
async fn helper() {}
153+
154+
helper().await;
155+
}
156+
150157
fn main() {}

0 commit comments

Comments
 (0)