@@ -10,7 +10,8 @@ use thiserror::Error;
10
10
use crate :: ffi_items:: FfiItems ;
11
11
use crate :: template:: { CTestTemplate , RustTestTemplate } ;
12
12
use crate :: {
13
- Const , Field , MapInput , Parameter , Result , Static , Struct , Type , VolatileItemKind , expand,
13
+ Const , Field , MapInput , Parameter , Result , Static , Struct , TranslationError , Type ,
14
+ VolatileItemKind , expand,
14
15
} ;
15
16
16
17
/// A function that takes a mappable input and returns its mapping as Some, otherwise
@@ -46,6 +47,12 @@ pub enum GenerationError {
46
47
MacroExpansion ( PathBuf , String ) ,
47
48
#[ error( "unable to parse expanded crate {0}: {1}" ) ]
48
49
RustSyntax ( String , String ) ,
50
+ #[ error( "unable to prepare template input: {0}" ) ]
51
+ Translation ( #[ from] TranslationError ) ,
52
+ #[ error( "unable to render Rust template: {0}" ) ]
53
+ RustTemplateRender ( askama:: Error ) ,
54
+ #[ error( "unable to render C template: {0}" ) ]
55
+ CTemplateRender ( askama:: Error ) ,
49
56
#[ error( "unable to render {0} template: {1}" ) ]
50
57
TemplateRender ( String , String ) ,
51
58
#[ error( "unable to create or write template file: {0}" ) ]
@@ -605,10 +612,9 @@ impl TestGenerator {
605
612
s. push ( '\n' ) ;
606
613
} ;
607
614
608
- let mut rust_file = RustTestTemplate :: new ( & ffi_items, self )
609
- . map_err ( |e| GenerationError :: TemplateRender ( "Rust" . to_string ( ) , e. to_string ( ) ) ) ?
615
+ let mut rust_file = RustTestTemplate :: new ( & ffi_items, self ) ?
610
616
. render ( )
611
- . map_err ( |e| GenerationError :: TemplateRender ( "Rust" . to_string ( ) , e . to_string ( ) ) ) ?;
617
+ . map_err ( GenerationError :: RustTemplateRender ) ?;
612
618
ensure_trailing_newline ( & mut rust_file) ;
613
619
614
620
// Generate the Rust side of the tests.
@@ -617,10 +623,9 @@ impl TestGenerator {
617
623
. write_all ( rust_file. as_bytes ( ) )
618
624
. map_err ( GenerationError :: OsError ) ?;
619
625
620
- let mut c_file = CTestTemplate :: new ( & ffi_items, self )
621
- . map_err ( |e| GenerationError :: TemplateRender ( "C" . to_string ( ) , e. to_string ( ) ) ) ?
626
+ let mut c_file = CTestTemplate :: new ( & ffi_items, self ) ?
622
627
. render ( )
623
- . map_err ( |e| GenerationError :: TemplateRender ( "C" . to_string ( ) , e . to_string ( ) ) ) ?;
628
+ . map_err ( GenerationError :: CTemplateRender ) ?;
624
629
ensure_trailing_newline ( & mut c_file) ;
625
630
626
631
// Generate the C/Cxx side of the tests.
0 commit comments