diff options
| author | bors <bors@rust-lang.org> | 2023-10-17 00:35:50 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-10-17 00:35:50 +0000 |
| commit | 2cf708d04f23a8aed92becd2f9141db62d775077 (patch) | |
| tree | 159950262c337f1d2cb6732b3a7a850b1250c11e | |
| parent | 9f27b1562cc8d6f6449cd3c94d89b410b51defc2 (diff) | |
| parent | 6ed04af81c3bf79ee49f88e219fd168ff51886c8 (diff) | |
| download | rust-2cf708d04f23a8aed92becd2f9141db62d775077.tar.gz rust-2cf708d04f23a8aed92becd2f9141db62d775077.zip | |
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`
| -rw-r--r-- | clippy_lints/src/multiple_unsafe_ops_per_block.rs | 7 | ||||
| -rw-r--r-- | tests/ui/multiple_unsafe_ops_per_block.rs | 7 |
2 files changed, 12 insertions, 2 deletions
diff --git a/clippy_lints/src/multiple_unsafe_ops_per_block.rs b/clippy_lints/src/multiple_unsafe_ops_per_block.rs index fe35126aab2..2c42a7a3676 100644 --- a/clippy_lints/src/multiple_unsafe_ops_per_block.rs +++ b/clippy_lints/src/multiple_unsafe_ops_per_block.rs @@ -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 @@ -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![]; diff --git a/tests/ui/multiple_unsafe_ops_per_block.rs b/tests/ui/multiple_unsafe_ops_per_block.rs index 4ef6f0ca92f..8afb4df20af 100644 --- a/tests/ui/multiple_unsafe_ops_per_block.rs +++ b/tests/ui/multiple_unsafe_ops_per_block.rs @@ -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() {} |
