From e2f3e3ac4f79fbfb872863135a732e9d4ccdbe6c Mon Sep 17 00:00:00 2001 From: Marcus Klaas Date: Sat, 19 Sep 2015 00:27:51 +0200 Subject: [PATCH] Include visibility modifier in span of foreign item --- src/libsyntax/parse/parser.rs | 11 ++++------- src/test/compile-fail/issue-28472.rs | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 src/test/compile-fail/issue-28472.rs diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index a7978babcb7e1..d6a34b328e89f 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -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) -> PResult> { - let lo = self.span.lo; try!(self.expect_keyword(keywords::Fn)); let (ident, mut generics) = try!(self.parse_fn_header()); @@ -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) -> PResult> { - let lo = self.span.lo; - try!(self.expect_keyword(keywords::Static)); let mutbl = try!(self.eat_keyword(keywords::Mut)); @@ -5554,11 +5551,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: diff --git a/src/test/compile-fail/issue-28472.rs b/src/test/compile-fail/issue-28472.rs new file mode 100644 index 0000000000000..23827c55a1044 --- /dev/null +++ b/src/test/compile-fail/issue-28472.rs @@ -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 or the MIT license +// , 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() { +}