@@ -57,6 +57,12 @@ enum PatternSource {
57
57
FnParam ,
58
58
}
59
59
60
+ #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
61
+ enum IsRepeatExpr {
62
+ No ,
63
+ Yes ,
64
+ }
65
+
60
66
impl PatternSource {
61
67
fn descr ( self ) -> & ' static str {
62
68
match self {
@@ -437,10 +443,8 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
437
443
self . resolve_block ( block) ;
438
444
}
439
445
fn visit_anon_const ( & mut self , constant : & ' ast AnonConst ) {
440
- debug ! ( "visit_anon_const {:?}" , constant) ;
441
- self . with_constant_rib ( constant. value . is_potential_trivial_const_param ( ) , |this| {
442
- visit:: walk_anon_const ( this, constant) ;
443
- } ) ;
446
+ // We deal with repeat expressions explicitly in `resolve_expr`.
447
+ self . resolve_anon_const ( constant, IsRepeatExpr :: No ) ;
444
448
}
445
449
fn visit_expr ( & mut self , expr : & ' ast Expr ) {
446
450
self . resolve_expr ( expr, None ) ;
@@ -647,7 +651,11 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
647
651
if !check_ns ( TypeNS ) && check_ns ( ValueNS ) {
648
652
// This must be equivalent to `visit_anon_const`, but we cannot call it
649
653
// directly due to visitor lifetimes so we have to copy-paste some code.
650
- self . with_constant_rib ( true , |this| {
654
+ //
655
+ // Note that we might not be inside of an repeat expression here,
656
+ // but considering that `IsRepeatExpr` is only relevant for
657
+ // non-trivial constants this is doesn't matter.
658
+ self . with_constant_rib ( IsRepeatExpr :: No , true , |this| {
651
659
this. smart_resolve_path (
652
660
ty. id ,
653
661
qself. as_ref ( ) ,
@@ -980,9 +988,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
980
988
//
981
989
// Type parameters can already be used and as associated consts are
982
990
// not used as part of the type system, this is far less surprising.
983
- this. with_constant_rib ( true , |this| {
984
- this. visit_expr ( expr)
985
- } ) ;
991
+ this. with_constant_rib (
992
+ IsRepeatExpr :: No ,
993
+ true ,
994
+ |this| this. visit_expr ( expr) ,
995
+ ) ;
986
996
}
987
997
}
988
998
AssocItemKind :: Fn ( _, _, generics, _) => {
@@ -1023,7 +1033,9 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1023
1033
self . with_item_rib ( HasGenericParams :: No , |this| {
1024
1034
this. visit_ty ( ty) ;
1025
1035
if let Some ( expr) = expr {
1026
- this. with_constant_rib ( expr. is_potential_trivial_const_param ( ) , |this| {
1036
+ // We already forbid generic params because of the above item rib,
1037
+ // so it doesn't matter whether this is a trivial constant.
1038
+ this. with_constant_rib ( IsRepeatExpr :: No , true , |this| {
1027
1039
this. visit_expr ( expr)
1028
1040
} ) ;
1029
1041
}
@@ -1122,12 +1134,29 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1122
1134
self . with_rib ( ValueNS , kind, |this| this. with_rib ( TypeNS , kind, f) )
1123
1135
}
1124
1136
1125
- fn with_constant_rib ( & mut self , trivial : bool , f : impl FnOnce ( & mut Self ) ) {
1126
- debug ! ( "with_constant_rib" ) ;
1127
- self . with_rib ( ValueNS , ConstantItemRibKind ( trivial) , |this| {
1128
- this. with_rib ( TypeNS , ConstantItemRibKind ( trivial) , |this| {
1129
- this. with_label_rib ( ConstantItemRibKind ( trivial) , f) ;
1130
- } )
1137
+ // HACK(min_const_generics,const_evaluatable_unchecked): We
1138
+ // want to keep allowing `[0; std::mem::size_of::<*mut T>()]`
1139
+ // with a future compat lint for now. We do this by adding an
1140
+ // additional special case for repeat expressions.
1141
+ //
1142
+ // Note that we intentionally still forbid `[0; N + 1]` during
1143
+ // name resolution so that we don't extend the future
1144
+ // compat lint to new cases.
1145
+ fn with_constant_rib (
1146
+ & mut self ,
1147
+ is_repeat : IsRepeatExpr ,
1148
+ is_trivial : bool ,
1149
+ f : impl FnOnce ( & mut Self ) ,
1150
+ ) {
1151
+ debug ! ( "with_constant_rib: is_repeat={:?} is_trivial={}" , is_repeat, is_trivial) ;
1152
+ self . with_rib ( ValueNS , ConstantItemRibKind ( is_trivial) , |this| {
1153
+ this. with_rib (
1154
+ TypeNS ,
1155
+ ConstantItemRibKind ( is_repeat == IsRepeatExpr :: Yes || is_trivial) ,
1156
+ |this| {
1157
+ this. with_label_rib ( ConstantItemRibKind ( is_trivial) , f) ;
1158
+ } ,
1159
+ )
1131
1160
} ) ;
1132
1161
}
1133
1162
@@ -1272,9 +1301,17 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1272
1301
//
1273
1302
// Type parameters can already be used and as associated consts are
1274
1303
// not used as part of the type system, this is far less surprising.
1275
- this. with_constant_rib ( true , |this| {
1276
- visit:: walk_assoc_item ( this, item, AssocCtxt :: Impl )
1277
- } ) ;
1304
+ this. with_constant_rib (
1305
+ IsRepeatExpr :: No ,
1306
+ true ,
1307
+ |this| {
1308
+ visit:: walk_assoc_item (
1309
+ this,
1310
+ item,
1311
+ AssocCtxt :: Impl ,
1312
+ )
1313
+ } ,
1314
+ ) ;
1278
1315
}
1279
1316
AssocItemKind :: Fn ( _, _, generics, _) => {
1280
1317
// We also need a new scope for the impl item type parameters.
@@ -2199,6 +2236,17 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
2199
2236
debug ! ( "(resolving block) leaving block" ) ;
2200
2237
}
2201
2238
2239
+ fn resolve_anon_const ( & mut self , constant : & ' ast AnonConst , is_repeat : IsRepeatExpr ) {
2240
+ debug ! ( "resolve_anon_const {:?} is_repeat: {:?}" , constant, is_repeat) ;
2241
+ self . with_constant_rib (
2242
+ is_repeat,
2243
+ constant. value . is_potential_trivial_const_param ( ) ,
2244
+ |this| {
2245
+ visit:: walk_anon_const ( this, constant) ;
2246
+ } ,
2247
+ ) ;
2248
+ }
2249
+
2202
2250
fn resolve_expr ( & mut self , expr : & ' ast Expr , parent : Option < & ' ast Expr > ) {
2203
2251
// First, record candidate traits for this expression if it could
2204
2252
// result in the invocation of a method call.
@@ -2322,6 +2370,10 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
2322
2370
ExprKind :: Async ( ..) | ExprKind :: Closure ( ..) => {
2323
2371
self . with_label_rib ( ClosureOrAsyncRibKind , |this| visit:: walk_expr ( this, expr) ) ;
2324
2372
}
2373
+ ExprKind :: Repeat ( ref elem, ref ct) => {
2374
+ self . visit_expr ( elem) ;
2375
+ self . resolve_anon_const ( ct, IsRepeatExpr :: Yes ) ;
2376
+ }
2325
2377
_ => {
2326
2378
visit:: walk_expr ( self , expr) ;
2327
2379
}
0 commit comments