@@ -1657,7 +1657,7 @@ pub enum ExprKind {
16571657 Try ( P < Expr > ) ,
16581658
16591659 /// A `yield`, with an optional value to be yielded.
1660- Yield ( Option < P < Expr > > , YieldKind ) ,
1660+ Yield ( YieldKind ) ,
16611661
16621662 /// A `do yeet` (aka `throw`/`fail`/`bail`/`raise`/whatever),
16631663 /// with an optional value to be returned.
@@ -1904,12 +1904,41 @@ pub enum MatchKind {
19041904}
19051905
19061906/// The kind of yield expression
1907- #[ derive( Clone , Copy , Encodable , Decodable , Debug , PartialEq ) ]
1907+ #[ derive( Clone , Encodable , Decodable , Debug ) ]
19081908pub enum YieldKind {
19091909 /// yield expr { ... }
1910- Prefix ,
1910+ Prefix ( Option < P < Expr > > ) ,
19111911 /// expr.yield { ... }
1912- Postfix ,
1912+ Postfix ( P < Expr > ) ,
1913+ }
1914+
1915+ impl YieldKind {
1916+ /// Returns the expression inside the yield expression, if any.
1917+ ///
1918+ /// For postfix yields, this is guaranteed to be `Some`.
1919+ pub const fn expr ( & self ) -> Option < & P < Expr > > {
1920+ match self {
1921+ YieldKind :: Prefix ( expr) => expr. as_ref ( ) ,
1922+ YieldKind :: Postfix ( expr) => Some ( expr) ,
1923+ }
1924+ }
1925+
1926+ /// Returns a mutable reference to the expression being yielded, if any.
1927+ pub const fn expr_mut ( & mut self ) -> Option < & mut P < Expr > > {
1928+ match self {
1929+ YieldKind :: Prefix ( expr) => expr. as_mut ( ) ,
1930+ YieldKind :: Postfix ( expr) => Some ( expr) ,
1931+ }
1932+ }
1933+
1934+ /// Returns true if both yields are prefix or both are postfix.
1935+ pub const fn same_kind ( & self , other : & Self ) -> bool {
1936+ match ( self , other) {
1937+ ( YieldKind :: Prefix ( _) , YieldKind :: Prefix ( _) ) => true ,
1938+ ( YieldKind :: Postfix ( _) , YieldKind :: Postfix ( _) ) => true ,
1939+ _ => false ,
1940+ }
1941+ }
19131942}
19141943
19151944/// A literal in a meta item.
0 commit comments