Skip to repository content59 lines · 1.7 KB · rust
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T02:25:17.873Z Public web read
NIP-34 coordinate
30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omegaMaintainersHidden in public view
References2 branches · 1 tag
Read-only clone
git clone https://openagents.com/git/tenant.openagents/omega.gitBrowse files
notify_in_render.rs
1use clippy_utils::diagnostics::span_lint;
2use rustc_hir::{Expr, ExprKind};
3use rustc_lint::{LateContext, LateLintPass};
4
5use crate::render_helpers::{is_directly_in_render_method, is_gpui_context};
6
7rustc_session::declare_lint! {
8 /// ### What it does
9 ///
10 /// Flags calls to `Context::notify()` that execute synchronously inside a
11 /// `Render::render` method.
12 ///
13 /// ### Why is this bad?
14 ///
15 /// `notify()` tells the framework that the entity's state has changed and
16 /// it should be re-rendered. Calling it during render means every render
17 /// pass schedules another render pass — either an infinite loop or wasted
18 /// work.
19 pub NOTIFY_IN_RENDER,
20 Warn,
21 "calling `cx.notify()` during render schedules a redundant re-render"
22}
23
24pub(crate) struct NotifyInRender;
25
26rustc_session::impl_lint_pass!(NotifyInRender => [NOTIFY_IN_RENDER]);
27
28impl<'tcx> LateLintPass<'tcx> for NotifyInRender {
29 fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
30 if expr.span.from_expansion() {
31 return;
32 }
33
34 let ExprKind::MethodCall(segment, receiver, _args, _span) = &expr.kind else {
35 return;
36 };
37
38 if segment.ident.name.as_str() != "notify" {
39 return;
40 }
41
42 let receiver_ty = cx.typeck_results().expr_ty(receiver);
43 if !is_gpui_context(cx, receiver_ty) {
44 return;
45 }
46
47 if !is_directly_in_render_method(cx, expr.hir_id) {
48 return;
49 }
50
51 span_lint(
52 cx,
53 NOTIFY_IN_RENDER,
54 expr.span,
55 "`cx.notify()` called during render schedules a re-render every render pass",
56 );
57 }
58}
59