@@ -52,10 +52,8 @@ struct AstValidator<'a> {
52
52
/// Are we inside a trait impl?
53
53
in_trait_impl : bool ,
54
54
55
- in_const_trait_impl : bool ,
56
-
57
- /// Are we inside a const trait defn?
58
- in_const_trait_defn : bool ,
55
+ /// Are we inside a const trait defn or impl?
56
+ in_const_trait : bool ,
59
57
60
58
has_proc_macro_decls : bool ,
61
59
@@ -82,16 +80,16 @@ impl<'a> AstValidator<'a> {
82
80
) {
83
81
let old = mem:: replace ( & mut self . in_trait_impl , is_in) ;
84
82
let old_const =
85
- mem:: replace ( & mut self . in_const_trait_impl , matches ! ( constness, Some ( Const :: Yes ( _) ) ) ) ;
83
+ mem:: replace ( & mut self . in_const_trait , matches ! ( constness, Some ( Const :: Yes ( _) ) ) ) ;
86
84
f ( self ) ;
87
85
self . in_trait_impl = old;
88
- self . in_const_trait_impl = old_const;
86
+ self . in_const_trait = old_const;
89
87
}
90
88
91
89
fn with_in_trait ( & mut self , is_const : bool , f : impl FnOnce ( & mut Self ) ) {
92
- let old = mem:: replace ( & mut self . in_const_trait_defn , is_const) ;
90
+ let old = mem:: replace ( & mut self . in_const_trait , is_const) ;
93
91
f ( self ) ;
94
- self . in_const_trait_defn = old;
92
+ self . in_const_trait = old;
95
93
}
96
94
97
95
fn with_banned_impl_trait ( & mut self , f : impl FnOnce ( & mut Self ) ) {
@@ -1289,16 +1287,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
1289
1287
}
1290
1288
1291
1289
let tilde_const_allowed =
1292
- if matches ! ( fk. header( ) , Some ( FnHeader { constness: ast:: Const :: Yes ( _) , .. } ) ) {
1293
- true
1294
- } else if let Some ( FnCtxt :: Assoc ( ctxt) ) = fk. ctxt ( ) {
1295
- match ctxt {
1296
- AssocCtxt :: Trait => self . in_const_trait_defn ,
1297
- AssocCtxt :: Impl => self . in_const_trait_impl ,
1298
- }
1299
- } else {
1300
- false
1301
- } ;
1290
+ matches ! ( fk. header( ) , Some ( FnHeader { constness: ast:: Const :: Yes ( _) , .. } ) )
1291
+ || ( matches ! ( fk. ctxt( ) , Some ( FnCtxt :: Assoc ( _) ) ) && self . in_const_trait ) ;
1302
1292
1303
1293
let disallowed = ( !tilde_const_allowed) . then ( || DisallowTildeConstContext :: Fn ( fk) ) ;
1304
1294
@@ -1383,7 +1373,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
1383
1373
walk_list ! ( self , visit_ty, ty) ;
1384
1374
}
1385
1375
AssocItemKind :: Fn ( box Fn { sig, generics, body, .. } )
1386
- if self . in_const_trait_impl
1376
+ if self . in_const_trait
1387
1377
|| ctxt == AssocCtxt :: Trait
1388
1378
|| matches ! ( sig. header. constness, Const :: Yes ( _) ) =>
1389
1379
{
@@ -1530,8 +1520,7 @@ pub fn check_crate(
1530
1520
features,
1531
1521
extern_mod : None ,
1532
1522
in_trait_impl : false ,
1533
- in_const_trait_impl : false ,
1534
- in_const_trait_defn : false ,
1523
+ in_const_trait : false ,
1535
1524
has_proc_macro_decls : false ,
1536
1525
outer_impl_trait : None ,
1537
1526
disallow_tilde_const : None ,
0 commit comments