@@ -111,7 +111,7 @@ crate enum RibKind<'a> {
111
111
ItemRibKind ( HasGenericParams ) ,
112
112
113
113
/// We're in a constant item. Can't refer to dynamic stuff.
114
- ConstantItemRibKind ,
114
+ ConstantItemRibKind ( bool ) ,
115
115
116
116
/// We passed through a module.
117
117
ModuleRibKind ( Module < ' a > ) ,
@@ -137,7 +137,7 @@ impl RibKind<'_> {
137
137
NormalRibKind
138
138
| ClosureOrAsyncRibKind
139
139
| FnItemRibKind
140
- | ConstantItemRibKind
140
+ | ConstantItemRibKind ( _ )
141
141
| ModuleRibKind ( _)
142
142
| MacroDefinition ( _)
143
143
| ConstParamTyRibKind => false ,
@@ -426,7 +426,7 @@ impl<'a, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
426
426
}
427
427
fn visit_anon_const ( & mut self , constant : & ' ast AnonConst ) {
428
428
debug ! ( "visit_anon_const {:?}" , constant) ;
429
- self . with_constant_rib ( |this| {
429
+ self . with_constant_rib ( constant . value . is_potential_trivial_const_param ( ) , |this| {
430
430
visit:: walk_anon_const ( this, constant) ;
431
431
} ) ;
432
432
}
@@ -628,7 +628,7 @@ impl<'a, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
628
628
if !check_ns ( TypeNS ) && check_ns ( ValueNS ) {
629
629
// This must be equivalent to `visit_anon_const`, but we cannot call it
630
630
// directly due to visitor lifetimes so we have to copy-paste some code.
631
- self . with_constant_rib ( |this| {
631
+ self . with_constant_rib ( true , |this| {
632
632
this. smart_resolve_path (
633
633
ty. id ,
634
634
qself. as_ref ( ) ,
@@ -829,7 +829,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
829
829
| ClosureOrAsyncRibKind
830
830
| FnItemRibKind
831
831
| ItemRibKind ( ..)
832
- | ConstantItemRibKind
832
+ | ConstantItemRibKind ( _ )
833
833
| ModuleRibKind ( ..)
834
834
| ForwardTyParamBanRibKind
835
835
| ConstParamTyRibKind => {
@@ -948,7 +948,14 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
948
948
// Only impose the restrictions of `ConstRibKind` for an
949
949
// actual constant expression in a provided default.
950
950
if let Some ( expr) = default {
951
- this. with_constant_rib ( |this| this. visit_expr ( expr) ) ;
951
+ // We allow arbitrary const expressions inside of associated consts,
952
+ // even if they are potentially not const evaluatable.
953
+ //
954
+ // Type parameters can already be used and as associated consts are
955
+ // not used as part of the type system, this is far less surprising.
956
+ this. with_constant_rib ( true , |this| {
957
+ this. visit_expr ( expr)
958
+ } ) ;
952
959
}
953
960
}
954
961
AssocItemKind :: Fn ( _, _, generics, _) => {
@@ -989,7 +996,9 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
989
996
self . with_item_rib ( HasGenericParams :: No , |this| {
990
997
this. visit_ty ( ty) ;
991
998
if let Some ( expr) = expr {
992
- this. with_constant_rib ( |this| this. visit_expr ( expr) ) ;
999
+ this. with_constant_rib ( expr. is_potential_trivial_const_param ( ) , |this| {
1000
+ this. visit_expr ( expr)
1001
+ } ) ;
993
1002
}
994
1003
} ) ;
995
1004
}
@@ -1086,11 +1095,11 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1086
1095
self . with_rib ( ValueNS , kind, |this| this. with_rib ( TypeNS , kind, f) )
1087
1096
}
1088
1097
1089
- fn with_constant_rib ( & mut self , f : impl FnOnce ( & mut Self ) ) {
1098
+ fn with_constant_rib ( & mut self , trivial : bool , f : impl FnOnce ( & mut Self ) ) {
1090
1099
debug ! ( "with_constant_rib" ) ;
1091
- self . with_rib ( ValueNS , ConstantItemRibKind , |this| {
1092
- this. with_rib ( TypeNS , ConstantItemRibKind , |this| {
1093
- this. with_label_rib ( ConstantItemRibKind , f) ;
1100
+ self . with_rib ( ValueNS , ConstantItemRibKind ( trivial ) , |this| {
1101
+ this. with_rib ( TypeNS , ConstantItemRibKind ( trivial ) , |this| {
1102
+ this. with_label_rib ( ConstantItemRibKind ( trivial ) , f) ;
1094
1103
} )
1095
1104
} ) ;
1096
1105
}
@@ -1220,7 +1229,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1220
1229
for item in impl_items {
1221
1230
use crate :: ResolutionError :: * ;
1222
1231
match & item. kind {
1223
- AssocItemKind :: Const ( .. ) => {
1232
+ AssocItemKind :: Const ( _default , _ty , _expr ) => {
1224
1233
debug ! ( "resolve_implementation AssocItemKind::Const" , ) ;
1225
1234
// If this is a trait impl, ensure the const
1226
1235
// exists in trait
@@ -1231,7 +1240,12 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1231
1240
|n, s| ConstNotMemberOfTrait ( n, s) ,
1232
1241
) ;
1233
1242
1234
- this. with_constant_rib ( |this| {
1243
+ // We allow arbitrary const expressions inside of associated consts,
1244
+ // even if they are potentially not const evaluatable.
1245
+ //
1246
+ // Type parameters can already be used and as associated consts are
1247
+ // not used as part of the type system, this is far less surprising.
1248
+ this. with_constant_rib ( true , |this| {
1235
1249
visit:: walk_assoc_item ( this, item, AssocCtxt :: Impl )
1236
1250
} ) ;
1237
1251
}
0 commit comments