Skip to content

Commit fcc92dd

Browse files
committed
Remove 'static lifetime from lrpar_config closure type
1 parent f66c661 commit fcc92dd

File tree

5 files changed

+14
-19
lines changed

5 files changed

+14
-19
lines changed

lrlex/src/lib/ctbuilder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ where
226226
LexerTypesT::StorageT: Debug + Eq + Hash + ToTokens,
227227
usize: num_traits::AsPrimitive<LexerTypesT::StorageT>,
228228
{
229-
lrpar_config: Option<Box<dyn Fn(CTParserBuilder<LexerTypesT>) -> CTParserBuilder<LexerTypesT>>>,
229+
lrpar_config: Option<Box<dyn Fn(CTParserBuilder<LexerTypesT>) -> CTParserBuilder<LexerTypesT> + 'a>>,
230230
lexer_path: Option<PathBuf>,
231231
output_path: Option<PathBuf>,
232232
lexerkind: Option<LexerKind>,
@@ -313,9 +313,9 @@ where
313313
/// .lexer_in_src_dir("calc.l")?
314314
/// .build()?;
315315
/// ```
316-
pub fn lrpar_config<F>(mut self, config_func: F) -> Self
316+
pub fn lrpar_config<F: 'a>(mut self, config_func: F) -> Self
317317
where
318-
F: 'static + Fn(CTParserBuilder<LexerTypesT>) -> CTParserBuilder<LexerTypesT>,
318+
F: Fn(CTParserBuilder<LexerTypesT>) -> CTParserBuilder<LexerTypesT>,
319319
{
320320
self.lrpar_config = Some(Box::new(config_func));
321321
self

lrpar/cttests/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use glob::glob;
33
#[path = "src/cgen_helper.rs"]
44
mod cgen_helper;
55
use cfg_aliases::cfg_aliases;
6-
use cgen_helper::{leaked_path, run_test_path};
6+
use cgen_helper::run_test_path;
77
use lrlex::{CTLexerBuilder, DefaultLexerTypes};
88

99
// Compiles the `*.test` files within `src`. Test files are written in Yaml syntax and have 4
@@ -16,7 +16,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
1616
println!("cargo::rerun-if-changed={}", src?.display());
1717
}
1818
for entry in glob("src/*.test")? {
19-
run_test_path(leaked_path(entry.unwrap()))?;
19+
run_test_path(entry.unwrap())?;
2020
}
2121

2222
cfg_aliases! {

lrpar/cttests/src/cgen_helper.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,13 @@ use std::{
77
};
88
use 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));

lrpar/cttests/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use cfgrammar::Span;
33

44
mod cgen_helper;
55
#[allow(unused)]
6-
use cgen_helper::{leaked_path, run_test_path};
6+
use cgen_helper::run_test_path;
77

88
mod calc_wasm;
99

lrpar/cttests_macro/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub fn generate_codegen_fail_tests(item: TokenStream) -> TokenStream {
3434
#[should_panic]
3535
#[test]
3636
fn #ident(){
37-
run_test_path(leaked_path(#path)).unwrap();
37+
run_test_path(#path).unwrap();
3838
}
3939
});
4040
}

0 commit comments

Comments
 (0)