@@ -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] { ... }
18531857fn 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 ) == 1 u &&
1864- vec:: len ( pt. node . types ) == 0 u {
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 ) -1 u] ;
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 ) - 1 u] ) ;
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