Skip to content

Commit 47127e7

Browse files
Vincent-Belliardnikomatsakis
authored andcommitted
---
yaml --- r: 30760 b: refs/heads/incoming c: ef23d77 h: refs/heads/master v: v3
1 parent 97449ad commit 47127e7

File tree

5 files changed

+55
-19
lines changed

5 files changed

+55
-19
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: 95bc32dc4f5041e1e354dd23fbb70431fe8f31ca
9+
refs/heads/incoming: ef23d77633484e4e85f8b37431e3b08ede3e4802
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/libsyntax/parse/parser.rs

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,29 @@ impl parser {
584584
} else { infer(self.get_id()) }
585585
}
586586

587+
fn is_named_argument() -> bool {
588+
let offset = if self.token == token::BINOP(token::AND) {
589+
1
590+
} else if self.token == token::BINOP(token::MINUS) {
591+
1
592+
} else if self.token == token::ANDAND {
593+
1
594+
} else if self.token == token::BINOP(token::PLUS) {
595+
if self.look_ahead(1) == token::BINOP(token::PLUS) {
596+
2
597+
} else {
598+
1
599+
}
600+
} else { 0 };
601+
if offset == 0 {
602+
is_plain_ident(self.token)
603+
&& self.look_ahead(1) == token::COLON
604+
} else {
605+
is_plain_ident(self.look_ahead(offset))
606+
&& self.look_ahead(offset + 1) == token::COLON
607+
}
608+
}
609+
587610
fn parse_capture_item_or(parse_arg_fn: fn(parser) -> arg_or_capture_item)
588611
-> arg_or_capture_item {
589612

@@ -605,29 +628,17 @@ impl parser {
605628
// This version of parse arg doesn't necessarily require
606629
// identifier names.
607630
fn parse_arg_general(require_name: bool) -> arg {
608-
let m = self.parse_arg_mode();
609-
let i = if require_name {
631+
let mut m;
632+
let i = if require_name || self.is_named_argument() {
633+
m = self.parse_arg_mode();
610634
let name = self.parse_value_ident();
611635
self.expect(token::COLON);
612636
name
613637
} else {
614-
if is_plain_ident(self.token)
615-
&& self.look_ahead(1u) == token::COLON {
616-
let name = self.parse_value_ident();
617-
self.bump();
618-
name
619-
} else { special_idents::invalid }
638+
m = infer(self.get_id());
639+
special_idents::invalid
620640
};
621641

622-
match m {
623-
expl(_) => {
624-
if i == special_idents::invalid {
625-
self.obsolete(copy self.span, ObsoleteModeInFnType);
626-
}
627-
}
628-
_ => {}
629-
}
630-
631642
let t = self.parse_ty(false);
632643

633644
{mode: m, ty: t, ident: i, id: self.get_id()}

branches/incoming/src/rustc/util/ppaux.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ fn ty_to_str(cx: ctxt, typ: t) -> ~str {
261261
m == ty::default_arg_mode_for_ty(cx, ty) {
262262
~""
263263
} else {
264-
mode_to_str(ast::expl(m))
264+
mode_to_str(ast::expl(m)) + ":"
265265
}
266266
}
267267
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//error-pattern: mismatched types
2+
3+
fn bad(&a: int) {
4+
}
5+
6+
// unnamed argument &int is now parsed x: &int
7+
// it's not parsed &x: int anymore
8+
9+
fn called(f: fn(&int)) {
10+
}
11+
12+
fn main() {
13+
called(bad);
14+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
fn good(a: &int) {
2+
}
3+
4+
// unnamed argument &int is now parse x: &int
5+
6+
fn called(f: fn(&int)) {
7+
}
8+
9+
fn main() {
10+
called(good);
11+
}

0 commit comments

Comments
 (0)