@@ -37,12 +37,17 @@ enum SelfSemantic {
37
37
}
38
38
39
39
/// 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.
40
42
enum DisallowTildeConstContext < ' a > {
41
43
TraitObject ,
42
44
Fn ( FnKind < ' a > ) ,
43
45
Trait ( Span ) ,
44
46
TraitImpl ( Span ) ,
45
47
Impl ( Span ) ,
48
+ TraitAssocTy ( Span ) ,
49
+ TraitImplAssocTy ( Span ) ,
50
+ InherentAssocTy ( Span ) ,
46
51
Item ,
47
52
}
48
53
@@ -316,6 +321,7 @@ impl<'a> AstValidator<'a> {
316
321
constness : Const :: No ,
317
322
polarity : ImplPolarity :: Positive ,
318
323
trait_ref,
324
+ ..
319
325
} = parent
320
326
{
321
327
Some ( trait_ref. path . span . shrink_to_lo ( ) )
@@ -1286,6 +1292,15 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
1286
1292
// suggestion for moving such bounds to the assoc const fns if available.
1287
1293
errors:: TildeConstReason :: Impl { span }
1288
1294
}
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
+ }
1289
1304
DisallowTildeConstContext :: TraitObject => {
1290
1305
errors:: TildeConstReason :: TraitObject
1291
1306
}
@@ -1483,13 +1498,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
1483
1498
self . check_item_named ( item. ident , "const" ) ;
1484
1499
}
1485
1500
1501
+ let parent_is_const =
1502
+ self . outer_trait_or_trait_impl . as_ref ( ) . and_then ( TraitOrTraitImpl :: constness) . is_some ( ) ;
1503
+
1486
1504
match & item. kind {
1487
1505
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
1493
1507
|| ctxt == AssocCtxt :: Trait
1494
1508
|| matches ! ( sig. header. constness, Const :: Yes ( _) ) =>
1495
1509
{
@@ -1505,6 +1519,20 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
1505
1519
) ;
1506
1520
self . visit_fn ( kind, item. span , item. id ) ;
1507
1521
}
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
+ }
1508
1536
_ => self . with_in_trait_impl ( None , |this| visit:: walk_assoc_item ( this, item, ctxt) ) ,
1509
1537
}
1510
1538
}
0 commit comments