diff options
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index db10dc1bc90..b7a31bb350a 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -4648,7 +4648,7 @@ impl<'a> Parser<'a> { is_tuple_like = false; fields = Vec::new(); while self.token != token::CloseDelim(token::Brace) { - fields.push(self.parse_struct_decl_field()); + fields.push(self.parse_struct_decl_field(true)); } if fields.len() == 0 { self.fatal(format!("unit-like struct definition should be \ @@ -4725,12 +4725,16 @@ impl<'a> Parser<'a> { } /// Parse an element of a struct definition - fn parse_struct_decl_field(&mut self) -> StructField { + fn parse_struct_decl_field(&mut self, allow_pub: bool) -> StructField { let attrs = self.parse_outer_attributes(); if self.eat_keyword(keywords::Pub) { - return self.parse_single_struct_field(Public, attrs); + if !allow_pub { + let span = self.last_span; + self.span_err(span, "`pub` is not allowed here"); + } + return self.parse_single_struct_field(Public, attrs); } return self.parse_single_struct_field(Inherited, attrs); @@ -5178,7 +5182,7 @@ impl<'a> Parser<'a> { fn parse_struct_def(&mut self) -> P<StructDef> { let mut fields: Vec<StructField> = Vec::new(); while self.token != token::CloseDelim(token::Brace) { - fields.push(self.parse_struct_decl_field()); + fields.push(self.parse_struct_decl_field(false)); } self.bump(); |
