zed/tooling/lints/ui/async_block_without_await.rs
Miguel Raz Guzmán Macedo 4b7369481d
Add dylint lint library for Zed-specific patterns (#58496)
Adds a dylint library under tooling/lints that flags Zed-specific
anti-patterns:

* shared_string_from_str_literal, 
* async_block_without_await, 
* entity_update_in_render, 
* notify_in_render, 
* owned_string_into_shared, 
* len_in_loop_condition, and 
* blocking_io_on_foreground. 

Includes UI tests, a single-lint helper, and workspace.metadata.dylint
registration so cargo dylint --all discovers it. The library pins its
own nightly toolchain (kept out of the main workspace) and tracks dylint
6.

Release Notes:

- N/A

Self-Review Checklist:

- [ ] I've reviewed my own diff for quality, security, and reliability
- [ ] Unsafe blocks (if any) have justifying comments
- [ ] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [ ] Tests cover the new/changed behavior
- [ ] Performance impact has been considered and is acceptable

Closes #ISSUE

Release Notes:

- N/A or Added/Fixed/Improved ...
2026-07-03 22:05:34 +00:00

79 lines
1.6 KiB
Rust

// Tests for the `async_block_without_await` lint.
#![allow(unused)]
async fn returns_42() -> i32 {
42
}
fn sync_fn() -> i32 {
42
}
fn main() {
// --- Should warn ---
// Empty async block.
let _f = async {};
// Async block with a pure expression.
let _f = async { 42 };
// Async move block without await.
let _f = async move {
let x = 1;
x + 2
};
// Async block calling a sync function.
let _f = async { sync_fn() };
// Nested: the *inner* async block has no await (should warn on it).
// The outer block awaits the inner future, so the outer is fine.
let _f = async {
let inner = async { 42 };
inner.await
};
// --- Should NOT warn ---
// Async block with an await.
let _f = async { returns_42().await };
// Async block with await in a let binding.
let _f = async {
let x = returns_42().await;
x + 1
};
// Async move block with await.
let _f = async move { returns_42().await };
// Regular closure (not async at all).
let _f = || 42;
}
// --- Trait impl cases ---
use std::future::Future;
trait AsyncWork {
fn do_work(&self) -> impl Future<Output = i32>;
}
struct Worker;
// Should NOT warn: the trait requires returning a future, so the
// implementor has no choice but to use `async { ... }`.
impl AsyncWork for Worker {
fn do_work(&self) -> impl Future<Output = i32> {
async { 42 }
}
}
// Should warn: inherent impl — the author chose `async` freely.
impl Worker {
fn compute(&self) -> impl Future<Output = i32> {
async { 42 }
}
}