@@ -500,6 +500,7 @@ impl<'a> FnIrBuilder<'a> {
500500 ty : ty_str,
501501 is_refcount_pointer,
502502 is_unsafe_pointer,
503+ is_reference : matches ! ( & ty, ast:: Type :: RefType ( _) ) ,
503504 derives : Vec :: new ( ) ,
504505 cpp_type : None ,
505506 elems : None ,
@@ -635,6 +636,40 @@ impl<'a> FnIrBuilder<'a> {
635636 . any ( |a| a. kind ( ) == SyntaxKind :: EXTERN_BLOCK )
636637 }
637638
639+ fn returns_place ( & self , params : & [ ParamInfo ] ) -> bool {
640+ fn is_place ( expr : ast:: Expr , params : & [ ParamInfo ] , projected : bool ) -> bool {
641+ match expr {
642+ ast:: Expr :: FieldExpr ( e) => {
643+ e. expr ( ) . is_some_and ( |base| is_place ( base, params, true ) )
644+ }
645+ ast:: Expr :: IndexExpr ( e) => {
646+ e. base ( ) . is_some_and ( |base| is_place ( base, params, true ) )
647+ }
648+ ast:: Expr :: ParenExpr ( e) => e
649+ . expr ( )
650+ . is_some_and ( |inner| is_place ( inner, params, projected) ) ,
651+ ast:: Expr :: PrefixExpr ( e) => {
652+ e. op_kind ( ) == Some ( ast:: UnaryOp :: Deref )
653+ && e. expr ( )
654+ . is_some_and ( |inner| is_place ( inner, params, projected) )
655+ }
656+ ast:: Expr :: PathExpr ( e) => {
657+ projected
658+ && e. path ( )
659+ . and_then ( |path| path. as_single_name_ref ( ) )
660+ . is_some_and ( |name| params. iter ( ) . any ( |p| p. name == name. text ( ) ) )
661+ }
662+ _ => false ,
663+ }
664+ }
665+ self . fn_item
666+ . body ( )
667+ . and_then ( |body| body. stmt_list ( ) )
668+ . filter ( |stmt_list| stmt_list. statements ( ) . next ( ) . is_none ( ) )
669+ . and_then ( |stmt_list| stmt_list. tail_expr ( ) )
670+ . is_some_and ( |tail| is_place ( tail, params, false ) )
671+ }
672+
638673 fn returns_mut_ref ( & self ) -> bool {
639674 self . fn_item
640675 . ret_type ( )
@@ -728,6 +763,7 @@ impl<'a> FnIrBuilder<'a> {
728763 ty : p. ty . clone ( ) ,
729764 is_refcount_pointer : p. is_refcount_pointer ,
730765 is_unsafe_pointer : p. is_unsafe_pointer ,
766+ is_reference : false ,
731767 derives : Vec :: new ( ) ,
732768 cpp_type : p. cpp_type . clone ( ) ,
733769 elems : None ,
@@ -767,6 +803,7 @@ impl<'a> FnIrBuilder<'a> {
767803 multi_statement,
768804 body,
769805 is_extern : self . is_extern ( ) . then_some ( true ) ,
806+ returns_place : self . returns_place ( & params) ,
770807 } ;
771808 ir. validate ( & format ! ( "{}:{}" , path. display( ) , fn_name) ) ;
772809 ir
@@ -840,6 +877,7 @@ impl<'a> TypeIrBuilder<'a> {
840877 ty : ty. syntax ( ) . text ( ) . to_string ( ) ,
841878 is_refcount_pointer,
842879 is_unsafe_pointer,
880+ is_reference : false ,
843881 derives : Vec :: new ( ) ,
844882 cpp_type : None ,
845883 elems : elems ( & ty) ,
0 commit comments