Skip to content

Commit 3b6f5a1

Browse files
committed
Merge branch 'method-vis-parse'
Conflicts: src/libsyntax/parse/parser.rs
2 parents 4da58a5 + 27fb3fe commit 3b6f5a1

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

src/libsyntax/parse/parser.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,10 @@ impl Parser {
333333
let is_static = p.parse_staticness();
334334
let static_sty = spanned(lo, p.span.hi, sty_static);
335335

336+
let vis = p.parse_visibility();
336337
let pur = p.parse_fn_purity();
337338
// NB: at the moment, trait methods are public by default; this
338339
// could change.
339-
let vis = p.parse_visibility();
340340
let ident = p.parse_method_name();
341341

342342
let tps = p.parse_ty_params();
@@ -2528,13 +2528,14 @@ impl Parser {
25282528
self.parse_value_ident()
25292529
}
25302530

2531-
fn parse_method(pr: visibility) -> @method {
2531+
fn parse_method() -> @method {
25322532
let attrs = self.parse_outer_attributes();
25332533
let lo = self.span.lo;
25342534

25352535
let is_static = self.parse_staticness();
25362536
let static_sty = spanned(lo, self.span.hi, sty_static);
25372537

2538+
let visa = self.parse_visibility();
25382539
let pur = self.parse_fn_purity();
25392540
let ident = self.parse_method_name();
25402541
let tps = self.parse_ty_params();
@@ -2549,7 +2550,7 @@ impl Parser {
25492550
@{ident: ident, attrs: attrs,
25502551
tps: tps, self_ty: self_ty, purity: pur, decl: decl,
25512552
body: body, id: self.get_id(), span: mk_sp(lo, body.span.hi),
2552-
self_id: self.get_id(), vis: pr}
2553+
self_id: self.get_id(), vis: visa}
25532554
}
25542555

25552556
fn parse_item_trait() -> item_info {
@@ -2610,8 +2611,7 @@ impl Parser {
26102611
let mut meths = ~[];
26112612
self.expect(token::LBRACE);
26122613
while !self.eat(token::RBRACE) {
2613-
let vis = self.parse_visibility();
2614-
meths.push(self.parse_method(vis));
2614+
meths.push(self.parse_method());
26152615
}
26162616
meths_opt = Some(move meths);
26172617
}
@@ -2772,7 +2772,7 @@ impl Parser {
27722772
return a_var;
27732773
} else {
27742774
self.obsolete(copy self.span, ObsoleteClassMethod);
2775-
return @method_member(self.parse_method(vis));
2775+
return @method_member(self.parse_method());
27762776
}
27772777
}
27782778

@@ -2878,9 +2878,9 @@ impl Parser {
28782878
(id, item_mod(m), Some(inner_attrs.inner))
28792879
}
28802880

2881-
fn parse_item_foreign_fn(vis: ast::visibility,
2882-
+attrs: ~[attribute]) -> @foreign_item {
2881+
fn parse_item_foreign_fn( +attrs: ~[attribute]) -> @foreign_item {
28832882
let lo = self.span.lo;
2883+
let vis = self.parse_visibility();
28842884
let purity = self.parse_fn_purity();
28852885
let t = self.parse_fn_header();
28862886
let (decl, _) = self.parse_fn_decl(|p| p.parse_arg());
@@ -2928,7 +2928,7 @@ impl Parser {
29282928
if self.is_keyword(~"const") {
29292929
self.parse_item_foreign_const(vis, move attrs)
29302930
} else {
2931-
self.parse_item_foreign_fn(vis, move attrs)
2931+
self.parse_item_foreign_fn( move attrs)
29322932
}
29332933
}
29342934

@@ -3249,7 +3249,7 @@ impl Parser {
32493249
maybe_append(attrs, extra_attrs)));
32503250
} else if foreign_items_allowed &&
32513251
(self.is_keyword(~"fn") || self.is_keyword(~"pure")) {
3252-
let item = self.parse_item_foreign_fn(visibility, attrs);
3252+
let item = self.parse_item_foreign_fn(attrs);
32533253
return iovi_foreign_item(item);
32543254
} else if items_allowed && self.is_keyword(~"unsafe")
32553255
&& self.look_ahead(1u) != token::LBRACE {

src/test/run-pass/issue-3753.rs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Issue #3656
2+
// Issue Name: pub method preceeded by attribute can't be parsed
3+
// Abstract: Visibility parsing failed when compiler parsing
4+
5+
struct Point {
6+
x: float,
7+
y: float
8+
}
9+
10+
pub enum Shape {
11+
Circle(Point, float),
12+
Rectangle(Point, Point)
13+
}
14+
15+
pub impl Shape {
16+
pub fn area(sh: Shape) -> float {
17+
match sh {
18+
Circle(_, size) => float::consts::pi * size * size,
19+
Rectangle(Point {x, y}, Point {x: x2, y: y2}) => (x2 - x) * (y2 - y)
20+
}
21+
}
22+
}
23+
24+
fn main(){
25+
let s = Circle(Point { x: 1f, y: 2f }, 3f);
26+
io::println(fmt!("%f", s.area(s)));
27+
}

0 commit comments

Comments
 (0)