Skip to content

Commit 38503e6

Browse files
committed
---
yaml --- r: 7007 b: refs/heads/master c: 506a6ec h: refs/heads/master i: 7005: b3e3fb9 7003: a4659d4 6999: e3b4084 6991: 63e5d22 6975: 4b4512f v: v3
1 parent 654ee23 commit 38503e6

File tree

2 files changed

+19
-24
lines changed

2 files changed

+19
-24
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: e1dc40b2717c3469a52d3b8ae31b377dbd6e4d60
2+
refs/heads/master: 506a6ec38b4e5f5fc80d8c6bfc388e5cdba4d772

trunk/src/comp/syntax/parse/parser.rs

+18-23
Original file line numberDiff line numberDiff line change
@@ -1850,34 +1850,29 @@ fn parse_item_iface(p: parser, attrs: [ast::attribute]) -> @ast::item {
18501850
ast::item_iface(tps, meths), attrs);
18511851
}
18521852

1853+
// Parses three variants (with the initial params always optional):
1854+
// impl <T: copy> of to_str for [T] { ... }
1855+
// impl name<T> of to_str for [T] { ... }
1856+
// impl name<T> for [T] { ... }
18531857
fn parse_item_impl(p: parser, attrs: [ast::attribute]) -> @ast::item {
1854-
let lo = p.get_last_lo_pos(), ident, tps, ifce;
1858+
let lo = p.get_last_lo_pos();
18551859
fn wrap_path(p: parser, pt: @ast::path) -> @ast::ty {
18561860
@{node: ast::ty_path(pt, p.get_id()), span: pt.span}
18571861
}
1858-
if eat_word(p, "of") {
1862+
let (ident, tps) = if !is_word(p, "of") {
1863+
if p.peek() == token::LT { (none, parse_ty_params(p)) }
1864+
else { (some(parse_ident(p)), parse_ty_params(p)) }
1865+
} else { (none, []) };
1866+
let ifce = if eat_word(p, "of") {
18591867
let path = parse_path_and_ty_param_substs(p, false);
1860-
tps = vec::map(path.node.types, {|tp|
1861-
alt tp.node {
1862-
ast::ty_path(pt, _) {
1863-
if vec::len(pt.node.idents) == 1u &&
1864-
vec::len(pt.node.types) == 0u {
1865-
ret {ident: pt.node.idents[0], id: p.get_id(),
1866-
bounds: @[]};
1867-
}
1868-
}
1869-
_ {}
1870-
}
1871-
p.fatal("only single-word, parameter-less types allowed here");
1872-
});
1873-
ident = path.node.idents[vec::len(path.node.idents)-1u];
1874-
ifce = some(wrap_path(p, path));
1875-
} else {
1876-
ident = parse_ident(p);
1877-
tps = parse_ty_params(p);
1878-
ifce = if eat_word(p, "of") {
1879-
some(wrap_path(p, parse_path_and_ty_param_substs(p, false)))
1880-
} else { none };
1868+
if option::is_none(ident) {
1869+
ident = some(path.node.idents[vec::len(path.node.idents) - 1u]);
1870+
}
1871+
some(wrap_path(p, path))
1872+
} else { none };
1873+
let ident = alt ident {
1874+
some(name) { name }
1875+
none. { expect_word(p, "of"); fail; }
18811876
};
18821877
expect_word(p, "for");
18831878
let ty = parse_ty(p, false), meths = [];

0 commit comments

Comments
 (0)