Skip to content

Commit 1efbebe

Browse files
committed
chore: Instantiate pre_linter context with Default
As a consequence, `Position` now implements `Default`, which results to `Position::start` (1,1).
1 parent 2ac48f3 commit 1efbebe

3 files changed

Lines changed: 8 additions & 12 deletions

File tree

rusty_common/src/position.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,9 @@ impl Position {
3232
self.col
3333
}
3434
}
35+
36+
impl Default for Position {
37+
fn default() -> Self {
38+
Self::start()
39+
}
40+
}

rusty_linter/src/pre_linter/main.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rusty_parser::*;
99
// TYPE ... END TYPE -> stored in user_defined_types depends on CONST for resolving string length (AS STRING * some_const)
1010
// FUNCTION/SUB -> depends on resolver for resolving bare names and on user_defined_types to ensure types exist
1111

12+
#[derive(Default)]
1213
struct MainContext {
1314
resolver: TypeResolverImpl,
1415
user_defined_types: UserDefinedTypes,
@@ -19,14 +20,7 @@ struct MainContext {
1920
}
2021

2122
pub fn pre_lint_program(program: &Program) -> Result<PreLinterResult, LintErrorPos> {
22-
let mut ctx = MainContext {
23-
resolver: TypeResolverImpl::new(),
24-
user_defined_types: Default::default(),
25-
functions: SubprogramContext::new(),
26-
subs: SubprogramContext::new(),
27-
global_constants: Default::default(),
28-
declaration_pos: Position::start(),
29-
};
23+
let mut ctx = MainContext::default();
3024
<MainContext as Visitor<Program>>::visit(&mut ctx, program)?;
3125
ctx.post_visit_functions()?;
3226
ctx.post_visit_subs()?;

rusty_linter/src/pre_linter/sub_program_context.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,6 @@ impl Implementations {
109109
}
110110

111111
impl SubprogramContext {
112-
pub fn new() -> Self {
113-
Self::default()
114-
}
115-
116112
pub fn add_declaration(
117113
&mut self,
118114
bare_name: BareName,

0 commit comments

Comments
 (0)