@@ -25,13 +25,14 @@ use crate::source_map::Spanned;
25
25
use crate :: edition:: { ALL_EDITIONS , Edition } ;
26
26
use crate :: visit:: { self , FnKind , Visitor } ;
27
27
use crate :: parse:: { token, ParseSess } ;
28
+ use crate :: parse:: parser:: Parser ;
28
29
use crate :: symbol:: { Symbol , sym} ;
29
30
use crate :: tokenstream:: TokenTree ;
30
31
31
32
use errors:: { Applicability , DiagnosticBuilder , Handler } ;
32
33
use rustc_data_structures:: fx:: FxHashMap ;
33
34
use rustc_target:: spec:: abi:: Abi ;
34
- use syntax_pos:: { Span , DUMMY_SP } ;
35
+ use syntax_pos:: { Span , DUMMY_SP , MultiSpan } ;
35
36
use log:: debug;
36
37
use lazy_static:: lazy_static;
37
38
@@ -569,6 +570,9 @@ declare_features! (
569
570
// #[repr(transparent)] on unions.
570
571
( active, transparent_unions, "1.37.0" , Some ( 60405 ) , None ) ,
571
572
573
+ // Allows explicit discriminants on non-unit enum variants.
574
+ ( active, arbitrary_enum_discriminant, "1.37.0" , Some ( 60553 ) , None ) ,
575
+
572
576
// -------------------------------------------------------------------------
573
577
// feature-group-end: actual feature gates
574
578
// -------------------------------------------------------------------------
@@ -1709,20 +1713,20 @@ pub fn emit_feature_err(
1709
1713
feature_err ( sess, feature, span, issue, explain) . emit ( ) ;
1710
1714
}
1711
1715
1712
- pub fn feature_err < ' a > (
1716
+ pub fn feature_err < ' a , S : Into < MultiSpan > > (
1713
1717
sess : & ' a ParseSess ,
1714
1718
feature : Symbol ,
1715
- span : Span ,
1719
+ span : S ,
1716
1720
issue : GateIssue ,
1717
1721
explain : & str ,
1718
1722
) -> DiagnosticBuilder < ' a > {
1719
1723
leveled_feature_err ( sess, feature, span, issue, explain, GateStrength :: Hard )
1720
1724
}
1721
1725
1722
- fn leveled_feature_err < ' a > (
1726
+ fn leveled_feature_err < ' a , S : Into < MultiSpan > > (
1723
1727
sess : & ' a ParseSess ,
1724
1728
feature : Symbol ,
1725
- span : Span ,
1729
+ span : S ,
1726
1730
issue : GateIssue ,
1727
1731
explain : & str ,
1728
1732
level : GateStrength ,
@@ -2037,6 +2041,29 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
2037
2041
}
2038
2042
}
2039
2043
2044
+ ast:: ItemKind :: Enum ( ast:: EnumDef { ref variants, ..} , ..) => {
2045
+ for variant in variants {
2046
+ match ( & variant. node . data , & variant. node . disr_expr ) {
2047
+ ( ast:: VariantData :: Unit ( ..) , _) => { } ,
2048
+ ( _, Some ( disr_expr) ) =>
2049
+ gate_feature_post ! (
2050
+ & self ,
2051
+ arbitrary_enum_discriminant,
2052
+ disr_expr. value. span,
2053
+ "discriminants on non-unit variants are experimental" ) ,
2054
+ _ => { } ,
2055
+ }
2056
+ }
2057
+
2058
+ let has_feature = self . context . features . arbitrary_enum_discriminant ;
2059
+ if !has_feature && !i. span . allows_unstable ( sym:: arbitrary_enum_discriminant) {
2060
+ Parser :: maybe_report_invalid_custom_discriminants (
2061
+ self . context . parse_sess ,
2062
+ & variants,
2063
+ ) ;
2064
+ }
2065
+ }
2066
+
2040
2067
ast:: ItemKind :: Impl ( _, polarity, defaultness, _, _, _, _) => {
2041
2068
if polarity == ast:: ImplPolarity :: Negative {
2042
2069
gate_feature_post ! ( & self , optin_builtin_traits,
0 commit comments