Skip to content

Commit 2d4c4c9

Browse files
committed
Address comments in lowering + parsing.
1 parent efdbb87 commit 2d4c4c9

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/librustc/hir/lowering.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4186,7 +4186,7 @@ impl<'a> LoweringContext<'a> {
41864186
ParamMode::Optional,
41874187
ImplTraitContext::disallowed(),
41884188
);
4189-
let (pats, ddpos) = self.lower_pat_tuple(&*pats, "tuple struct");
4189+
let (pats, ddpos) = self.lower_pat_tuple(pats, "tuple struct");
41904190
hir::PatKind::TupleStruct(qpath, pats, ddpos)
41914191
}
41924192
PatKind::Path(ref qself, ref path) => {
@@ -4225,7 +4225,7 @@ impl<'a> LoweringContext<'a> {
42254225
hir::PatKind::Struct(qpath, fs, etc)
42264226
}
42274227
PatKind::Tuple(ref pats) => {
4228-
let (pats, ddpos) = self.lower_pat_tuple(&*pats, "tuple");
4228+
let (pats, ddpos) = self.lower_pat_tuple(pats, "tuple");
42294229
hir::PatKind::Tuple(pats, ddpos)
42304230
}
42314231
PatKind::Box(ref inner) => hir::PatKind::Box(self.lower_pat(inner)),
@@ -4246,7 +4246,7 @@ impl<'a> LoweringContext<'a> {
42464246
PatKind::Mac(_) => panic!("Shouldn't exist here"),
42474247
};
42484248

4249-
self.pat_bound(p, node)
4249+
self.pat_with_node_id_of(p, node)
42504250
}
42514251

42524252
fn lower_pat_tuple(
@@ -4292,14 +4292,14 @@ impl<'a> LoweringContext<'a> {
42924292
match pat.node {
42934293
PatKind::Rest => {
42944294
prev_rest_span = Some(pat.span);
4295-
slice = Some(self.pat_bound_wild(pat));
4295+
slice = Some(self.pat_wild_with_node_id_of(pat));
42964296
break;
42974297
},
42984298
PatKind::Ident(ref bm, ident, Some(ref sub)) if sub.is_rest() => {
42994299
prev_rest_span = Some(sub.span);
4300-
let lower_sub = |this: &mut Self| Some(this.pat_bound_wild(sub));
4300+
let lower_sub = |this: &mut Self| Some(this.pat_wild_with_node_id_of(sub));
43014301
let node = self.lower_pat_ident(pat, bm, ident, lower_sub);
4302-
slice = Some(self.pat_bound(pat, node));
4302+
slice = Some(self.pat_with_node_id_of(pat, node));
43034303
break;
43044304
},
43054305
_ => {}
@@ -4315,7 +4315,7 @@ impl<'a> LoweringContext<'a> {
43154315
PatKind::Rest => Some(pat.span),
43164316
PatKind::Ident(.., Some(ref sub)) if sub.is_rest() => {
43174317
// The `HirValidator` is merciless; add a `_` pattern to avoid ICEs.
4318-
after.push(self.pat_bound_wild(pat));
4318+
after.push(self.pat_wild_with_node_id_of(pat));
43194319
Some(sub.span)
43204320
},
43214321
_ => None,
@@ -4363,12 +4363,12 @@ impl<'a> LoweringContext<'a> {
43634363
}
43644364
}
43654365

4366-
fn pat_bound_wild(&mut self, p: &Pat) -> P<hir::Pat> {
4367-
self.pat_bound(p, hir::PatKind::Wild)
4366+
fn pat_wild_with_node_id_of(&mut self, p: &Pat) -> P<hir::Pat> {
4367+
self.pat_with_node_id_of(p, hir::PatKind::Wild)
43684368
}
43694369

43704370
/// Construct a `Pat` with the `HirId` of `p.id` lowered.
4371-
fn pat_bound(&mut self, p: &Pat, node: hir::PatKind) -> P<hir::Pat> {
4371+
fn pat_with_node_id_of(&mut self, p: &Pat, node: hir::PatKind) -> P<hir::Pat> {
43724372
P(hir::Pat {
43734373
hir_id: self.lower_node_id(p.id),
43744374
node,

src/libsyntax/parse/parser.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3747,8 +3747,9 @@ impl<'a> Parser<'a> {
37473747
})
37483748
}
37493749

3750-
/// Parse a parentesized comma separated sequence of patterns until `delim` is reached.
3751-
fn parse_recover_pat_list(&mut self) -> PResult<'a, ()> {
3750+
/// Parse and throw away a parentesized comma separated
3751+
/// sequence of patterns until `)` is reached.
3752+
fn skip_pat_list(&mut self) -> PResult<'a, ()> {
37523753
while !self.check(&token::CloseDelim(token::Paren)) {
37533754
self.parse_pat(None)?;
37543755
if !self.eat(&token::Comma) {
@@ -3771,7 +3772,7 @@ impl<'a> Parser<'a> {
37713772
// later.
37723773
let comma_span = self.token.span;
37733774
self.bump();
3774-
if let Err(mut err) = self.parse_recover_pat_list() {
3775+
if let Err(mut err) = self.skip_pat_list() {
37753776
// We didn't expect this to work anyway; we just wanted
37763777
// to advance to the end of the comma-sequence so we know
37773778
// the span to suggest parenthesizing
@@ -3876,9 +3877,11 @@ impl<'a> Parser<'a> {
38763877
pat = PatKind::Ref(subpat, mutbl);
38773878
}
38783879
token::OpenDelim(token::Paren) => {
3879-
// Parse `(pat, pat, pat, ...)` as tuple pattern.
3880+
// Parse a tuple or parenthesis pattern.
38803881
let (fields, trailing_comma) = self.parse_paren_comma_seq(|p| p.parse_pat(None))?;
38813882

3883+
// Here, `(pat,)` is a tuple pattern.
3884+
// For backward compatibility, `(..)` is a tuple pattern as well.
38823885
pat = if fields.len() == 1 && !(trailing_comma || fields[0].is_rest()) {
38833886
PatKind::Paren(fields.into_iter().nth(0).unwrap())
38843887
} else {

0 commit comments

Comments
 (0)