@@ -5052,7 +5052,7 @@ impl<'a> Parser<'a> {
5052
5052
fn parse_enum_def ( & mut self , _generics : & ast:: Generics ) -> EnumDef {
5053
5053
let mut variants = Vec :: new ( ) ;
5054
5054
let mut all_nullary = true ;
5055
- let mut have_disr = false ;
5055
+ let mut any_disr = None ;
5056
5056
while self . token != token:: RBRACE {
5057
5057
let variant_attrs = self . parse_outer_attributes ( ) ;
5058
5058
let vlo = self . span . lo ;
@@ -5084,8 +5084,8 @@ impl<'a> Parser<'a> {
5084
5084
}
5085
5085
kind = TupleVariantKind ( args) ;
5086
5086
} else if self . eat ( & token:: EQ ) {
5087
- have_disr = true ;
5088
5087
disr_expr = Some ( self . parse_expr ( ) ) ;
5088
+ any_disr = disr_expr. as_ref ( ) . map ( |expr| expr. span ) ;
5089
5089
kind = TupleVariantKind ( args) ;
5090
5090
} else {
5091
5091
kind = TupleVariantKind ( Vec :: new ( ) ) ;
@@ -5104,9 +5104,11 @@ impl<'a> Parser<'a> {
5104
5104
if !self . eat ( & token:: COMMA ) { break ; }
5105
5105
}
5106
5106
self . expect ( & token:: RBRACE ) ;
5107
- if have_disr && !all_nullary {
5108
- self . fatal ( "discriminator values can only be used with a c-like \
5109
- enum") ;
5107
+ match any_disr {
5108
+ Some ( disr_span) if !all_nullary =>
5109
+ self . span_err ( disr_span,
5110
+ "discriminator values can only be used with a c-like enum" ) ,
5111
+ _ => ( )
5110
5112
}
5111
5113
5112
5114
ast:: EnumDef { variants : variants }
0 commit comments