Skip to content

Commit 0798716

Browse files
committed
ast: Remove mutability from VarDeclaration
1 parent 5917c1e commit 0798716

File tree

5 files changed

+9
-29
lines changed

5 files changed

+9
-29
lines changed

ast/src/lib.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ pub enum Node {
189189
else_block: Option<Box<Ast>>,
190190
},
191191
VarDeclaration {
192-
mutable: bool,
193192
to_declare: Symbol,
194193
value: Box<Ast>,
195194
},
@@ -409,19 +408,14 @@ pub trait Visitor {
409408
fn visit_var_declaration(
410409
&mut self,
411410
location: SpanTuple,
412-
mutable: bool,
413411
to_declare: Symbol,
414412
value: Box<Ast>,
415413
) -> Result<Ast, Error> {
416414
let value = self.boxed(value)?;
417415

418416
Ok(Ast {
419417
location,
420-
node: Node::VarDeclaration {
421-
mutable,
422-
to_declare,
423-
value,
424-
},
418+
node: Node::VarDeclaration { to_declare, value },
425419
})
426420
}
427421

@@ -503,11 +497,9 @@ pub trait Visitor {
503497
if_block,
504498
else_block,
505499
} => self.visit_if_else(ast.location, if_condition, if_block, else_block),
506-
Node::VarDeclaration {
507-
mutable,
508-
to_declare,
509-
value,
510-
} => self.visit_var_declaration(ast.location, mutable, to_declare, value),
500+
Node::VarDeclaration { to_declare, value } => {
501+
self.visit_var_declaration(ast.location, to_declare, value)
502+
}
511503
Node::VarAssign { to_assign, value } => {
512504
self.visit_var_assign(ast.location, to_assign, value)
513505
}

flatten/src/lib.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,6 @@ impl<'ast> Ctx<'ast> {
768768
fn visit_var_declaration(
769769
self,
770770
ast: AstInfo<'ast>,
771-
_mutable: bool,
772771
_to_declare: &Symbol,
773772
value: &'ast Ast,
774773
) -> (Ctx<'ast>, RefIdx) {
@@ -900,11 +899,9 @@ impl<'ast> Ctx<'ast> {
900899
if_block,
901900
else_block,
902901
} => self.visit_if_else(node, if_condition, if_block, else_block),
903-
AstNode::VarDeclaration {
904-
mutable,
905-
to_declare,
906-
value,
907-
} => self.visit_var_declaration(node, *mutable, to_declare, value),
902+
AstNode::VarDeclaration { to_declare, value } => {
903+
self.visit_var_declaration(node, to_declare, value)
904+
}
908905
AstNode::VarAssign { to_assign, value } => {
909906
self.visit_var_assign(node, to_assign, value)
910907
}
@@ -1013,7 +1010,7 @@ mod tests {
10131010
fn where_expr() {
10141011
let ast = ast! {
10151012
where x = 15;
1016-
where mut y = x;
1013+
where y = x;
10171014
};
10181015

10191016
let fir = ast.flatten();

loop_desugar/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ fn var_declare<S: Into<Symbol>>(loc: &SpanTuple, to_declare: S, value: Box<Ast>)
8686
Ast {
8787
location: loc.clone(),
8888
node: Node::VarDeclaration {
89-
mutable: false,
9089
to_declare: to_declare.into(),
9190
value,
9291
},

xparser/src/constructs.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ fn method_or_field(
229229
///
230230
/// | 'type' type_id '(' named_args
231231
/// | 'incl' spaced_identifier [ 'as' next IDENTIFIER ]
232-
/// | 'mut' spaced_identifier '=' expr (* mutable variable assigment *)
233232
/// | '@' spaced_identifier '(' args
234233
///
235234
/// | 'extern' 'func' function_declaration ';'
@@ -617,19 +616,16 @@ fn unit_type_decl(input: ParseInput, start_loc: Location) -> ParseResult<ParseIn
617616
))
618617
}
619618

620-
/// mut? [`spaced_identifier`] '=' expr
619+
/// [`spaced_identifier`] '=' expr
621620
fn unit_var_decl(input: ParseInput) -> ParseResult<ParseInput, Ast> {
622621
let input = next(input);
623-
let (input, mutable) = opt(tokens::mut_tok)(input)?;
624-
let mutable = mutable.is_some();
625622

626623
let (input, (symbol, (start_loc, _))) = spaced_identifier(input)?;
627624
let (input, _) = tokens::equal(input)?;
628625
let (input, value) = expr(input)?;
629626
let (input, end_loc) = position(input)?;
630627

631628
let assignment = Node::VarDeclaration {
632-
mutable,
633629
to_declare: Symbol::from(symbol),
634630
value: Box::new(value),
635631
};

xparser/src/tokens.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,6 @@ pub fn in_tok(input: ParseInput) -> ParseResult<ParseInput, ParseInput> {
148148
specific_token(input, "in")
149149
}
150150

151-
pub fn mut_tok(input: ParseInput) -> ParseResult<ParseInput, ParseInput> {
152-
specific_token(input, "mut")
153-
}
154-
155151
pub fn if_tok(input: ParseInput) -> ParseResult<ParseInput, ParseInput> {
156152
specific_token(input, "if")
157153
}

0 commit comments

Comments
 (0)