@@ -7,18 +7,13 @@ use std::{
77} ;
88use yaml_rust2:: YamlLoader ;
99
10- pub ( crate ) fn leaked_path < P : AsRef < Path > > ( path : P ) -> & ' static Path {
11- let p = PathBuf :: from ( path. as_ref ( ) ) . into_boxed_path ( ) ;
12- Box :: leak ( p)
13- }
14-
1510#[ allow( dead_code) ]
16- pub ( crate ) fn run_test_path ( path : & ' static Path ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
11+ pub ( crate ) fn run_test_path < P : AsRef < Path > > ( path : P ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
1712 let out_dir = env:: var ( "OUT_DIR" ) . unwrap ( ) ;
18- if path. is_file ( ) {
19- println ! ( "cargo::rerun-if-changed={}" , path. display( ) ) ;
13+ if path. as_ref ( ) . is_file ( ) {
14+ println ! ( "cargo::rerun-if-changed={}" , path. as_ref ( ) . display( ) ) ;
2015 // Parse test file
21- let s = fs:: read_to_string ( path) . unwrap ( ) ;
16+ let s = fs:: read_to_string ( path. as_ref ( ) ) . unwrap ( ) ;
2217 let docs = YamlLoader :: load_from_str ( & s) . unwrap ( ) ;
2318 let grm = & docs[ 0 ] [ "grammar" ] . as_str ( ) . unwrap ( ) ;
2419 let lex = & docs[ 0 ] [ "lexer" ] . as_str ( ) . unwrap ( ) ;
@@ -66,7 +61,7 @@ pub(crate) fn run_test_path(path: &'static Path) -> Result<(), Box<dyn std::erro
6661 // filename conventions. If those change, this code will also have to change.
6762
6863 // Create grammar files
69- let base = path. file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
64+ let base = path. as_ref ( ) . file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
7065 let mut pg = PathBuf :: from ( & out_dir) ;
7166 pg. push ( format ! ( "{}.test.y" , base) ) ;
7267 fs:: write ( & pg, grm) . unwrap ( ) ;
@@ -89,8 +84,8 @@ pub(crate) fn run_test_path(path: &'static Path) -> Result<(), Box<dyn std::erro
8984 outl. push ( format ! ( "{}.l.rs" , base) ) ;
9085 outl. set_extension ( "rs" ) ;
9186 let mut cl_build = CTLexerBuilder :: new ( )
92- . lrpar_config ( move |mut cp_build| {
93- let s = fs:: read_to_string ( path) . unwrap ( ) ;
87+ . lrpar_config ( |mut cp_build| {
88+ let s = fs:: read_to_string ( path. as_ref ( ) ) . unwrap ( ) ;
9489 let docs = YamlLoader :: load_from_str ( & s) . unwrap ( ) ;
9590 let mut outp = PathBuf :: from ( & out_dir) ;
9691 outp. push ( format ! ( "{}.y.rs" , base) ) ;
0 commit comments