Skip to content

Commit 517ad98

Browse files
committed
Handle interpolated paths in pattern parsing. Fixes #3007.
We might need to use is_ident_or_path in a for other places too.
1 parent 4544c01 commit 517ad98

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident,
7373
~[rhs]);
7474
let p = parser(cx.parse_sess(), cx.cfg(),
7575
trncbr as reader, SOURCE_FILE);
76-
return mr_expr(p.parse_expr());
76+
let e = p.parse_expr();
77+
return mr_expr(e);
7778
}
7879
failure(sp, msg) => if sp.lo >= best_fail_spot.lo {
7980
best_fail_spot = sp;

src/libsyntax/parse/parser.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import print::pprust::expr_to_str;
33
import result::result;
44
import either::{either, left, right};
55
import std::map::{hashmap, str_hash};
6-
import token::{can_begin_expr, is_ident, is_plain_ident, INTERPOLATED};
6+
import token::{can_begin_expr, is_ident, is_ident_or_path, is_plain_ident,
7+
INTERPOLATED};
78
import codemap::{span,fss_none};
89
import util::interner;
910
import ast_util::{spanned, respan, mk_sp, ident_to_path, operator_prec};
@@ -1748,7 +1749,7 @@ class parser {
17481749
}
17491750
}
17501751
tok => {
1751-
if !is_ident(tok) ||
1752+
if !is_ident_or_path(tok) ||
17521753
self.is_keyword(~"true") || self.is_keyword(~"false") {
17531754
let val = self.parse_expr_res(RESTRICT_NO_BAR_OP);
17541755
if self.eat_keyword(~"to") {

src/libsyntax/parse/token.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,13 @@ pure fn is_ident(t: token) -> bool {
262262
alt t { IDENT(_, _) => true, _ => false }
263263
}
264264

265+
pure fn is_ident_or_path(t: token) -> bool {
266+
alt t {
267+
IDENT(_, _) | INTERPOLATED(nt_path(*)) => true,
268+
_ => false
269+
}
270+
}
271+
265272
pure fn is_plain_ident(t: token) -> bool {
266273
alt t { IDENT(_, false) => true, _ => false }
267274
}

0 commit comments

Comments
 (0)