diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2016-04-06 17:15:31 +0530 |
|---|---|---|
| committer | Manish Goregaokar <manishsmail@gmail.com> | 2016-04-06 17:15:31 +0530 |
| commit | af7b00b68fc7960e98fb914be52d9a6a16fe2224 (patch) | |
| tree | 13260050b5b5463c491ae61c941f60477421fdc0 /src/libsyntax/parse | |
| parent | 772c600d4d6f39daa6d07d1a60ee0df3d3426978 (diff) | |
| parent | 8fe4290f1cf87bf7b0a0661e6bbe84f3319e614d (diff) | |
| download | rust-af7b00b68fc7960e98fb914be52d9a6a16fe2224.tar.gz rust-af7b00b68fc7960e98fb914be52d9a6a16fe2224.zip | |
Rollup merge of #32682 - petrochenkov:field3, r=Manishearth
The AST part of https://github.com/rust-lang/rust/pull/31937 Unlike HIR, AST still uses `Option` for field names because parser can't know field indexes reliably due to constructions like ``` struct S(#[cfg(false)] u8, u8); // The index of the second field changes from 1 during parsing to 0 after expansion. ``` and I wouldn't like to put the burden of renaming fields on expansion passes and syntax extensions. plugin-[breaking-change] cc https://github.com/rust-lang/rust/issues/31645 r? @Manishearth
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 89a504e1ebd..28e4682f66b 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -29,7 +29,6 @@ use ast::Local; use ast::MacStmtStyle; use ast::Mac_; use ast::{MutTy, Mutability}; -use ast::NamedField; use ast::{Pat, PatKind}; use ast::{PolyTraitRef, QSelf}; use ast::{Stmt, StmtKind}; @@ -38,7 +37,6 @@ use ast::StrStyle; use ast::SelfKind; use ast::{Delimited, SequenceRepetition, TokenTree, TraitItem, TraitRef}; use ast::{Ty, TyKind, TypeBinding, TyParam, TyParamBounds}; -use ast::UnnamedField; use ast::{ViewPath, ViewPathGlob, ViewPathList, ViewPathSimple}; use ast::{Visibility, WhereClause}; use attr::{ThinAttributes, ThinAttributesExt, AttributesExt}; @@ -3847,12 +3845,14 @@ impl<'a> Parser<'a> { let name = self.parse_ident()?; self.expect(&token::Colon)?; let ty = self.parse_ty_sum()?; - Ok(spanned(lo, self.last_span.hi, ast::StructField_ { - kind: NamedField(name, pr), + Ok(StructField { + span: mk_sp(lo, self.last_span.hi), + ident: Some(name), + vis: pr, id: ast::DUMMY_NODE_ID, ty: ty, attrs: attrs, - })) + }) } /// Emit an expected item after attributes error. @@ -5246,13 +5246,16 @@ impl<'a> Parser<'a> { |p| { let attrs = p.parse_outer_attributes()?; let lo = p.span.lo; - let struct_field_ = ast::StructField_ { - kind: UnnamedField(p.parse_visibility()?), + let vis = p.parse_visibility()?; + let ty = p.parse_ty_sum()?; + Ok(StructField { + span: mk_sp(lo, p.span.hi), + vis: vis, + ident: None, id: ast::DUMMY_NODE_ID, - ty: p.parse_ty_sum()?, + ty: ty, attrs: attrs, - }; - Ok(spanned(lo, p.span.hi, struct_field_)) + }) })?; Ok(fields) |
