@@ -2314,7 +2314,7 @@ impl<'a> Emitter<'a> {
23142314 Doc :: intersperse ( ses. into_iter ( ) . map ( |se| se. group ( ) ) , Doc :: hardline ( ) )
23152315 }
23162316
2317- fn emit_fn_decl (
2317+ fn emit_fn_sig (
23182318 & mut self ,
23192319 env : & Env ,
23202320 FnDecl {
@@ -2468,6 +2468,39 @@ impl<'a> Emitter<'a> {
24682468 } ) ) )
24692469 . group ( )
24702470 }
2471+
2472+ fn emit_fn_decl ( & mut self , env : & Env , decl : & FnDecl ) -> Doc {
2473+ self . emit_fn_sig ( env, decl)
2474+ . nest ( 2 )
2475+ . append ( Doc :: hardline ( ) )
2476+ // add a (warning-free) body so that we can call it
2477+ . append ( "{ assume pure False; unreachable () }" )
2478+ }
2479+
2480+ fn emit_fn_defn ( & mut self , env : & Env , FnDefn { decl, body } : & FnDefn ) -> Doc {
2481+ if decl. is_pure {
2482+ return self . emit_pure_fn ( env, decl, body) ;
2483+ }
2484+ let decl_doc = self . emit_fn_sig ( env, decl) . nest ( 2 ) . append ( Doc :: hardline ( ) ) ;
2485+ let arg_redecl_as_mut = Doc :: concat ( decl. args . iter ( ) . filter_map ( |arg| {
2486+ arg. name . as_ref ( ) . map ( |n| {
2487+ Doc :: line ( ) . append ( annotated (
2488+ n,
2489+ Doc :: group ( {
2490+ let n = self . nm . emit ( Name :: Var ( n. val . clone ( ) ) ) ;
2491+ Doc :: text ( "let mut " )
2492+ . append ( n. clone ( ) )
2493+ . append ( " = " )
2494+ . append ( n)
2495+ . append ( ";" )
2496+ } ) ,
2497+ ) )
2498+ } )
2499+ } ) ) ;
2500+ let env = & mut env. clone ( ) ;
2501+ env. push_fn_decl_args_for_body ( decl) ;
2502+ decl_doc. append ( block ( arg_redecl_as_mut. append ( self . emit_stmts ( env, body) ) ) . group ( ) )
2503+ }
24712504} // impl Emitter (group E)
24722505
24732506/// Append remaining statements to a block (for if/else continuation in pure functions).
@@ -2730,32 +2763,8 @@ impl<'a> Emitter<'a> {
27302763 fn emit_decl ( & mut self , env : & Env , decl : & Decl ) -> Doc {
27312764 annotated ( decl, {
27322765 match & decl. val {
2733- DeclT :: FnDefn ( FnDefn { decl, body } ) => {
2734- if decl. is_pure {
2735- return self . emit_pure_fn ( env, decl, body) ;
2736- }
2737- let decl_doc = self . emit_fn_decl ( env, decl) . nest ( 2 ) . append ( Doc :: hardline ( ) ) ;
2738- let arg_redecl_as_mut = Doc :: concat ( decl. args . iter ( ) . filter_map ( |arg| {
2739- arg. name . as_ref ( ) . map ( |n| {
2740- Doc :: line ( ) . append ( annotated (
2741- n,
2742- Doc :: group ( {
2743- let n = self . nm . emit ( Name :: Var ( n. val . clone ( ) ) ) ;
2744- Doc :: text ( "let mut " )
2745- . append ( n. clone ( ) )
2746- . append ( " = " )
2747- . append ( n)
2748- . append ( ";" )
2749- } ) ,
2750- ) )
2751- } )
2752- } ) ) ;
2753- let env = & mut env. clone ( ) ;
2754- env. push_fn_decl_args_for_body ( decl) ;
2755- decl_doc
2756- . append ( block ( arg_redecl_as_mut. append ( self . emit_stmts ( env, body) ) ) . group ( ) )
2757- }
2758- DeclT :: FnDecl ( fn_decl) => self . emit_fn_decl ( & mut env. clone ( ) , fn_decl) ,
2766+ DeclT :: FnDefn ( fn_defn) => self . emit_fn_defn ( env, fn_defn) ,
2767+ DeclT :: FnDecl ( fn_decl) => self . emit_fn_decl ( env, fn_decl) ,
27592768 DeclT :: Typedef ( typedef) => self . emit_typedef ( env, typedef) ,
27602769 DeclT :: StructDefn ( struct_defn) => self . emit_structdefn ( env, struct_defn) ,
27612770 DeclT :: UnionDefn ( union_defn) => self . emit_uniondefn ( env, union_defn) ,
0 commit comments