Skip to content

Commit f76a737

Browse files
committed
Correct span for pub_restricted field
1 parent 8787a12 commit f76a737

File tree

3 files changed

+37
-25
lines changed

3 files changed

+37
-25
lines changed

Diff for: src/libsyntax/parse/parser.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -3760,19 +3760,18 @@ impl<'a> Parser<'a> {
37603760
}
37613761

37623762
/// Parse a structure field
3763-
fn parse_name_and_ty(&mut self, pr: Visibility,
3764-
attrs: Vec<Attribute> ) -> PResult<'a, StructField> {
3765-
let lo = match pr {
3766-
Visibility::Inherited => self.span.lo,
3767-
_ => self.last_span.lo,
3768-
};
3763+
fn parse_name_and_ty(&mut self,
3764+
lo: BytePos,
3765+
vis: Visibility,
3766+
attrs: Vec<Attribute>)
3767+
-> PResult<'a, StructField> {
37693768
let name = self.parse_ident()?;
37703769
self.expect(&token::Colon)?;
37713770
let ty = self.parse_ty_sum()?;
37723771
Ok(StructField {
37733772
span: mk_sp(lo, self.last_span.hi),
37743773
ident: Some(name),
3775-
vis: pr,
3774+
vis: vis,
37763775
id: ast::DUMMY_NODE_ID,
37773776
ty: ty,
37783777
attrs: attrs,
@@ -5092,10 +5091,11 @@ impl<'a> Parser<'a> {
50925091

50935092
/// Parse a structure field declaration
50945093
pub fn parse_single_struct_field(&mut self,
5094+
lo: BytePos,
50955095
vis: Visibility,
50965096
attrs: Vec<Attribute> )
50975097
-> PResult<'a, StructField> {
5098-
let a_var = self.parse_name_and_ty(vis, attrs)?;
5098+
let a_var = self.parse_name_and_ty(lo, vis, attrs)?;
50995099
match self.token {
51005100
token::Comma => {
51015101
self.bump();
@@ -5116,8 +5116,9 @@ impl<'a> Parser<'a> {
51165116
/// Parse an element of a struct definition
51175117
fn parse_struct_decl_field(&mut self) -> PResult<'a, StructField> {
51185118
let attrs = self.parse_outer_attributes()?;
5119+
let lo = self.span.lo;
51195120
let vis = self.parse_visibility(true)?;
5120-
self.parse_single_struct_field(vis, attrs)
5121+
self.parse_single_struct_field(lo, vis, attrs)
51215122
}
51225123

51235124
// If `allow_path` is false, just parse the `pub` in `pub(path)` (but still parse `pub(crate)`)
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -8,23 +8,15 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// Regression test for issue #26083
12-
// Test that span for public struct fields start at `pub` instead of the identifier
11+
// Regression test for issue #26083 and #35435
12+
// Test that span for public struct fields start at `pub`
1313

14-
struct Foo {
15-
pub bar: u8,
14+
#![feature(pub_restricted)]
1615

17-
pub
18-
//~^ error: field `bar` is already declared [E0124]
16+
struct Foo {
1917
bar: u8,
20-
21-
pub bar:
22-
//~^ error: field `bar` is already declared [E0124]
23-
u8,
24-
25-
bar:
26-
//~^ error: field `bar` is already declared [E0124]
27-
u8,
18+
pub bar: u8,
19+
pub(crate) bar: u8,
2820
}
2921

30-
fn main() { }
22+
fn main() {}

Diff for: src/test/ui/span/pub-struct-field.stderr

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0124]: field `bar` is already declared
2+
--> $DIR/pub-struct-field.rs:18:5
3+
|
4+
17 | bar: u8,
5+
| ------- `bar` first declared here
6+
18 | pub bar: u8,
7+
| ^^^^^^^^^^^ field already declared
8+
9+
error[E0124]: field `bar` is already declared
10+
--> $DIR/pub-struct-field.rs:19:5
11+
|
12+
17 | bar: u8,
13+
| ------- `bar` first declared here
14+
18 | pub bar: u8,
15+
19 | pub(crate) bar: u8,
16+
| ^^^^^^^^^^^^^^^^^^ field already declared
17+
18+
error: aborting due to 2 previous errors
19+

0 commit comments

Comments
 (0)