Skip to content

Commit e2f3e3a

Browse files
committed
Include visibility modifier in span of foreign item
1 parent dc1c797 commit e2f3e3a

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5037,9 +5037,8 @@ impl<'a> Parser<'a> {
50375037
}
50385038

50395039
/// Parse a function declaration from a foreign module
5040-
fn parse_item_foreign_fn(&mut self, vis: ast::Visibility,
5040+
fn parse_item_foreign_fn(&mut self, vis: ast::Visibility, lo: BytePos,
50415041
attrs: Vec<Attribute>) -> PResult<P<ForeignItem>> {
5042-
let lo = self.span.lo;
50435042
try!(self.expect_keyword(keywords::Fn));
50445043

50455044
let (ident, mut generics) = try!(self.parse_fn_header());
@@ -5058,10 +5057,8 @@ impl<'a> Parser<'a> {
50585057
}
50595058

50605059
/// Parse a static item from a foreign module
5061-
fn parse_item_foreign_static(&mut self, vis: ast::Visibility,
5060+
fn parse_item_foreign_static(&mut self, vis: ast::Visibility, lo: BytePos,
50625061
attrs: Vec<Attribute>) -> PResult<P<ForeignItem>> {
5063-
let lo = self.span.lo;
5064-
50655062
try!(self.expect_keyword(keywords::Static));
50665063
let mutbl = try!(self.eat_keyword(keywords::Mut));
50675064

@@ -5554,11 +5551,11 @@ impl<'a> Parser<'a> {
55545551

55555552
if self.check_keyword(keywords::Static) {
55565553
// FOREIGN STATIC ITEM
5557-
return Ok(Some(try!(self.parse_item_foreign_static(visibility, attrs))));
5554+
return Ok(Some(try!(self.parse_item_foreign_static(visibility, lo, attrs))));
55585555
}
55595556
if self.check_keyword(keywords::Fn) || self.check_keyword(keywords::Unsafe) {
55605557
// FOREIGN FUNCTION ITEM
5561-
return Ok(Some(try!(self.parse_item_foreign_fn(visibility, attrs))));
5558+
return Ok(Some(try!(self.parse_item_foreign_fn(visibility, lo, attrs))));
55625559
}
55635560

55645561
// FIXME #5668: this will occur for a macro invocation:

src/test/compile-fail/issue-28472.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Check that the visibility modifier is included in the span of foreign items.
12+
13+
extern {
14+
fn foo();
15+
16+
pub //~ ERROR duplicate definition
17+
fn foo();
18+
19+
pub //~ ERROR duplicate definition
20+
static mut foo: u32;
21+
}
22+
23+
fn main() {
24+
}

0 commit comments

Comments
 (0)