@@ -2,7 +2,7 @@ use rustpython_codegen::{compile, symboltable};
22use rustpython_parser:: ast:: { fold:: Fold , ConstantOptimizer } ;
33
44pub use rustpython_codegen:: compile:: CompileOpts ;
5- pub use rustpython_compiler_core:: { BaseError as CompileErrorBody , CodeObject , Mode } ;
5+ pub use rustpython_compiler_core:: { CodeObject , Mode } ;
66
77// these modules are out of repository. re-exporting them here for convenience.
88pub use rustpython_codegen as codegen;
@@ -45,12 +45,7 @@ impl From<parser::ParseErrorType> for CompileErrorType {
4545 }
4646}
4747
48- pub type CompileError = rustpython_compiler_core:: CompileError < CompileErrorType > ;
49-
50- fn error_from_parse ( error : parser:: ParseError , source : & str ) -> CompileError {
51- let error: CompileErrorBody < parser:: ParseErrorType > = error. into ( ) ;
52- CompileError :: from ( error, source)
53- }
48+ pub type CompileError = rustpython_compiler_core:: BaseError < CompileErrorType > ;
5449
5550/// Compile a given source code into a bytecode object.
5651pub fn compile (
@@ -61,31 +56,30 @@ pub fn compile(
6156) -> Result < CodeObject , CompileError > {
6257 let mut ast = match parser:: parse ( source, mode. into ( ) , & source_path) {
6358 Ok ( x) => x,
64- Err ( e) => return Err ( error_from_parse ( e , source ) ) ,
59+ Err ( e) => return Err ( e . into ( ) ) ,
6560 } ;
6661 if opts. optimize > 0 {
6762 ast = ConstantOptimizer :: new ( )
6863 . fold_mod ( ast)
6964 . unwrap_or_else ( |e| match e { } ) ;
7065 }
71- compile:: compile_top ( & ast, source_path, mode, opts) . map_err ( |e| CompileError :: from ( e , source ) )
66+ compile:: compile_top ( & ast, source_path, mode, opts) . map_err ( |e| e . into ( ) )
7267}
7368
7469pub fn compile_symtable (
7570 source : & str ,
7671 mode : compile:: Mode ,
7772 source_path : & str ,
7873) -> Result < symboltable:: SymbolTable , CompileError > {
79- let parse_err = |e| error_from_parse ( e, source) ;
8074 let res = match mode {
8175 compile:: Mode :: Exec | compile:: Mode :: Single | compile:: Mode :: BlockExpr => {
82- let ast = parser:: parse_program ( source, source_path) . map_err ( parse_err ) ?;
76+ let ast = parser:: parse_program ( source, source_path) . map_err ( |e| e . into ( ) ) ?;
8377 symboltable:: SymbolTable :: scan_program ( & ast)
8478 }
8579 compile:: Mode :: Eval => {
86- let expr = parser:: parse_expression ( source, source_path) . map_err ( parse_err ) ?;
80+ let expr = parser:: parse_expression ( source, source_path) . map_err ( |e| e . into ( ) ) ?;
8781 symboltable:: SymbolTable :: scan_expr ( & expr)
8882 }
8983 } ;
90- res. map_err ( |e| CompileError :: from ( e. into_codegen_error ( source_path. to_owned ( ) ) , source ) )
84+ res. map_err ( |e| e. into_codegen_error ( source_path. to_owned ( ) ) . into ( ) )
9185}
0 commit comments