@@ -92,6 +92,12 @@ crate enum HasGenericParams {
92
92
No ,
93
93
}
94
94
95
+ #[ derive( Copy , Clone , Debug , Eq , PartialEq ) ]
96
+ crate enum ConstantItemKind {
97
+ Const ,
98
+ Static ,
99
+ }
100
+
95
101
/// The rib kind restricts certain accesses,
96
102
/// e.g. to a `Res::Local` of an outer item.
97
103
#[ derive( Copy , Clone , Debug ) ]
@@ -119,7 +125,7 @@ crate enum RibKind<'a> {
119
125
///
120
126
/// The `bool` indicates if this constant may reference generic parameters
121
127
/// and is used to only allow generic parameters to be used in trivial constant expressions.
122
- ConstantItemRibKind ( bool ) ,
128
+ ConstantItemRibKind ( bool , Option < ( Ident , ConstantItemKind ) > ) ,
123
129
124
130
/// We passed through a module.
125
131
ModuleRibKind ( Module < ' a > ) ,
@@ -145,7 +151,7 @@ impl RibKind<'_> {
145
151
NormalRibKind
146
152
| ClosureOrAsyncRibKind
147
153
| FnItemRibKind
148
- | ConstantItemRibKind ( _ )
154
+ | ConstantItemRibKind ( .. )
149
155
| ModuleRibKind ( _)
150
156
| MacroDefinition ( _)
151
157
| ConstParamTyRibKind => false ,
@@ -634,7 +640,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
634
640
// Note that we might not be inside of an repeat expression here,
635
641
// but considering that `IsRepeatExpr` is only relevant for
636
642
// non-trivial constants this is doesn't matter.
637
- self . with_constant_rib ( IsRepeatExpr :: No , true , |this| {
643
+ self . with_constant_rib ( IsRepeatExpr :: No , true , None , |this| {
638
644
this. smart_resolve_path (
639
645
ty. id ,
640
646
qself. as_ref ( ) ,
@@ -843,7 +849,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
843
849
| ClosureOrAsyncRibKind
844
850
| FnItemRibKind
845
851
| ItemRibKind ( ..)
846
- | ConstantItemRibKind ( _ )
852
+ | ConstantItemRibKind ( .. )
847
853
| ModuleRibKind ( ..)
848
854
| ForwardTyParamBanRibKind
849
855
| ConstParamTyRibKind => {
@@ -970,6 +976,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
970
976
this. with_constant_rib (
971
977
IsRepeatExpr :: No ,
972
978
true ,
979
+ None ,
973
980
|this| this. visit_expr ( expr) ,
974
981
) ;
975
982
}
@@ -1012,11 +1019,19 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1012
1019
self . with_item_rib ( HasGenericParams :: No , |this| {
1013
1020
this. visit_ty ( ty) ;
1014
1021
if let Some ( expr) = expr {
1022
+ let constant_item_kind = match item. kind {
1023
+ ItemKind :: Const ( ..) => ConstantItemKind :: Const ,
1024
+ ItemKind :: Static ( ..) => ConstantItemKind :: Static ,
1025
+ _ => unreachable ! ( ) ,
1026
+ } ;
1015
1027
// We already forbid generic params because of the above item rib,
1016
1028
// so it doesn't matter whether this is a trivial constant.
1017
- this. with_constant_rib ( IsRepeatExpr :: No , true , |this| {
1018
- this. visit_expr ( expr)
1019
- } ) ;
1029
+ this. with_constant_rib (
1030
+ IsRepeatExpr :: No ,
1031
+ true ,
1032
+ Some ( ( item. ident , constant_item_kind) ) ,
1033
+ |this| this. visit_expr ( expr) ,
1034
+ ) ;
1020
1035
}
1021
1036
} ) ;
1022
1037
}
@@ -1118,15 +1133,16 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1118
1133
& mut self ,
1119
1134
is_repeat : IsRepeatExpr ,
1120
1135
is_trivial : bool ,
1136
+ item : Option < ( Ident , ConstantItemKind ) > ,
1121
1137
f : impl FnOnce ( & mut Self ) ,
1122
1138
) {
1123
1139
debug ! ( "with_constant_rib: is_repeat={:?} is_trivial={}" , is_repeat, is_trivial) ;
1124
- self . with_rib ( ValueNS , ConstantItemRibKind ( is_trivial) , |this| {
1140
+ self . with_rib ( ValueNS , ConstantItemRibKind ( is_trivial, item ) , |this| {
1125
1141
this. with_rib (
1126
1142
TypeNS ,
1127
- ConstantItemRibKind ( is_repeat == IsRepeatExpr :: Yes || is_trivial) ,
1143
+ ConstantItemRibKind ( is_repeat == IsRepeatExpr :: Yes || is_trivial, item ) ,
1128
1144
|this| {
1129
- this. with_label_rib ( ConstantItemRibKind ( is_trivial) , f) ;
1145
+ this. with_label_rib ( ConstantItemRibKind ( is_trivial, item ) , f) ;
1130
1146
} ,
1131
1147
)
1132
1148
} ) ;
@@ -1266,6 +1282,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1266
1282
this. with_constant_rib (
1267
1283
IsRepeatExpr :: No ,
1268
1284
true ,
1285
+ None ,
1269
1286
|this| {
1270
1287
visit:: walk_assoc_item (
1271
1288
this,
@@ -2200,6 +2217,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
2200
2217
self . with_constant_rib (
2201
2218
is_repeat,
2202
2219
constant. value . is_potential_trivial_const_param ( ) ,
2220
+ None ,
2203
2221
|this| {
2204
2222
visit:: walk_anon_const ( this, constant) ;
2205
2223
} ,
0 commit comments