diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-08-25 10:47:44 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-08-25 10:47:44 +0100 |
commit | 866b41ddd86cbe9c3e8d9cb2896477bab060a044 (patch) | |
tree | 2108601228076d62e833b732de52e182b8be4a0b /crates/ra_syntax/src/ast/generated.rs | |
parent | fdece911fe8e2f3c22760ea22038a6d00cb70dfa (diff) | |
parent | c93903e9c7f64be2edcae0dfe62d8390514658b1 (diff) |
Merge #1733
1733: Parse arbitrarily complex `box` patterns. r=matklad a=ecstatic-morse
This fully resolves the pattern part of #1412 by enabling the parsing of complex `box` patterns such as:
```rust
let box Struct { box i, j: box Inner(box &x) } = todo!();
```
This introduces a new `ast::BoxPat` (in the mold of `ast::RefPat`) that gets translated to `hir::Pat::Missing`.
Co-authored-by: Dylan MacKenzie <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/ast/generated.rs')
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 07cc3e0db..90480b6ca 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -307,6 +307,33 @@ impl BlockExpr { | |||
307 | } | 307 | } |
308 | } | 308 | } |
309 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 309 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
310 | pub struct BoxPat { | ||
311 | pub(crate) syntax: SyntaxNode, | ||
312 | } | ||
313 | impl AstNode for BoxPat { | ||
314 | fn can_cast(kind: SyntaxKind) -> bool { | ||
315 | match kind { | ||
316 | BOX_PAT => true, | ||
317 | _ => false, | ||
318 | } | ||
319 | } | ||
320 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
321 | if Self::can_cast(syntax.kind()) { | ||
322 | Some(Self { syntax }) | ||
323 | } else { | ||
324 | None | ||
325 | } | ||
326 | } | ||
327 | fn syntax(&self) -> &SyntaxNode { | ||
328 | &self.syntax | ||
329 | } | ||
330 | } | ||
331 | impl BoxPat { | ||
332 | pub fn pat(&self) -> Option<Pat> { | ||
333 | AstChildren::new(&self.syntax).next() | ||
334 | } | ||
335 | } | ||
336 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
310 | pub struct BreakExpr { | 337 | pub struct BreakExpr { |
311 | pub(crate) syntax: SyntaxNode, | 338 | pub(crate) syntax: SyntaxNode, |
312 | } | 339 | } |
@@ -2063,6 +2090,7 @@ impl ParenType { | |||
2063 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2090 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2064 | pub enum Pat { | 2091 | pub enum Pat { |
2065 | RefPat(RefPat), | 2092 | RefPat(RefPat), |
2093 | BoxPat(BoxPat), | ||
2066 | BindPat(BindPat), | 2094 | BindPat(BindPat), |
2067 | PlaceholderPat(PlaceholderPat), | 2095 | PlaceholderPat(PlaceholderPat), |
2068 | PathPat(PathPat), | 2096 | PathPat(PathPat), |
@@ -2078,6 +2106,11 @@ impl From<RefPat> for Pat { | |||
2078 | Pat::RefPat(node) | 2106 | Pat::RefPat(node) |
2079 | } | 2107 | } |
2080 | } | 2108 | } |
2109 | impl From<BoxPat> for Pat { | ||
2110 | fn from(node: BoxPat) -> Pat { | ||
2111 | Pat::BoxPat(node) | ||
2112 | } | ||
2113 | } | ||
2081 | impl From<BindPat> for Pat { | 2114 | impl From<BindPat> for Pat { |
2082 | fn from(node: BindPat) -> Pat { | 2115 | fn from(node: BindPat) -> Pat { |
2083 | Pat::BindPat(node) | 2116 | Pat::BindPat(node) |
@@ -2126,14 +2159,15 @@ impl From<LiteralPat> for Pat { | |||
2126 | impl AstNode for Pat { | 2159 | impl AstNode for Pat { |
2127 | fn can_cast(kind: SyntaxKind) -> bool { | 2160 | fn can_cast(kind: SyntaxKind) -> bool { |
2128 | match kind { | 2161 | match kind { |
2129 | REF_PAT | BIND_PAT | PLACEHOLDER_PAT | PATH_PAT | RECORD_PAT | TUPLE_STRUCT_PAT | 2162 | REF_PAT | BOX_PAT | BIND_PAT | PLACEHOLDER_PAT | PATH_PAT | RECORD_PAT |
2130 | | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => true, | 2163 | | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => true, |
2131 | _ => false, | 2164 | _ => false, |
2132 | } | 2165 | } |
2133 | } | 2166 | } |
2134 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2167 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2135 | let res = match syntax.kind() { | 2168 | let res = match syntax.kind() { |
2136 | REF_PAT => Pat::RefPat(RefPat { syntax }), | 2169 | REF_PAT => Pat::RefPat(RefPat { syntax }), |
2170 | BOX_PAT => Pat::BoxPat(BoxPat { syntax }), | ||
2137 | BIND_PAT => Pat::BindPat(BindPat { syntax }), | 2171 | BIND_PAT => Pat::BindPat(BindPat { syntax }), |
2138 | PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }), | 2172 | PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }), |
2139 | PATH_PAT => Pat::PathPat(PathPat { syntax }), | 2173 | PATH_PAT => Pat::PathPat(PathPat { syntax }), |
@@ -2150,6 +2184,7 @@ impl AstNode for Pat { | |||
2150 | fn syntax(&self) -> &SyntaxNode { | 2184 | fn syntax(&self) -> &SyntaxNode { |
2151 | match self { | 2185 | match self { |
2152 | Pat::RefPat(it) => &it.syntax, | 2186 | Pat::RefPat(it) => &it.syntax, |
2187 | Pat::BoxPat(it) => &it.syntax, | ||
2153 | Pat::BindPat(it) => &it.syntax, | 2188 | Pat::BindPat(it) => &it.syntax, |
2154 | Pat::PlaceholderPat(it) => &it.syntax, | 2189 | Pat::PlaceholderPat(it) => &it.syntax, |
2155 | Pat::PathPat(it) => &it.syntax, | 2190 | Pat::PathPat(it) => &it.syntax, |