@@ -57,6 +57,12 @@ enum PatternSource {
5757 FnParam ,
5858}
5959
60+ #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
61+ enum IsRepeatExpr {
62+ No ,
63+ Yes ,
64+ }
65+
6066impl PatternSource {
6167 fn descr ( self ) -> & ' static str {
6268 match self {
@@ -437,10 +443,8 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
437443 self . resolve_block ( block) ;
438444 }
439445 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 ) ;
444448 }
445449 fn visit_expr ( & mut self , expr : & ' ast Expr ) {
446450 self . resolve_expr ( expr, None ) ;
@@ -647,7 +651,11 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
647651 if !check_ns ( TypeNS ) && check_ns ( ValueNS ) {
648652 // This must be equivalent to `visit_anon_const`, but we cannot call it
649653 // 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| {
651659 this. smart_resolve_path (
652660 ty. id ,
653661 qself. as_ref ( ) ,
@@ -980,9 +988,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
980988 //
981989 // Type parameters can already be used and as associated consts are
982990 // 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+ ) ;
986996 }
987997 }
988998 AssocItemKind :: Fn ( _, _, generics, _) => {
@@ -1023,7 +1033,9 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
10231033 self . with_item_rib ( HasGenericParams :: No , |this| {
10241034 this. visit_ty ( ty) ;
10251035 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| {
10271039 this. visit_expr ( expr)
10281040 } ) ;
10291041 }
@@ -1122,12 +1134,29 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
11221134 self . with_rib ( ValueNS , kind, |this| this. with_rib ( TypeNS , kind, f) )
11231135 }
11241136
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+ )
11311160 } ) ;
11321161 }
11331162
@@ -1272,9 +1301,17 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
12721301 //
12731302 // Type parameters can already be used and as associated consts are
12741303 // 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+ ) ;
12781315 }
12791316 AssocItemKind :: Fn ( _, _, generics, _) => {
12801317 // 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> {
21992236 debug ! ( "(resolving block) leaving block" ) ;
22002237 }
22012238
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+
22022250 fn resolve_expr ( & mut self , expr : & ' ast Expr , parent : Option < & ' ast Expr > ) {
22032251 // First, record candidate traits for this expression if it could
22042252 // result in the invocation of a method call.
@@ -2322,6 +2370,10 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
23222370 ExprKind :: Async ( ..) | ExprKind :: Closure ( ..) => {
23232371 self . with_label_rib ( ClosureOrAsyncRibKind , |this| visit:: walk_expr ( this, expr) ) ;
23242372 }
2373+ ExprKind :: Repeat ( ref elem, ref ct) => {
2374+ self . visit_expr ( elem) ;
2375+ self . resolve_anon_const ( ct, IsRepeatExpr :: Yes ) ;
2376+ }
23252377 _ => {
23262378 visit:: walk_expr ( self , expr) ;
23272379 }
0 commit comments