@@ -111,7 +111,7 @@ crate enum RibKind<'a> {
111111 ItemRibKind ( HasGenericParams ) ,
112112
113113 /// We're in a constant item. Can't refer to dynamic stuff.
114- ConstantItemRibKind ,
114+ ConstantItemRibKind ( bool ) ,
115115
116116 /// We passed through a module.
117117 ModuleRibKind ( Module < ' a > ) ,
@@ -137,7 +137,7 @@ impl RibKind<'_> {
137137 NormalRibKind
138138 | ClosureOrAsyncRibKind
139139 | FnItemRibKind
140- | ConstantItemRibKind
140+ | ConstantItemRibKind ( _ )
141141 | ModuleRibKind ( _)
142142 | MacroDefinition ( _)
143143 | ConstParamTyRibKind => false ,
@@ -426,7 +426,7 @@ impl<'a, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
426426 }
427427 fn visit_anon_const ( & mut self , constant : & ' ast AnonConst ) {
428428 debug ! ( "visit_anon_const {:?}" , constant) ;
429- self . with_constant_rib ( |this| {
429+ self . with_constant_rib ( constant . value . is_potential_trivial_const_param ( ) , |this| {
430430 visit:: walk_anon_const ( this, constant) ;
431431 } ) ;
432432 }
@@ -628,7 +628,7 @@ impl<'a, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
628628 if !check_ns ( TypeNS ) && check_ns ( ValueNS ) {
629629 // This must be equivalent to `visit_anon_const`, but we cannot call it
630630 // 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| {
632632 this. smart_resolve_path (
633633 ty. id ,
634634 qself. as_ref ( ) ,
@@ -829,7 +829,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
829829 | ClosureOrAsyncRibKind
830830 | FnItemRibKind
831831 | ItemRibKind ( ..)
832- | ConstantItemRibKind
832+ | ConstantItemRibKind ( _ )
833833 | ModuleRibKind ( ..)
834834 | ForwardTyParamBanRibKind
835835 | ConstParamTyRibKind => {
@@ -948,7 +948,14 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
948948 // Only impose the restrictions of `ConstRibKind` for an
949949 // actual constant expression in a provided default.
950950 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+ } ) ;
952959 }
953960 }
954961 AssocItemKind :: Fn ( _, _, generics, _) => {
@@ -989,7 +996,9 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
989996 self . with_item_rib ( HasGenericParams :: No , |this| {
990997 this. visit_ty ( ty) ;
991998 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+ } ) ;
9931002 }
9941003 } ) ;
9951004 }
@@ -1086,11 +1095,11 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
10861095 self . with_rib ( ValueNS , kind, |this| this. with_rib ( TypeNS , kind, f) )
10871096 }
10881097
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 ) ) {
10901099 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) ;
10941103 } )
10951104 } ) ;
10961105 }
@@ -1220,7 +1229,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
12201229 for item in impl_items {
12211230 use crate :: ResolutionError :: * ;
12221231 match & item. kind {
1223- AssocItemKind :: Const ( .. ) => {
1232+ AssocItemKind :: Const ( _default , _ty , _expr ) => {
12241233 debug ! ( "resolve_implementation AssocItemKind::Const" , ) ;
12251234 // If this is a trait impl, ensure the const
12261235 // exists in trait
@@ -1231,7 +1240,12 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
12311240 |n, s| ConstNotMemberOfTrait ( n, s) ,
12321241 ) ;
12331242
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| {
12351249 visit:: walk_assoc_item ( this, item, AssocCtxt :: Impl )
12361250 } ) ;
12371251 }
0 commit comments