@@ -66,7 +66,7 @@ pub(crate) enum PatternSource {
66
66
}
67
67
68
68
#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
69
- enum IsRepeatExpr {
69
+ pub ( crate ) enum IsRepeatExpr {
70
70
No ,
71
71
Yes ,
72
72
}
@@ -76,13 +76,28 @@ struct IsNeverPattern;
76
76
/// Describes whether an `AnonConst` is a type level const arg or
77
77
/// some other form of anon const (i.e. inline consts or enum discriminants)
78
78
#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
79
- enum AnonConstKind {
79
+ pub ( crate ) enum AnonConstKind {
80
80
EnumDiscriminant ,
81
81
FieldDefaultValue ,
82
82
InlineConst ,
83
83
ConstArg ( IsRepeatExpr ) ,
84
84
}
85
85
86
+ impl IntoDiagArg for AnonConstKind {
87
+ fn into_diag_arg ( self , _: & mut Option < std:: path:: PathBuf > ) -> DiagArgValue {
88
+ DiagArgValue :: Str ( Cow :: Borrowed ( match self {
89
+ AnonConstKind :: EnumDiscriminant => "enum discriminant" ,
90
+ AnonConstKind :: FieldDefaultValue => "field default value" ,
91
+ AnonConstKind :: InlineConst => "inline const" ,
92
+ AnonConstKind :: ConstArg ( is_repeat_expr) => match is_repeat_expr {
93
+ IsRepeatExpr :: No => "array repeat expression" ,
94
+ IsRepeatExpr :: Yes => "const generic args" ,
95
+ }
96
+ } ,
97
+ ) )
98
+ }
99
+ }
100
+
86
101
impl PatternSource {
87
102
fn descr ( self ) -> & ' static str {
88
103
match self {
@@ -209,7 +224,7 @@ pub(crate) enum RibKind<'ra> {
209
224
///
210
225
/// The item may reference generic parameters in trivial constant expressions.
211
226
/// All other constants aren't allowed to use generic params at all.
212
- ConstantItem ( ConstantHasGenerics , Option < ( Ident , ConstantItemKind ) > ) ,
227
+ ConstantItem ( ConstantHasGenerics , Option < ( Ident , ConstantItemKind ) > , Option < AnonConstKind > ) ,
213
228
214
229
/// We passed through a module.
215
230
Module ( Module < ' ra > ) ,
@@ -3017,19 +3032,21 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3017
3032
& mut self ,
3018
3033
is_repeat : IsRepeatExpr ,
3019
3034
may_use_generics : ConstantHasGenerics ,
3035
+ anon_const_kind : Option < AnonConstKind > ,
3020
3036
item : Option < ( Ident , ConstantItemKind ) > ,
3021
3037
f : impl FnOnce ( & mut Self ) ,
3022
3038
) {
3023
3039
let f = |this : & mut Self | {
3024
- this. with_rib ( ValueNS , RibKind :: ConstantItem ( may_use_generics, item) , |this| {
3040
+ this. with_rib ( ValueNS , RibKind :: ConstantItem ( may_use_generics, item, anon_const_kind ) , |this| {
3025
3041
this. with_rib (
3026
3042
TypeNS ,
3027
3043
RibKind :: ConstantItem (
3028
3044
may_use_generics. force_yes_if ( is_repeat == IsRepeatExpr :: Yes ) ,
3029
3045
item,
3046
+ anon_const_kind,
3030
3047
) ,
3031
3048
|this| {
3032
- this. with_label_rib ( RibKind :: ConstantItem ( may_use_generics, item) , f) ;
3049
+ this. with_label_rib ( RibKind :: ConstantItem ( may_use_generics, item, anon_const_kind ) , f) ;
3033
3050
} ,
3034
3051
)
3035
3052
} )
@@ -3548,7 +3565,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
3548
3565
3549
3566
fn resolve_const_body ( & mut self , expr : & ' ast Expr , item : Option < ( Ident , ConstantItemKind ) > ) {
3550
3567
self . with_lifetime_rib ( LifetimeRibKind :: Elided ( LifetimeRes :: Infer ) , |this| {
3551
- this. with_constant_rib ( IsRepeatExpr :: No , ConstantHasGenerics :: Yes , item, |this| {
3568
+ this. with_constant_rib ( IsRepeatExpr :: No , ConstantHasGenerics :: Yes , None , item, |this| {
3552
3569
this. visit_expr ( expr)
3553
3570
} ) ;
3554
3571
} )
@@ -4757,7 +4774,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
4757
4774
}
4758
4775
} ;
4759
4776
4760
- self . with_constant_rib ( is_repeat_expr, may_use_generics, None , |this| {
4777
+ self . with_constant_rib ( is_repeat_expr, may_use_generics, Some ( anon_const_kind ) , None , |this| {
4761
4778
this. with_lifetime_rib ( LifetimeRibKind :: Elided ( LifetimeRes :: Infer ) , |this| {
4762
4779
resolve_expr ( this) ;
4763
4780
} ) ;
0 commit comments