@@ -37,12 +37,17 @@ enum SelfSemantic {
3737} 
3838
3939/// What is the context that prevents using `~const`? 
40+ // FIXME(effects): Consider getting rid of this in favor of `errors::TildeConstReason`, they're 
41+ // almost identical. This gets rid of an abstraction layer which might be considered bad. 
4042enum  DisallowTildeConstContext < ' a >  { 
4143 TraitObject , 
4244 Fn ( FnKind < ' a > ) , 
4345 Trait ( Span ) , 
4446 TraitImpl ( Span ) , 
4547 Impl ( Span ) , 
48+  TraitAssocTy ( Span ) , 
49+  TraitImplAssocTy ( Span ) , 
50+  InherentAssocTy ( Span ) , 
4651 Item , 
4752} 
4853
@@ -316,6 +321,7 @@ impl<'a> AstValidator<'a> {
316321 constness :  Const :: No , 
317322 polarity :  ImplPolarity :: Positive , 
318323 trait_ref, 
324+  ..
319325 }  = parent
320326 { 
321327 Some ( trait_ref. path . span . shrink_to_lo ( ) ) 
@@ -1286,6 +1292,15 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12861292 // suggestion for moving such bounds to the assoc const fns if available. 
12871293 errors:: TildeConstReason :: Impl  {  span } 
12881294 } 
1295+  & DisallowTildeConstContext :: TraitAssocTy ( span)  => { 
1296+  errors:: TildeConstReason :: TraitAssocTy  {  span } 
1297+  } 
1298+  & DisallowTildeConstContext :: TraitImplAssocTy ( span)  => { 
1299+  errors:: TildeConstReason :: TraitImplAssocTy  {  span } 
1300+  } 
1301+  & DisallowTildeConstContext :: InherentAssocTy ( span)  => { 
1302+  errors:: TildeConstReason :: InherentAssocTy  {  span } 
1303+  } 
12891304 DisallowTildeConstContext :: TraitObject  => { 
12901305 errors:: TildeConstReason :: TraitObject 
12911306 } 
@@ -1483,13 +1498,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
14831498 self . check_item_named ( item. ident ,  "const" ) ; 
14841499 } 
14851500
1501+  let  parent_is_const =
1502+  self . outer_trait_or_trait_impl . as_ref ( ) . and_then ( TraitOrTraitImpl :: constness) . is_some ( ) ; 
1503+ 
14861504 match  & item. kind  { 
14871505 AssocItemKind :: Fn ( box  Fn  {  sig,  generics,  body,  .. } ) 
1488-  if  self 
1489-  . outer_trait_or_trait_impl 
1490-  . as_ref ( ) 
1491-  . and_then ( TraitOrTraitImpl :: constness) 
1492-  . is_some ( ) 
1506+  if  parent_is_const
14931507 || ctxt == AssocCtxt :: Trait 
14941508 || matches ! ( sig. header. constness,  Const :: Yes ( _) )  =>
14951509 { 
@@ -1505,6 +1519,20 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
15051519 ) ; 
15061520 self . visit_fn ( kind,  item. span ,  item. id ) ; 
15071521 } 
1522+  AssocItemKind :: Type ( _)  => { 
1523+  let  disallowed = ( !parent_is_const) . then ( || match  self . outer_trait_or_trait_impl  { 
1524+  Some ( TraitOrTraitImpl :: Trait  {  .. } )  => { 
1525+  DisallowTildeConstContext :: TraitAssocTy ( item. span ) 
1526+  } 
1527+  Some ( TraitOrTraitImpl :: TraitImpl  {  .. } )  => { 
1528+  DisallowTildeConstContext :: TraitImplAssocTy ( item. span ) 
1529+  } 
1530+  None  => DisallowTildeConstContext :: InherentAssocTy ( item. span ) , 
1531+  } ) ; 
1532+  self . with_tilde_const ( disallowed,  |this| { 
1533+  this. with_in_trait_impl ( None ,  |this| visit:: walk_assoc_item ( this,  item,  ctxt) ) 
1534+  } ) 
1535+  } 
15081536 _ => self . with_in_trait_impl ( None ,  |this| visit:: walk_assoc_item ( this,  item,  ctxt) ) , 
15091537 } 
15101538 } 
0 commit comments