@@ -5069,7 +5069,7 @@ impl<'a> Parser<'a> {
50695069 fn parse_enum_def ( & mut self , _generics : & ast:: Generics ) -> EnumDef {
50705070 let mut variants = Vec :: new ( ) ;
50715071 let mut all_nullary = true ;
5072- let mut have_disr = false ;
5072+ let mut any_disr = None ;
50735073 while self . token != token:: RBRACE {
50745074 let variant_attrs = self . parse_outer_attributes ( ) ;
50755075 let vlo = self . span . lo ;
@@ -5101,8 +5101,8 @@ impl<'a> Parser<'a> {
51015101 }
51025102 kind = TupleVariantKind ( args) ;
51035103 } else if self . eat ( & token:: EQ ) {
5104- have_disr = true ;
51055104 disr_expr = Some ( self . parse_expr ( ) ) ;
5105+ any_disr = disr_expr. as_ref ( ) . map ( |expr| expr. span ) ;
51065106 kind = TupleVariantKind ( args) ;
51075107 } else {
51085108 kind = TupleVariantKind ( Vec :: new ( ) ) ;
@@ -5121,9 +5121,11 @@ impl<'a> Parser<'a> {
51215121 if !self . eat ( & token:: COMMA ) { break ; }
51225122 }
51235123 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+ _ => ( )
51275129 }
51285130
51295131 ast:: EnumDef { variants : variants }
0 commit comments