Rename DotDotPat -> RestPat

This commit is contained in:
Aleksey Kladov 2020-07-31 21:45:29 +02:00
parent 215b9b9ccc
commit 22d295ceaa
14 changed files with 55 additions and 55 deletions

View file

@ -826,7 +826,7 @@ impl ExprCollector<'_> {
Pat::Missing
}
}
ast::Pat::DotDotPat(_) => {
ast::Pat::RestPat(_) => {
// `DotDotPat` requires special handling and should not be mapped
// to a Pat. Here we are using `Pat::Missing` as a fallback for
// when `DotDotPat` is mapped to `Pat`, which can easily happen
@ -853,10 +853,10 @@ impl ExprCollector<'_> {
fn collect_tuple_pat(&mut self, args: AstChildren<ast::Pat>) -> (Vec<PatId>, Option<usize>) {
// Find the location of the `..`, if there is one. Note that we do not
// consider the possiblity of there being multiple `..` here.
let ellipsis = args.clone().position(|p| matches!(p, ast::Pat::DotDotPat(_)));
let ellipsis = args.clone().position(|p| matches!(p, ast::Pat::RestPat(_)));
// We want to skip the `..` pattern here, since we account for it above.
let args = args
.filter(|p| !matches!(p, ast::Pat::DotDotPat(_)))
.filter(|p| !matches!(p, ast::Pat::RestPat(_)))
.map(|p| self.collect_pat(p))
.collect();

View file

@ -577,7 +577,7 @@ fn highlight_element(
_ if element.parent().and_then(ast::RangePat::cast).is_some() => {
HighlightTag::Operator.into()
}
_ if element.parent().and_then(ast::DotDotPat::cast).is_some() => {
_ if element.parent().and_then(ast::RestPat::cast).is_some() => {
HighlightTag::Operator.into()
}
_ if element.parent().and_then(ast::Attr::cast).is_some() => {

View file

@ -192,7 +192,7 @@ fn record_field_pat_list(p: &mut Parser) {
p.bump(T!['{']);
while !p.at(EOF) && !p.at(T!['}']) {
match p.current() {
// A trailing `..` is *not* treated as a DOT_DOT_PAT.
// A trailing `..` is *not* treated as a REST_PAT.
T![.] if p.at(T![..]) => p.bump(T![..]),
T!['{'] => error_block(p, "expected ident"),
@ -267,7 +267,7 @@ fn dot_dot_pat(p: &mut Parser) -> CompletedMarker {
assert!(p.at(T![..]));
let m = p.start();
p.bump(T![..]);
m.complete(p, DOT_DOT_PAT)
m.complete(p, REST_PAT)
}
// test ref_pat

View file

@ -158,7 +158,7 @@ pub enum SyntaxKind {
BOX_PAT,
IDENT_PAT,
WILDCARD_PAT,
DOT_DOT_PAT,
REST_PAT,
PATH_PAT,
RECORD_PAT,
RECORD_PAT_FIELD_LIST,

View file

@ -1130,10 +1130,10 @@ impl BoxPat {
pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct DotDotPat {
pub struct RestPat {
pub(crate) syntax: SyntaxNode,
}
impl DotDotPat {
impl RestPat {
pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) }
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@ -1336,7 +1336,7 @@ pub enum Stmt {
pub enum Pat {
IdentPat(IdentPat),
BoxPat(BoxPat),
DotDotPat(DotDotPat),
RestPat(RestPat),
LiteralPat(LiteralPat),
MacroPat(MacroPat),
OrPat(OrPat),
@ -2577,8 +2577,8 @@ impl AstNode for BoxPat {
}
fn syntax(&self) -> &SyntaxNode { &self.syntax }
}
impl AstNode for DotDotPat {
fn can_cast(kind: SyntaxKind) -> bool { kind == DOT_DOT_PAT }
impl AstNode for RestPat {
fn can_cast(kind: SyntaxKind) -> bool { kind == REST_PAT }
fn cast(syntax: SyntaxNode) -> Option<Self> {
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
@ -3141,8 +3141,8 @@ impl From<IdentPat> for Pat {
impl From<BoxPat> for Pat {
fn from(node: BoxPat) -> Pat { Pat::BoxPat(node) }
}
impl From<DotDotPat> for Pat {
fn from(node: DotDotPat) -> Pat { Pat::DotDotPat(node) }
impl From<RestPat> for Pat {
fn from(node: RestPat) -> Pat { Pat::RestPat(node) }
}
impl From<LiteralPat> for Pat {
fn from(node: LiteralPat) -> Pat { Pat::LiteralPat(node) }
@ -3183,7 +3183,7 @@ impl From<TupleStructPat> for Pat {
impl AstNode for Pat {
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
IDENT_PAT | BOX_PAT | DOT_DOT_PAT | LITERAL_PAT | MACRO_PAT | OR_PAT | PAREN_PAT
IDENT_PAT | BOX_PAT | REST_PAT | LITERAL_PAT | MACRO_PAT | OR_PAT | PAREN_PAT
| PATH_PAT | WILDCARD_PAT | RANGE_PAT | RECORD_PAT | REF_PAT | SLICE_PAT
| TUPLE_PAT | TUPLE_STRUCT_PAT => true,
_ => false,
@ -3193,7 +3193,7 @@ impl AstNode for Pat {
let res = match syntax.kind() {
IDENT_PAT => Pat::IdentPat(IdentPat { syntax }),
BOX_PAT => Pat::BoxPat(BoxPat { syntax }),
DOT_DOT_PAT => Pat::DotDotPat(DotDotPat { syntax }),
REST_PAT => Pat::RestPat(RestPat { syntax }),
LITERAL_PAT => Pat::LiteralPat(LiteralPat { syntax }),
MACRO_PAT => Pat::MacroPat(MacroPat { syntax }),
OR_PAT => Pat::OrPat(OrPat { syntax }),
@ -3214,7 +3214,7 @@ impl AstNode for Pat {
match self {
Pat::IdentPat(it) => &it.syntax,
Pat::BoxPat(it) => &it.syntax,
Pat::DotDotPat(it) => &it.syntax,
Pat::RestPat(it) => &it.syntax,
Pat::LiteralPat(it) => &it.syntax,
Pat::MacroPat(it) => &it.syntax,
Pat::OrPat(it) => &it.syntax,
@ -3990,7 +3990,7 @@ impl std::fmt::Display for BoxPat {
std::fmt::Display::fmt(self.syntax(), f)
}
}
impl std::fmt::Display for DotDotPat {
impl std::fmt::Display for RestPat {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.syntax(), f)
}

View file

@ -293,15 +293,15 @@ impl ast::SlicePat {
let mut args = self.args().peekable();
let prefix = args
.peeking_take_while(|p| match p {
ast::Pat::DotDotPat(_) => false,
ast::Pat::RestPat(_) => false,
ast::Pat::IdentPat(bp) => match bp.pat() {
Some(ast::Pat::DotDotPat(_)) => false,
Some(ast::Pat::RestPat(_)) => false,
_ => true,
},
ast::Pat::RefPat(rp) => match rp.pat() {
Some(ast::Pat::DotDotPat(_)) => false,
Some(ast::Pat::RestPat(_)) => false,
Some(ast::Pat::IdentPat(bp)) => match bp.pat() {
Some(ast::Pat::DotDotPat(_)) => false,
Some(ast::Pat::RestPat(_)) => false,
_ => true,
},
_ => true,

View file

@ -81,7 +81,7 @@ SOURCE_FILE@0..103
NAME_REF@87..90
IDENT@87..90 "Bar"
L_PAREN@90..91 "("
DOT_DOT_PAT@91..93
REST_PAT@91..93
DOT2@91..93 ".."
R_PAREN@93..94 ")"
WHITESPACE@94..95 " "

View file

@ -26,7 +26,7 @@ SOURCE_FILE@0..39
IDENT@24..25 "b"
COMMA@25..26 ","
WHITESPACE@26..27 " "
DOT_DOT_PAT@27..29
REST_PAT@27..29
DOT2@27..29 ".."
R_BRACK@29..30 "]"
WHITESPACE@30..31 " "

View file

@ -83,7 +83,7 @@ SOURCE_FILE@0..97
UNDERSCORE@78..79 "_"
COMMA@79..80 ","
WHITESPACE@80..81 " "
DOT_DOT_PAT@81..83
REST_PAT@81..83
DOT2@81..83 ".."
WHITESPACE@83..84 " "
COMMA@84..85 ","

View file

@ -26,7 +26,7 @@ SOURCE_FILE@0..94
IDENT@24..25 "b"
COMMA@25..26 ","
WHITESPACE@26..27 " "
DOT_DOT_PAT@27..29
REST_PAT@27..29
DOT2@27..29 ".."
R_PAREN@29..30 ")"
WHITESPACE@30..31 " "
@ -60,7 +60,7 @@ SOURCE_FILE@0..94
WHITESPACE@63..64 " "
TUPLE_PAT@64..68
L_PAREN@64..65 "("
DOT_DOT_PAT@65..67
REST_PAT@65..67
DOT2@65..67 ".."
R_PAREN@67..68 ")"
WHITESPACE@68..69 " "

View file

@ -14,7 +14,7 @@ SOURCE_FILE@0..555
LET_STMT@16..28
LET_KW@16..19 "let"
WHITESPACE@19..20 " "
DOT_DOT_PAT@20..22
REST_PAT@20..22
DOT2@20..22 ".."
WHITESPACE@22..23 " "
EQ@23..24 "="
@ -40,7 +40,7 @@ SOURCE_FILE@0..555
IDENT@66..67 "a"
COMMA@67..68 ","
WHITESPACE@68..69 " "
DOT_DOT_PAT@69..71
REST_PAT@69..71
DOT2@69..71 ".."
R_PAREN@71..72 ")"
WHITESPACE@72..73 " "
@ -61,7 +61,7 @@ SOURCE_FILE@0..555
IDENT@88..89 "a"
COMMA@89..90 ","
WHITESPACE@90..91 " "
DOT_DOT_PAT@91..93
REST_PAT@91..93
DOT2@91..93 ".."
COMMA@93..94 ","
R_PAREN@94..95 ")"
@ -87,7 +87,7 @@ SOURCE_FILE@0..555
IDENT@116..117 "a"
COMMA@117..118 ","
WHITESPACE@118..119 " "
DOT_DOT_PAT@119..121
REST_PAT@119..121
DOT2@119..121 ".."
R_PAREN@121..122 ")"
WHITESPACE@122..123 " "
@ -112,7 +112,7 @@ SOURCE_FILE@0..555
IDENT@143..144 "a"
COMMA@144..145 ","
WHITESPACE@145..146 " "
DOT_DOT_PAT@146..148
REST_PAT@146..148
DOT2@146..148 ".."
COMMA@148..149 ","
R_PAREN@149..150 ")"
@ -129,11 +129,11 @@ SOURCE_FILE@0..555
WHITESPACE@164..165 " "
TUPLE_PAT@165..173
L_PAREN@165..166 "("
DOT_DOT_PAT@166..168
REST_PAT@166..168
DOT2@166..168 ".."
COMMA@168..169 ","
WHITESPACE@169..170 " "
DOT_DOT_PAT@170..172
REST_PAT@170..172
DOT2@170..172 ".."
R_PAREN@172..173 ")"
WHITESPACE@173..174 " "
@ -153,11 +153,11 @@ SOURCE_FILE@0..555
NAME_REF@188..193
IDENT@188..193 "Tuple"
L_PAREN@193..194 "("
DOT_DOT_PAT@194..196
REST_PAT@194..196
DOT2@194..196 ".."
COMMA@196..197 ","
WHITESPACE@197..198 " "
DOT_DOT_PAT@198..200
REST_PAT@198..200
DOT2@198..200 ".."
R_PAREN@200..201 ")"
WHITESPACE@201..202 " "
@ -173,7 +173,7 @@ SOURCE_FILE@0..555
WHITESPACE@215..216 " "
TUPLE_PAT@216..227
L_PAREN@216..217 "("
DOT_DOT_PAT@217..219
REST_PAT@217..219
DOT2@217..219 ".."
COMMA@219..220 ","
WHITESPACE@220..221 " "
@ -182,7 +182,7 @@ SOURCE_FILE@0..555
IDENT@221..222 "a"
COMMA@222..223 ","
WHITESPACE@223..224 " "
DOT_DOT_PAT@224..226
REST_PAT@224..226
DOT2@224..226 ".."
R_PAREN@226..227 ")"
WHITESPACE@227..228 " "
@ -202,7 +202,7 @@ SOURCE_FILE@0..555
NAME_REF@242..247
IDENT@242..247 "Tuple"
L_PAREN@247..248 "("
DOT_DOT_PAT@248..250
REST_PAT@248..250
DOT2@248..250 ".."
COMMA@250..251 ","
WHITESPACE@251..252 " "
@ -211,7 +211,7 @@ SOURCE_FILE@0..555
IDENT@252..253 "a"
COMMA@253..254 ","
WHITESPACE@254..255 " "
DOT_DOT_PAT@255..257
REST_PAT@255..257
DOT2@255..257 ".."
R_PAREN@257..258 ")"
WHITESPACE@258..259 " "
@ -233,7 +233,7 @@ SOURCE_FILE@0..555
WHITESPACE@300..301 " "
SLICE_PAT@301..305
L_BRACK@301..302 "["
DOT_DOT_PAT@302..304
REST_PAT@302..304
DOT2@302..304 ".."
R_BRACK@304..305 "]"
WHITESPACE@305..306 " "
@ -254,7 +254,7 @@ SOURCE_FILE@0..555
IDENT@321..325 "head"
COMMA@325..326 ","
WHITESPACE@326..327 " "
DOT_DOT_PAT@327..329
REST_PAT@327..329
DOT2@327..329 ".."
R_BRACK@329..330 "]"
WHITESPACE@330..331 " "
@ -281,7 +281,7 @@ SOURCE_FILE@0..555
WHITESPACE@356..357 " "
AT@357..358 "@"
WHITESPACE@358..359 " "
DOT_DOT_PAT@359..361
REST_PAT@359..361
DOT2@359..361 ".."
R_BRACK@361..362 "]"
WHITESPACE@362..363 " "
@ -302,7 +302,7 @@ SOURCE_FILE@0..555
IDENT@378..382 "head"
COMMA@382..383 ","
WHITESPACE@383..384 " "
DOT_DOT_PAT@384..386
REST_PAT@384..386
DOT2@384..386 ".."
COMMA@386..387 ","
WHITESPACE@387..388 " "
@ -334,7 +334,7 @@ SOURCE_FILE@0..555
WHITESPACE@418..419 " "
AT@419..420 "@"
WHITESPACE@420..421 " "
DOT_DOT_PAT@421..423
REST_PAT@421..423
DOT2@421..423 ".."
COMMA@423..424 ","
WHITESPACE@424..425 " "
@ -360,11 +360,11 @@ SOURCE_FILE@0..555
IDENT@446..450 "head"
COMMA@450..451 ","
WHITESPACE@451..452 " "
DOT_DOT_PAT@452..454
REST_PAT@452..454
DOT2@452..454 ".."
COMMA@454..455 ","
WHITESPACE@455..456 " "
DOT_DOT_PAT@456..458
REST_PAT@456..458
DOT2@456..458 ".."
COMMA@458..459 ","
WHITESPACE@459..460 " "
@ -390,7 +390,7 @@ SOURCE_FILE@0..555
IDENT@481..485 "head"
COMMA@485..486 ","
WHITESPACE@486..487 " "
DOT_DOT_PAT@487..489
REST_PAT@487..489
DOT2@487..489 ".."
COMMA@489..490 ","
WHITESPACE@490..491 " "
@ -405,7 +405,7 @@ SOURCE_FILE@0..555
WHITESPACE@500..501 " "
AT@501..502 "@"
WHITESPACE@502..503 " "
DOT_DOT_PAT@503..505
REST_PAT@503..505
DOT2@503..505 ".."
R_BRACK@505..506 "]"
WHITESPACE@506..507 " "
@ -426,7 +426,7 @@ SOURCE_FILE@0..555
IDENT@522..526 "head"
COMMA@526..527 ","
WHITESPACE@527..528 " "
DOT_DOT_PAT@528..530
REST_PAT@528..530
DOT2@528..530 ".."
COMMA@530..531 ","
WHITESPACE@531..532 " "
@ -435,7 +435,7 @@ SOURCE_FILE@0..555
IDENT@532..535 "mid"
COMMA@535..536 ","
WHITESPACE@536..537 " "
DOT_DOT_PAT@537..539
REST_PAT@537..539
DOT2@537..539 ".."
COMMA@539..540 ","
WHITESPACE@540..541 " "

View file

@ -1634,7 +1634,7 @@ SOURCE_FILE@0..3813
PARAM@2952..2962
TUPLE_PAT@2952..2956
L_PAREN@2952..2953 "("
DOT_DOT_PAT@2953..2955
REST_PAT@2953..2955
DOT2@2953..2955 ".."
R_PAREN@2955..2956 ")"
COLON@2956..2957 ":"

View file

@ -128,7 +128,7 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc {
"BOX_PAT",
"IDENT_PAT",
"WILDCARD_PAT",
"DOT_DOT_PAT",
"REST_PAT",
"PATH_PAT",
"RECORD_PAT",
"RECORD_PAT_FIELD_LIST",

View file

@ -498,7 +498,7 @@ TypeBound =
Pat =
IdentPat
| BoxPat
| DotDotPat
| RestPat
| LiteralPat
| MacroPat
| OrPat
@ -560,7 +560,7 @@ OrPat =
BoxPat =
'box' Pat
DotDotPat =
RestPat =
'..'
MacroPat =