auto merge of #17415 : jakub-/rust/issue-17383, r=huonw

Fixes #17383.
This commit is contained in:
bors 2014-09-21 01:00:29 +00:00
commit d7e1bb5ff4
2 changed files with 25 additions and 5 deletions

View File

@ -5069,7 +5069,7 @@ impl<'a> Parser<'a> {
fn parse_enum_def(&mut self, _generics: &ast::Generics) -> EnumDef { fn parse_enum_def(&mut self, _generics: &ast::Generics) -> EnumDef {
let mut variants = Vec::new(); let mut variants = Vec::new();
let mut all_nullary = true; let mut all_nullary = true;
let mut have_disr = false; let mut any_disr = None;
while self.token != token::RBRACE { while self.token != token::RBRACE {
let variant_attrs = self.parse_outer_attributes(); let variant_attrs = self.parse_outer_attributes();
let vlo = self.span.lo; let vlo = self.span.lo;
@ -5101,8 +5101,8 @@ impl<'a> Parser<'a> {
} }
kind = TupleVariantKind(args); kind = TupleVariantKind(args);
} else if self.eat(&token::EQ) { } else if self.eat(&token::EQ) {
have_disr = true;
disr_expr = Some(self.parse_expr()); disr_expr = Some(self.parse_expr());
any_disr = disr_expr.as_ref().map(|expr| expr.span);
kind = TupleVariantKind(args); kind = TupleVariantKind(args);
} else { } else {
kind = TupleVariantKind(Vec::new()); kind = TupleVariantKind(Vec::new());
@ -5121,9 +5121,11 @@ impl<'a> Parser<'a> {
if !self.eat(&token::COMMA) { break; } if !self.eat(&token::COMMA) { break; }
} }
self.expect(&token::RBRACE); self.expect(&token::RBRACE);
if have_disr && !all_nullary { match any_disr {
self.fatal("discriminator values can only be used with a c-like \ Some(disr_span) if !all_nullary =>
enum"); self.span_err(disr_span,
"discriminator values can only be used with a c-like enum"),
_ => ()
} }
ast::EnumDef { variants: variants } ast::EnumDef { variants: variants }

View File

@ -0,0 +1,18 @@
// Copyright 2014 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.
enum X {
A =
b'a' //~ ERROR discriminator values can only be used with a c-like enum
,
B(int)
}
fn main() {}