@@ -5069,7 +5069,7 @@ impl<'a> Parser<'a> {
5069
5069
fn parse_enum_def ( & mut self , _generics : & ast:: Generics ) -> EnumDef {
5070
5070
let mut variants = Vec :: new ( ) ;
5071
5071
let mut all_nullary = true ;
5072
- let mut have_disr = false ;
5072
+ let mut any_disr = None ;
5073
5073
while self . token != token:: RBRACE {
5074
5074
let variant_attrs = self . parse_outer_attributes ( ) ;
5075
5075
let vlo = self . span . lo ;
@@ -5101,8 +5101,8 @@ impl<'a> Parser<'a> {
5101
5101
}
5102
5102
kind = TupleVariantKind ( args) ;
5103
5103
} else if self . eat ( & token:: EQ ) {
5104
- have_disr = true ;
5105
5104
disr_expr = Some ( self . parse_expr ( ) ) ;
5105
+ any_disr = disr_expr. as_ref ( ) . map ( |expr| expr. span ) ;
5106
5106
kind = TupleVariantKind ( args) ;
5107
5107
} else {
5108
5108
kind = TupleVariantKind ( Vec :: new ( ) ) ;
@@ -5121,9 +5121,11 @@ impl<'a> Parser<'a> {
5121
5121
if !self . eat ( & token:: COMMA ) { break ; }
5122
5122
}
5123
5123
self . expect ( & token:: RBRACE ) ;
5124
- if have_disr && !all_nullary {
5125
- self . fatal ( "discriminator values can only be used with a c-like \
5126
- enum") ;
5124
+ match any_disr {
5125
+ Some ( disr_span) if !all_nullary =>
5126
+ self . span_err ( disr_span,
5127
+ "discriminator values can only be used with a c-like enum" ) ,
5128
+ _ => ( )
5127
5129
}
5128
5130
5129
5131
ast:: EnumDef { variants : variants }
0 commit comments