aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/generated.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-09-15 08:10:16 +0100
committerGitHub <[email protected]>2019-09-15 08:10:16 +0100
commit2d79a1ad83cc39075c7c9e3230973013c8c58b17 (patch)
treee394007f715f8586c737db8f20f2d8f16f8913af /crates/ra_syntax/src/ast/generated.rs
parentbcdba777bdc43762cff73ac3ded4ae737a503692 (diff)
parent0956323bb7b728da6bff4ad7241a542f4bb4e8e6 (diff)
Merge #1848
1848: Parse `..` as a full pattern r=matklad a=ecstatic-morse Resolves #1479. This PR implements [RFC 2707](https://github.com/rust-lang/rfcs/pull/2707) in the parser. It introduces a new `DotDotPat` AST node modeled on `PlaceholderPat` and changes the parsing of tuple and slice patterns to conform to the RFC. Notably, this PR does *not* change the resulting AST when `..` appears in a struct pattern (e.g. `Struct { a, b: c, .. }`). I *think* this is the behavior mandated by RFC 2707, but someone should confirm this. 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.rs37
1 files changed, 35 insertions, 2 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
index a8a231ef3..591ac8ca3 100644
--- a/crates/ra_syntax/src/ast/generated.rs
+++ b/crates/ra_syntax/src/ast/generated.rs
@@ -532,6 +532,29 @@ impl AstNode for ContinueExpr {
532} 532}
533impl ContinueExpr {} 533impl ContinueExpr {}
534#[derive(Debug, Clone, PartialEq, Eq, Hash)] 534#[derive(Debug, Clone, PartialEq, Eq, Hash)]
535pub struct DotDotPat {
536 pub(crate) syntax: SyntaxNode,
537}
538impl AstNode for DotDotPat {
539 fn can_cast(kind: SyntaxKind) -> bool {
540 match kind {
541 DOT_DOT_PAT => true,
542 _ => false,
543 }
544 }
545 fn cast(syntax: SyntaxNode) -> Option<Self> {
546 if Self::can_cast(syntax.kind()) {
547 Some(Self { syntax })
548 } else {
549 None
550 }
551 }
552 fn syntax(&self) -> &SyntaxNode {
553 &self.syntax
554 }
555}
556impl DotDotPat {}
557#[derive(Debug, Clone, PartialEq, Eq, Hash)]
535pub struct DynTraitType { 558pub struct DynTraitType {
536 pub(crate) syntax: SyntaxNode, 559 pub(crate) syntax: SyntaxNode,
537} 560}
@@ -2128,6 +2151,7 @@ pub enum Pat {
2128 BoxPat(BoxPat), 2151 BoxPat(BoxPat),
2129 BindPat(BindPat), 2152 BindPat(BindPat),
2130 PlaceholderPat(PlaceholderPat), 2153 PlaceholderPat(PlaceholderPat),
2154 DotDotPat(DotDotPat),
2131 PathPat(PathPat), 2155 PathPat(PathPat),
2132 RecordPat(RecordPat), 2156 RecordPat(RecordPat),
2133 TupleStructPat(TupleStructPat), 2157 TupleStructPat(TupleStructPat),
@@ -2156,6 +2180,11 @@ impl From<PlaceholderPat> for Pat {
2156 Pat::PlaceholderPat(node) 2180 Pat::PlaceholderPat(node)
2157 } 2181 }
2158} 2182}
2183impl From<DotDotPat> for Pat {
2184 fn from(node: DotDotPat) -> Pat {
2185 Pat::DotDotPat(node)
2186 }
2187}
2159impl From<PathPat> for Pat { 2188impl From<PathPat> for Pat {
2160 fn from(node: PathPat) -> Pat { 2189 fn from(node: PathPat) -> Pat {
2161 Pat::PathPat(node) 2190 Pat::PathPat(node)
@@ -2194,8 +2223,10 @@ impl From<LiteralPat> for Pat {
2194impl AstNode for Pat { 2223impl AstNode for Pat {
2195 fn can_cast(kind: SyntaxKind) -> bool { 2224 fn can_cast(kind: SyntaxKind) -> bool {
2196 match kind { 2225 match kind {
2197 REF_PAT | BOX_PAT | BIND_PAT | PLACEHOLDER_PAT | PATH_PAT | RECORD_PAT 2226 REF_PAT | BOX_PAT | BIND_PAT | PLACEHOLDER_PAT | DOT_DOT_PAT | PATH_PAT
2198 | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => true, 2227 | RECORD_PAT | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => {
2228 true
2229 }
2199 _ => false, 2230 _ => false,
2200 } 2231 }
2201 } 2232 }
@@ -2205,6 +2236,7 @@ impl AstNode for Pat {
2205 BOX_PAT => Pat::BoxPat(BoxPat { syntax }), 2236 BOX_PAT => Pat::BoxPat(BoxPat { syntax }),
2206 BIND_PAT => Pat::BindPat(BindPat { syntax }), 2237 BIND_PAT => Pat::BindPat(BindPat { syntax }),
2207 PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }), 2238 PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }),
2239 DOT_DOT_PAT => Pat::DotDotPat(DotDotPat { syntax }),
2208 PATH_PAT => Pat::PathPat(PathPat { syntax }), 2240 PATH_PAT => Pat::PathPat(PathPat { syntax }),
2209 RECORD_PAT => Pat::RecordPat(RecordPat { syntax }), 2241 RECORD_PAT => Pat::RecordPat(RecordPat { syntax }),
2210 TUPLE_STRUCT_PAT => Pat::TupleStructPat(TupleStructPat { syntax }), 2242 TUPLE_STRUCT_PAT => Pat::TupleStructPat(TupleStructPat { syntax }),
@@ -2222,6 +2254,7 @@ impl AstNode for Pat {
2222 Pat::BoxPat(it) => &it.syntax, 2254 Pat::BoxPat(it) => &it.syntax,
2223 Pat::BindPat(it) => &it.syntax, 2255 Pat::BindPat(it) => &it.syntax,
2224 Pat::PlaceholderPat(it) => &it.syntax, 2256 Pat::PlaceholderPat(it) => &it.syntax,
2257 Pat::DotDotPat(it) => &it.syntax,
2225 Pat::PathPat(it) => &it.syntax, 2258 Pat::PathPat(it) => &it.syntax,
2226 Pat::RecordPat(it) => &it.syntax, 2259 Pat::RecordPat(it) => &it.syntax,
2227 Pat::TupleStructPat(it) => &it.syntax, 2260 Pat::TupleStructPat(it) => &it.syntax,