@@ -1657,7 +1657,7 @@ pub enum ExprKind {
1657
1657
Try ( P < Expr > ) ,
1658
1658
1659
1659
/// A `yield`, with an optional value to be yielded.
1660
- Yield ( Option < P < Expr > > , YieldKind ) ,
1660
+ Yield ( YieldKind ) ,
1661
1661
1662
1662
/// A `do yeet` (aka `throw`/`fail`/`bail`/`raise`/whatever),
1663
1663
/// with an optional value to be returned.
@@ -1904,12 +1904,41 @@ pub enum MatchKind {
1904
1904
}
1905
1905
1906
1906
/// The kind of yield expression
1907
- #[ derive( Clone , Copy , Encodable , Decodable , Debug , PartialEq ) ]
1907
+ #[ derive( Clone , Encodable , Decodable , Debug ) ]
1908
1908
pub enum YieldKind {
1909
1909
/// yield expr { ... }
1910
- Prefix ,
1910
+ Prefix ( Option < P < Expr > > ) ,
1911
1911
/// 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
+ }
1913
1942
}
1914
1943
1915
1944
/// A literal in a meta item.
0 commit comments