From 2985b8e55283ec14548f35f9057a0305e0b84618 Mon Sep 17 00:00:00 2001 From: Mahmut Bulut Date: Tue, 23 Oct 2012 09:42:30 +0300 Subject: [PATCH 1/4] * Parsing sequence changed 1- visibility parse 2- purity parse --- src/libsyntax/parse/parser.rs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 1ee683bdd0887..ed9be96f02773 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -333,10 +333,11 @@ impl Parser { let is_static = p.parse_staticness(); let static_sty = spanned(lo, p.span.hi, sty_static); + let vis = p.parse_visibility(); let pur = p.parse_fn_purity(); // NB: at the moment, trait methods are public by default; this // could change. - let vis = p.parse_visibility(); + let ident = p.parse_method_name(); let tps = p.parse_ty_params(); @@ -2528,13 +2529,14 @@ impl Parser { self.parse_value_ident() } - fn parse_method(pr: visibility) -> @method { + fn parse_method() -> @method { let attrs = self.parse_outer_attributes(); let lo = self.span.lo; let is_static = self.parse_staticness(); let static_sty = spanned(lo, self.span.hi, sty_static); - + + let visa = self.parse_visibility(); let pur = self.parse_fn_purity(); let ident = self.parse_method_name(); let tps = self.parse_ty_params(); @@ -2549,7 +2551,7 @@ impl Parser { @{ident: ident, attrs: attrs, tps: tps, self_ty: self_ty, purity: pur, decl: decl, body: body, id: self.get_id(), span: mk_sp(lo, body.span.hi), - self_id: self.get_id(), vis: pr} + self_id: self.get_id(), vis: visa} } fn parse_item_trait() -> item_info { @@ -2606,8 +2608,7 @@ impl Parser { let mut meths = ~[]; self.expect(token::LBRACE); while !self.eat(token::RBRACE) { - let vis = self.parse_visibility(); - meths.push(self.parse_method(vis)); + meths.push(self.parse_method()); } (ident, item_impl(tps, opt_trait, ty, meths), None) } @@ -2763,7 +2764,7 @@ impl Parser { return a_var; } else { self.obsolete(copy self.span, ObsoleteClassMethod); - return @method_member(self.parse_method(vis)); + return @method_member(self.parse_method()); } } @@ -2869,9 +2870,9 @@ impl Parser { (id, item_mod(m), Some(inner_attrs.inner)) } - fn parse_item_foreign_fn(vis: ast::visibility, - +attrs: ~[attribute]) -> @foreign_item { + fn parse_item_foreign_fn( +attrs: ~[attribute]) -> @foreign_item { let lo = self.span.lo; + let vis = self.parse_visibility(); let purity = self.parse_fn_purity(); let t = self.parse_fn_header(); let (decl, _) = self.parse_fn_decl(|p| p.parse_arg()); @@ -2919,7 +2920,7 @@ impl Parser { if self.is_keyword(~"const") { self.parse_item_foreign_const(vis, move attrs) } else { - self.parse_item_foreign_fn(vis, move attrs) + self.parse_item_foreign_fn( move attrs) } } @@ -3239,7 +3240,7 @@ impl Parser { maybe_append(attrs, extra_attrs))); } else if foreign_items_allowed && (self.is_keyword(~"fn") || self.is_keyword(~"pure")) { - let item = self.parse_item_foreign_fn(visibility, attrs); + let item = self.parse_item_foreign_fn(attrs); return iovi_foreign_item(item); } else if items_allowed && self.is_keyword(~"unsafe") && self.look_ahead(1u) != token::LBRACE { From 21cbc310c7cc631b39b3b08f127d19747e2a232d Mon Sep 17 00:00:00 2001 From: Mahmut Bulut Date: Wed, 24 Oct 2012 16:51:33 +0300 Subject: [PATCH 2/4] Make check & Tidy --- src/libsyntax/parse/parser.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index ed9be96f02773..467e001ede7d4 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -333,11 +333,10 @@ impl Parser { let is_static = p.parse_staticness(); let static_sty = spanned(lo, p.span.hi, sty_static); - let vis = p.parse_visibility(); + let vis = p.parse_visibility(); let pur = p.parse_fn_purity(); // NB: at the moment, trait methods are public by default; this // could change. - let ident = p.parse_method_name(); let tps = p.parse_ty_params(); @@ -2535,8 +2534,8 @@ impl Parser { let is_static = self.parse_staticness(); let static_sty = spanned(lo, self.span.hi, sty_static); - - let visa = self.parse_visibility(); + + let visa = self.parse_visibility(); let pur = self.parse_fn_purity(); let ident = self.parse_method_name(); let tps = self.parse_ty_params(); From 27fb3fe90d53ecebb874d32f02433da5e3a62a23 Mon Sep 17 00:00:00 2001 From: Mahmut Bulut Date: Wed, 24 Oct 2012 18:32:36 +0300 Subject: [PATCH 3/4] stage2 run-pass test for #3753 --- src/test/run-pass/issue-3753.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/test/run-pass/issue-3753.rs diff --git a/src/test/run-pass/issue-3753.rs b/src/test/run-pass/issue-3753.rs new file mode 100644 index 0000000000000..986d6a1817b27 --- /dev/null +++ b/src/test/run-pass/issue-3753.rs @@ -0,0 +1,27 @@ +// Issue #3656 +// Issue Name: pub method preceeded by attribute can't be parsed +// Abstract: Visibility parsing failed when compiler parsing + +struct Point { + x: float, + y: float +} + +pub enum Shape { + Circle(Point, float), + Rectangle(Point, Point) +} + +pub impl Shape { + pub fn area(sh: Shape) -> float { + match sh { + Circle(_, size) => float::consts::pi * size * size, + Rectangle(Point {x, y}, Point {x: x2, y: y2}) => (x2 - x) * (y2 - y) + } + } +} + +fn main(){ + let s = Circle(Point { x: 1f, y: 2f }, 3f); + io::println(fmt!("%f", s.area(s))); +} \ No newline at end of file From ef129d21e3f45123b0e0e23f7867c001cdf21bfb Mon Sep 17 00:00:00 2001 From: Mahmut Bulut Date: Wed, 24 Oct 2012 18:36:40 +0300 Subject: [PATCH 4/4] .settings/ added in .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index bfcdf15fd2fe0..83d6186c9e19b 100644 --- a/.gitignore +++ b/.gitignore @@ -80,3 +80,4 @@ tmp.*.rs config.stamp .DS_Store src/etc/dl +.settings/