@@ -1726,8 +1726,9 @@ fn make_body(
1726
1726
1727
1727
let block = match & fun. body {
1728
1728
FunctionBody :: Expr ( expr) => {
1729
- let expr = rewrite_body_segment ( ctx, & fun. params , & handler, expr. syntax ( ) ) ?;
1730
- let expr = ast:: Expr :: cast ( expr) ?;
1729
+ let expr = rewrite_body_segment ( ctx, & fun. params , & handler, expr. syntax ( ) )
1730
+ . expect ( "rewrite_body_segment failed." ) ;
1731
+ let expr = ast:: Expr :: cast ( expr) . expect ( "error while casting body segment to an expr." ) ;
1731
1732
match expr {
1732
1733
ast:: Expr :: BlockExpr ( block) => {
1733
1734
// If the extracted expression is itself a block, there is no need to wrap it inside another block.
@@ -1934,25 +1935,22 @@ fn fix_param_usages(
1934
1935
1935
1936
for ( param, usages) in usages_for_param {
1936
1937
for usage in usages {
1937
- match usage. syntax ( ) . ancestors ( ) . skip ( 1 ) . find_map ( ast:: Expr :: cast) {
1938
- Some ( ast:: Expr :: MethodCallExpr ( _) | ast:: Expr :: FieldExpr ( _) ) => {
1939
- // do nothing
1940
- }
1941
- Some ( ast:: Expr :: RefExpr ( node) )
1942
- if param. kind ( ) == ParamKind :: MutRef && node. mut_token ( ) . is_some ( ) =>
1943
- {
1944
- ted:: replace ( node. syntax ( ) , node. expr ( ) ?. syntax ( ) ) ;
1945
- }
1946
- Some ( ast:: Expr :: RefExpr ( node) )
1947
- if param. kind ( ) == ParamKind :: SharedRef && node. mut_token ( ) . is_none ( ) =>
1938
+ let expr = usage. syntax ( ) . ancestors ( ) . skip ( 1 ) . find_map ( ast:: Expr :: cast) ;
1939
+ if let Some ( ast:: Expr :: MethodCallExpr ( _) | ast:: Expr :: FieldExpr ( _) ) = expr {
1940
+ continue ;
1941
+ }
1942
+
1943
+ if let Some ( ast:: Expr :: RefExpr ( node) ) = expr {
1944
+ if ( param. kind ( ) == ParamKind :: MutRef && node. mut_token ( ) . is_some ( ) )
1945
+ || ( param. kind ( ) == ParamKind :: SharedRef && node. mut_token ( ) . is_none ( ) )
1948
1946
{
1949
1947
ted:: replace ( node. syntax ( ) , node. expr ( ) ?. syntax ( ) ) ;
1950
- }
1951
- Some ( _) | None => {
1952
- let p = & make:: expr_prefix ( T ! [ * ] , usage. clone ( ) ) . clone_for_update ( ) ;
1953
- ted:: replace ( usage. syntax ( ) , p. syntax ( ) )
1948
+ continue ;
1954
1949
}
1955
1950
}
1951
+
1952
+ let p = & make:: expr_prefix ( T ! [ * ] , usage. clone ( ) ) . clone_for_update ( ) ;
1953
+ ted:: replace ( usage. syntax ( ) , p. syntax ( ) )
1956
1954
}
1957
1955
}
1958
1956
0 commit comments