Skip to content
This repository was archived by the owner on May 11, 2023. It is now read-only.

Commit 767772f

Browse files
committed
Revert into_node and node() changes
1 parent 5ffa8a1 commit 767772f

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

compiler/ast/src/ast_gen.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,24 @@ impl<T> Located<T> {
6363
}
6464
}
6565

66+
impl<T, U> std::ops::Deref for Located<T, U> {
67+
type Target = T;
68+
69+
fn deref(&self) -> &Self::Target {
70+
&self.node
71+
}
72+
73+
pub const fn start(&self) -> Location {
74+
self.location
75+
}
76+
77+
/// Returns the node's [`end_location`](Located::end_location) or [`location`](Located::start) if
78+
/// [`end_location`](Located::end_location) is `None`.
79+
pub fn end(&self) -> Location {
80+
self.end_location.unwrap_or(self.location)
81+
}
82+
}
83+
6684
impl<T, U> std::ops::Deref for Located<T, U> {
6785
type Target = T;
6886

compiler/parser/python.lalrpop

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ ClosedPattern: ast::Pattern = {
519519

520520
SequencePattern: ast::PatternKind = {
521521
// A single-item tuple is a special case: it's a group pattern, _not_ a sequence pattern.
522-
<location:@L> "(" <pattern:Pattern> ")" <end_location:@R> => pattern.into_node(),
522+
<location:@L> "(" <pattern:Pattern> ")" <end_location:@R> => pattern.node,
523523
<location:@L> "(" ")" <end_location:@R> => ast::PatternKind::MatchSequence {
524524
patterns: vec![],
525525
},
@@ -1554,7 +1554,7 @@ Atom<Goal>: ast::Expr = {
15541554
},
15551555
<location:@L> "(" <left:(<OneOrMore<Test<"all">>> ",")?> <mid:NamedOrStarExpr> <right:("," <TestOrStarNamedExpr>)*> <trailing_comma:","?> ")" <end_location:@R> =>? {
15561556
if left.is_none() && right.is_empty() && trailing_comma.is_none() {
1557-
if matches!(mid.node(), ast::ExprKind::Starred { .. }) {
1557+
if matches!(mid.node, ast::ExprKind::Starred { .. }) {
15581558
Err(LexicalError{
15591559
error: LexicalErrorType::OtherError("cannot use starred expression here".to_string()),
15601560
location: mid.start(),

compiler/parser/src/function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ pub(crate) fn parse_args(func_args: Vec<FunctionArgument>) -> Result<ArgumentLis
144144

145145
// Check if an expression is a starred expression.
146146
fn is_starred(exp: &ast::Expr) -> bool {
147-
matches!(exp.node(), ast::ExprKind::Starred { .. })
147+
matches!(exp.node, ast::ExprKind::Starred { .. })
148148
}
149149

150150
#[cfg(test)]

0 commit comments

Comments
 (0)