pub trait Rule<L: Lang> {
// Required methods
fn name(&self) -> &'static str;
fn check(&self, ctx: RewriteCtx<'_, L>, id: L::Id) -> Option<Edit<L>>;
// Provided methods
fn kinds(&self) -> &'static [NodeKind] { ... }
fn structural(&self) -> bool { ... }
}Expand description
一条简化规则。
Required Methods§
Provided Methods§
Sourcefn kinds(&self) -> &'static [NodeKind]
fn kinds(&self) -> &'static [NodeKind]
本规则关注的节点类别(空 = 全部类别)。pass 循环按类别建分派桶, 无关节点直接跳过检查——“全部规则 × 每节点一次虚调用“是扫描主开销。 声明必须覆盖 check() 入口的真实类别判定:多报只是浪费检查(正确), 漏报会让规则失效(漏改写,回归测试会暴露)。
Sourcefn structural(&self) -> bool
fn structural(&self) -> bool
结构性规则:豁免成本严格下降约束。 适用于“内联后暂时变贵、由后续折叠回本“的变换(如方法内联)。 实现方必须自证终止(如:每次消费一类节点且不引入新的同类节点)。
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".