@@ -1726,8 +1726,9 @@ fn make_body(
17261726
17271727 let block = match & fun. body {
17281728 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." ) ;
17311732 match expr {
17321733 ast:: Expr :: BlockExpr ( block) => {
17331734 // 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(
19341935
19351936 for ( param, usages) in usages_for_param {
19361937 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 ( ) )
19481946 {
19491947 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 ;
19541949 }
19551950 }
1951+
1952+ let p = & make:: expr_prefix ( T ! [ * ] , usage. clone ( ) ) . clone_for_update ( ) ;
1953+ ted:: replace ( usage. syntax ( ) , p. syntax ( ) )
19561954 }
19571955 }
19581956
0 commit comments