Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions crates/lint/src/linter/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ use super::LintContext;

/// Trait for lints that operate on the HIR (High-level Intermediate Representation).
/// Its methods mirror `hir::visit::Visit`, with the addition of `LintContext`.
///
/// The original `check_nested_*` hooks took borrowed IDs, but current `solar::hir::Visit`
/// dispatches nested IDs by value. Those legacy hooks are kept as deprecated compatibility shims;
/// `LateLintVisitor` dispatches the corresponding `*_id` hooks instead.
pub trait LateLintPass<'hir>: Send + Sync {
fn check_nested_source(
&mut self,
Expand All @@ -13,34 +17,74 @@ pub trait LateLintPass<'hir>: Send + Sync {
_id: hir::SourceId,
) {
}
#[deprecated(
note = "use check_nested_item_id instead; current solar::hir::Visit passes ItemId by value"
)]
fn check_nested_item(
&mut self,
_ctx: &LintContext,
_hir: &'hir hir::Hir<'hir>,
_id: &'hir hir::ItemId,
) {
}
fn check_nested_item_id(
&mut self,
_ctx: &LintContext,
_hir: &'hir hir::Hir<'hir>,
_id: hir::ItemId,
) {
}
#[deprecated(
note = "use check_nested_contract_id instead; current solar::hir::Visit passes ContractId by value"
)]
fn check_nested_contract(
&mut self,
_ctx: &LintContext,
_hir: &'hir hir::Hir<'hir>,
_id: &'hir hir::ContractId,
) {
}
fn check_nested_contract_id(
&mut self,
_ctx: &LintContext,
_hir: &'hir hir::Hir<'hir>,
_id: hir::ContractId,
) {
}
#[deprecated(
note = "use check_nested_function_id instead; current solar::hir::Visit passes FunctionId by value"
)]
fn check_nested_function(
&mut self,
_ctx: &LintContext,
_hir: &'hir hir::Hir<'hir>,
_id: &'hir hir::FunctionId,
) {
}
fn check_nested_function_id(
&mut self,
_ctx: &LintContext,
_hir: &'hir hir::Hir<'hir>,
_id: hir::FunctionId,
) {
}
#[deprecated(
note = "use check_nested_var_id instead; current solar::hir::Visit passes VariableId by value"
)]
fn check_nested_var(
&mut self,
_ctx: &LintContext,
_hir: &'hir hir::Hir<'hir>,
_id: &'hir hir::VariableId,
) {
}
fn check_nested_var_id(
&mut self,
_ctx: &LintContext,
_hir: &'hir hir::Hir<'hir>,
_id: hir::VariableId,
) {
}
fn check_item(
&mut self,
_ctx: &LintContext,
Expand Down Expand Up @@ -143,6 +187,34 @@ where
self.walk_nested_source(id)
}

fn visit_nested_item(&mut self, id: hir::ItemId) -> ControlFlow<Self::BreakValue> {
for pass in self.passes.iter_mut() {
pass.check_nested_item_id(self.ctx, self.hir, id);
}
self.walk_nested_item(id)
}

fn visit_nested_contract(&mut self, id: hir::ContractId) -> ControlFlow<Self::BreakValue> {
for pass in self.passes.iter_mut() {
pass.check_nested_contract_id(self.ctx, self.hir, id);
}
self.walk_nested_contract(id)
}

fn visit_nested_function(&mut self, id: hir::FunctionId) -> ControlFlow<Self::BreakValue> {
for pass in self.passes.iter_mut() {
pass.check_nested_function_id(self.ctx, self.hir, id);
}
self.walk_nested_function(id)
}

fn visit_nested_var(&mut self, id: hir::VariableId) -> ControlFlow<Self::BreakValue> {
for pass in self.passes.iter_mut() {
pass.check_nested_var_id(self.ctx, self.hir, id);
}
self.walk_nested_var(id)
}

fn visit_contract(
&mut self,
contract: &'hir hir::Contract<'hir>,
Expand All @@ -160,6 +232,16 @@ where
self.walk_function(func)
}

fn visit_modifier(
&mut self,
modifier: &'hir hir::Modifier<'hir>,
) -> ControlFlow<Self::BreakValue> {
for pass in self.passes.iter_mut() {
pass.check_modifier(self.ctx, self.hir, modifier);
}
self.walk_modifier(modifier)
}

fn visit_item(&mut self, item: hir::Item<'hir, 'hir>) -> ControlFlow<Self::BreakValue> {
for pass in self.passes.iter_mut() {
pass.check_item(self.ctx, self.hir, item);
Expand All @@ -181,6 +263,16 @@ where
self.walk_expr(expr)
}

fn visit_call_args(
&mut self,
args: &'hir hir::CallArgs<'hir>,
) -> ControlFlow<Self::BreakValue> {
for pass in self.passes.iter_mut() {
pass.check_call_args(self.ctx, self.hir, args);
}
self.walk_call_args(args)
}

fn visit_stmt(&mut self, stmt: &'hir hir::Stmt<'hir>) -> ControlFlow<Self::BreakValue> {
for pass in self.passes.iter_mut() {
pass.check_stmt(self.ctx, self.hir, stmt);
Expand Down
Loading