diff options
| author | Jakub Wieczorek <jakub@jakub.cc> | 2014-09-20 22:29:26 +0200 |
|---|---|---|
| committer | Jakub Wieczorek <jakub@jakub.cc> | 2014-09-21 01:33:57 +0200 |
| commit | 3514737b4cf1d91dc8c7b61c95f2f20d3b386d1c (patch) | |
| tree | 3bc63441a07dff2193ad5dcf82c9453470af704f | |
| parent | 5d335c94bd9017f16ce7538a5f4063e1178f15a1 (diff) | |
| download | rust-3514737b4cf1d91dc8c7b61c95f2f20d3b386d1c.tar.gz rust-3514737b4cf1d91dc8c7b61c95f2f20d3b386d1c.zip | |
Fix the span for discriminators in non-C-like enums
Fixes #17383.
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 12 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-17383.rs | 18 |
2 files changed, 25 insertions, 5 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 069d30cbd83..fbec61441d1 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -5052,7 +5052,7 @@ impl<'a> Parser<'a> { fn parse_enum_def(&mut self, _generics: &ast::Generics) -> EnumDef { let mut variants = Vec::new(); let mut all_nullary = true; - let mut have_disr = false; + let mut any_disr = None; while self.token != token::RBRACE { let variant_attrs = self.parse_outer_attributes(); let vlo = self.span.lo; @@ -5084,8 +5084,8 @@ impl<'a> Parser<'a> { } kind = TupleVariantKind(args); } else if self.eat(&token::EQ) { - have_disr = true; disr_expr = Some(self.parse_expr()); + any_disr = disr_expr.as_ref().map(|expr| expr.span); kind = TupleVariantKind(args); } else { kind = TupleVariantKind(Vec::new()); @@ -5104,9 +5104,11 @@ impl<'a> Parser<'a> { if !self.eat(&token::COMMA) { break; } } self.expect(&token::RBRACE); - if have_disr && !all_nullary { - self.fatal("discriminator values can only be used with a c-like \ - enum"); + match any_disr { + Some(disr_span) if !all_nullary => + self.span_err(disr_span, + "discriminator values can only be used with a c-like enum"), + _ => () } ast::EnumDef { variants: variants } diff --git a/src/test/compile-fail/issue-17383.rs b/src/test/compile-fail/issue-17383.rs new file mode 100644 index 00000000000..24007364550 --- /dev/null +++ b/src/test/compile-fail/issue-17383.rs @@ -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() {} |
