From a72283832d3e64fb09fd4e6243c22c72cccd8779 Mon Sep 17 00:00:00 2001 From: Chris Hellmuth <chellmuth@gmail.com> Date: Sun, 7 Jun 2015 16:34:03 -0600 Subject: [PATCH 1/3] StructField span should include `pub` --- src/libsyntax/parse/parser.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 539d594cb8b..6cfa6c05701 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3395,7 +3395,10 @@ impl<'a> Parser<'a> { /// Parse a structure field fn parse_name_and_ty(&mut self, pr: Visibility, attrs: Vec<Attribute> ) -> PResult<StructField> { - let lo = self.span.lo; + let lo = match pr { + Inherited => self.span.lo, + Public => self.last_span.lo, + }; if !self.token.is_plain_ident() { return Err(self.fatal("expected ident")); } From 2938d92a35dbb55dfbf444f92a73865a475733f1 Mon Sep 17 00:00:00 2001 From: Chris Hellmuth <chellmuth@gmail.com> Date: Sun, 7 Jun 2015 17:29:09 -0600 Subject: [PATCH 2/3] Add a regression test for public struct field spans --- .../pub-struct-field-span-26083.rs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/test/compile-fail/pub-struct-field-span-26083.rs diff --git a/src/test/compile-fail/pub-struct-field-span-26083.rs b/src/test/compile-fail/pub-struct-field-span-26083.rs new file mode 100644 index 00000000000..ef0f7a546eb --- /dev/null +++ b/src/test/compile-fail/pub-struct-field-span-26083.rs @@ -0,0 +1,20 @@ +// Regression test for issue #26083 +// Test that span for public struct fields start at `pub` instead of the identifier + +struct Foo { + pub bar: u8, + + pub + //~^ error: field `bar` is already declared [E0124] + bar: u8, + + pub bar: + //~^ error: field `bar` is already declared [E0124] + u8, + + bar: + //~^ error: field `bar` is already declared [E0124] + u8, +} + +fn main() { } From 905727246a38d72d6df7608ca976e1880ddc6a85 Mon Sep 17 00:00:00 2001 From: Chris Hellmuth <chellmuth@gmail.com> Date: Sun, 7 Jun 2015 22:33:54 -0600 Subject: [PATCH 3/3] Add license --- src/test/compile-fail/pub-struct-field-span-26083.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/test/compile-fail/pub-struct-field-span-26083.rs b/src/test/compile-fail/pub-struct-field-span-26083.rs index ef0f7a546eb..0dc7e09f0e4 100644 --- a/src/test/compile-fail/pub-struct-field-span-26083.rs +++ b/src/test/compile-fail/pub-struct-field-span-26083.rs @@ -1,3 +1,13 @@ +// Copyright 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. + // Regression test for issue #26083 // Test that span for public struct fields start at `pub` instead of the identifier