@@ -1287,13 +1287,45 @@ impl_ast_arena! {
12871287 Metadata => metadata,
12881288}
12891289
1290+ #[ doc( hidden) ]
1291+ #[ derive( Default ) ]
1292+ pub struct InvariantLifetime < ' a > ( std:: marker:: PhantomData < fn ( & ' a ( ) ) -> & ' a ( ) > ) ;
1293+
1294+ // Copied from the compact_arena crate
1295+ #[ macro_export]
1296+ macro_rules! mk_ast_arena {
1297+ ( $name: ident) => {
1298+ let tag = $crate:: ast:: InvariantLifetime :: default ( ) ;
1299+ let $name = unsafe { std:: sync:: Arc :: new( $crate:: ast:: Arena :: new( & tag) ) } ;
1300+ let _guard;
1301+ // this doesn't make it to MIR, but ensures that borrowck will not
1302+ // unify the lifetimes of two macro calls by binding the lifetime to
1303+ // drop scope
1304+ if false {
1305+ struct Guard <' tag>( & ' tag $crate:: ast:: InvariantLifetime <' tag>) ;
1306+ impl <' tag> :: core:: ops:: Drop for Guard <' tag> {
1307+ fn drop( & mut self ) { }
1308+ }
1309+ _guard = Guard ( & tag) ;
1310+ }
1311+ } ;
1312+ }
1313+
12901314pub struct RootExpr < Id : ' static > {
12911315 // Only used to keep `expr` alive
12921316 #[ allow( dead_code) ]
12931317 arena : Arc < Arena < ' static , Id > > ,
12941318 expr : * mut SpannedExpr < ' static , Id > ,
12951319}
12961320
1321+ impl < Id : ' static > Default for RootExpr < Id > {
1322+ fn default ( ) -> Self {
1323+ mk_ast_arena ! ( arena) ;
1324+ let expr = arena. alloc ( SpannedExpr :: default ( ) ) ;
1325+ RootExpr :: new ( arena. clone ( ) , expr)
1326+ }
1327+ }
1328+
12971329impl < Id : Eq > Eq for RootExpr < Id > { }
12981330impl < Id : PartialEq > PartialEq for RootExpr < Id > {
12991331 fn eq ( & self , other : & Self ) -> bool {
@@ -1393,6 +1425,12 @@ pub struct OwnedExpr<Id: 'static> {
13931425 expr : * mut SpannedExpr < ' static , Id > ,
13941426}
13951427
1428+ impl < Id : ' static > Default for OwnedExpr < Id > {
1429+ fn default ( ) -> Self {
1430+ RootExpr :: default ( ) . try_into_send ( ) . ok ( ) . unwrap_or_default ( )
1431+ }
1432+ }
1433+
13961434impl < Id : Eq > Eq for OwnedExpr < Id > { }
13971435impl < Id : PartialEq > PartialEq for OwnedExpr < Id > {
13981436 fn eq ( & self , other : & Self ) -> bool {
@@ -1449,30 +1487,6 @@ impl<Id> OwnedExpr<Id> {
14491487 }
14501488}
14511489
1452- #[ doc( hidden) ]
1453- #[ derive( Default ) ]
1454- pub struct InvariantLifetime < ' a > ( std:: marker:: PhantomData < fn ( & ' a ( ) ) -> & ' a ( ) > ) ;
1455-
1456- // Copied from the compact_arena crate
1457- #[ macro_export]
1458- macro_rules! mk_ast_arena {
1459- ( $name: ident) => {
1460- let tag = $crate:: ast:: InvariantLifetime :: default ( ) ;
1461- let $name = unsafe { std:: sync:: Arc :: new( $crate:: ast:: Arena :: new( & tag) ) } ;
1462- let _guard;
1463- // this doesn't make it to MIR, but ensures that borrowck will not
1464- // unify the lifetimes of two macro calls by binding the lifetime to
1465- // drop scope
1466- if false {
1467- struct Guard <' tag>( & ' tag $crate:: ast:: InvariantLifetime <' tag>) ;
1468- impl <' tag> :: core:: ops:: Drop for Guard <' tag> {
1469- fn drop( & mut self ) { }
1470- }
1471- _guard = Guard ( & tag) ;
1472- }
1473- } ;
1474- }
1475-
14761490pub trait AstClone < ' ast , Id > {
14771491 fn ast_clone ( & self , arena : ArenaRef < ' _ , ' ast , Id > ) -> Self ;
14781492}
0 commit comments