Skip to content

Commit becdba8

Browse files
committed
Address comments in lowering + parsing.
1 parent 397a027 commit becdba8

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/librustc/hir/lowering.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -4185,7 +4185,7 @@ impl<'a> LoweringContext<'a> {
41854185
ParamMode::Optional,
41864186
ImplTraitContext::disallowed(),
41874187
);
4188-
let (pats, ddpos) = self.lower_pat_tuple(&*pats, "tuple struct");
4188+
let (pats, ddpos) = self.lower_pat_tuple(pats, "tuple struct");
41894189
hir::PatKind::TupleStruct(qpath, pats, ddpos)
41904190
}
41914191
PatKind::Path(ref qself, ref path) => {
@@ -4224,7 +4224,7 @@ impl<'a> LoweringContext<'a> {
42244224
hir::PatKind::Struct(qpath, fs, etc)
42254225
}
42264226
PatKind::Tuple(ref pats) => {
4227-
let (pats, ddpos) = self.lower_pat_tuple(&*pats, "tuple");
4227+
let (pats, ddpos) = self.lower_pat_tuple(pats, "tuple");
42284228
hir::PatKind::Tuple(pats, ddpos)
42294229
}
42304230
PatKind::Box(ref inner) => hir::PatKind::Box(self.lower_pat(inner)),
@@ -4245,7 +4245,7 @@ impl<'a> LoweringContext<'a> {
42454245
PatKind::Mac(_) => panic!("Shouldn't exist here"),
42464246
};
42474247

4248-
self.pat_bound(p, node)
4248+
self.pat_with_node_id_of(p, node)
42494249
}
42504250

42514251
fn lower_pat_tuple(
@@ -4291,14 +4291,14 @@ impl<'a> LoweringContext<'a> {
42914291
match pat.node {
42924292
PatKind::Rest => {
42934293
prev_rest_span = Some(pat.span);
4294-
slice = Some(self.pat_bound_wild(pat));
4294+
slice = Some(self.pat_wild_with_node_id_of(pat));
42954295
break;
42964296
},
42974297
PatKind::Ident(ref bm, ident, Some(ref sub)) if sub.is_rest() => {
42984298
prev_rest_span = Some(sub.span);
4299-
let lower_sub = |this: &mut Self| Some(this.pat_bound_wild(sub));
4299+
let lower_sub = |this: &mut Self| Some(this.pat_wild_with_node_id_of(sub));
43004300
let node = self.lower_pat_ident(pat, bm, ident, lower_sub);
4301-
slice = Some(self.pat_bound(pat, node));
4301+
slice = Some(self.pat_with_node_id_of(pat, node));
43024302
break;
43034303
},
43044304
_ => {}
@@ -4314,7 +4314,7 @@ impl<'a> LoweringContext<'a> {
43144314
PatKind::Rest => Some(pat.span),
43154315
PatKind::Ident(.., Some(ref sub)) if sub.is_rest() => {
43164316
// The `HirValidator` is merciless; add a `_` pattern to avoid ICEs.
4317-
after.push(self.pat_bound_wild(pat));
4317+
after.push(self.pat_wild_with_node_id_of(pat));
43184318
Some(sub.span)
43194319
},
43204320
_ => None,
@@ -4362,12 +4362,12 @@ impl<'a> LoweringContext<'a> {
43624362
}
43634363
}
43644364

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

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

src/libsyntax/parse/parser.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -3748,8 +3748,9 @@ impl<'a> Parser<'a> {
37483748
})
37493749
}
37503750

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

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

0 commit comments

Comments
 (0)