File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -537,17 +537,22 @@ impl<'a> TypeIrBuilder<'a> {
537537 . fn_item
538538 . ret_type ( )
539539 . and_then ( |rt| rt. ty ( ) )
540- . expect ( "type rule must declare a return type" ) ;
540+ . expect ( "Type rules must declare a return type" ) ;
541541 let ( is_refcount_pointer, is_unsafe_pointer) = pointer_flags ( & ty) ;
542542
543- let body = self . fn_item . body ( ) . expect ( "type rule must have a body" ) ;
544- let init = body
545- . syntax ( )
546- . descendants ( )
547- . find_map ( ast:: ReturnExpr :: cast)
548- . and_then ( |ret| ret. expr ( ) )
549- . or_else ( || body. stmt_list ( ) . and_then ( |sl| sl. tail_expr ( ) ) )
550- . expect ( "type rule must yield an initializer" ) ;
543+ let stmts = self
544+ . fn_item
545+ . body ( )
546+ . and_then ( |bd| bd. stmt_list ( ) )
547+ . expect ( "Types rule must have a body" ) ;
548+ assert ! (
549+ stmts. statements( ) . count( ) == 0 ,
550+ "Type rules mustn't contain anything in the body besides the tail expression"
551+ ) ;
552+
553+ let init = stmts
554+ . tail_expr ( )
555+ . expect ( "Type rules must yield an initializer" ) ;
551556
552557 TypeIr {
553558 init : init. syntax ( ) . text ( ) . to_string ( ) ,
You can’t perform that action at this time.
0 commit comments