Skip to content

Commit

Permalink
Auto merge of #28503 - marcusklaas:pub-extern, r=alexcrichton
Browse files Browse the repository at this point in the history
Fixes #28472.
  • Loading branch information
bors committed Sep 20, 2015
2 parents fbce450 + e2f3e3a commit fd38a75
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5037,9 +5037,8 @@ impl<'a> Parser<'a> {
}

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

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

/// Parse a static item from a foreign module
fn parse_item_foreign_static(&mut self, vis: ast::Visibility,
fn parse_item_foreign_static(&mut self, vis: ast::Visibility, lo: BytePos,
attrs: Vec<Attribute>) -> PResult<P<ForeignItem>> {
let lo = self.span.lo;

try!(self.expect_keyword(keywords::Static));
let mutbl = try!(self.eat_keyword(keywords::Mut));

Expand Down Expand Up @@ -5557,11 +5554,11 @@ impl<'a> Parser<'a> {

if self.check_keyword(keywords::Static) {
// FOREIGN STATIC ITEM
return Ok(Some(try!(self.parse_item_foreign_static(visibility, attrs))));
return Ok(Some(try!(self.parse_item_foreign_static(visibility, lo, attrs))));
}
if self.check_keyword(keywords::Fn) || self.check_keyword(keywords::Unsafe) {
// FOREIGN FUNCTION ITEM
return Ok(Some(try!(self.parse_item_foreign_fn(visibility, attrs))));
return Ok(Some(try!(self.parse_item_foreign_fn(visibility, lo, attrs))));
}

// FIXME #5668: this will occur for a macro invocation:
Expand Down
24 changes: 24 additions & 0 deletions src/test/compile-fail/issue-28472.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Check that the visibility modifier is included in the span of foreign items.

extern {
fn foo();

pub //~ ERROR duplicate definition
fn foo();

pub //~ ERROR duplicate definition
static mut foo: u32;
}

fn main() {
}

0 comments on commit fd38a75

Please sign in to comment.