From 11071ed6826f0f33816245efca574b795e4cd20c Mon Sep 17 00:00:00 2001 From: WillLillis Date: Mon, 3 Mar 2025 01:37:48 -0500 Subject: [PATCH] fix(rust): adapt to new nightly lint --- cli/benches/benchmark.rs | 6 +++--- cli/generate/src/lib.rs | 3 ++- cli/loader/src/lib.rs | 20 ++++++++++---------- cli/src/input.rs | 4 ++-- cli/src/query.rs | 4 ++-- cli/src/wasm.rs | 16 ++++++++++++---- lib/binding_rust/build.rs | 9 ++++++--- 7 files changed, 37 insertions(+), 25 deletions(-) diff --git a/cli/benches/benchmark.rs b/cli/benches/benchmark.rs index 2b0e29ea..943390c6 100644 --- a/cli/benches/benchmark.rs +++ b/cli/benches/benchmark.rs @@ -112,7 +112,7 @@ fn main() { parse(path, max_path_length, |source| { Query::new(&language, str::from_utf8(source).unwrap()) - .with_context(|| format!("Query file path: {path:?}")) + .with_context(|| format!("Query file path: {}", path.display())) .expect("Failed to parse query"); }); } @@ -201,7 +201,7 @@ fn parse(path: &Path, max_path_length: usize, mut action: impl FnMut(&[u8])) -> ); let source_code = fs::read(path) - .with_context(|| format!("Failed to read {path:?}")) + .with_context(|| format!("Failed to read {}", path.display())) .unwrap(); let time = Instant::now(); for _ in 0..*REPETITION_COUNT { @@ -221,6 +221,6 @@ fn get_language(path: &Path) -> Language { let src_path = GRAMMARS_DIR.join(path).join("src"); TEST_LOADER .load_language_at_path(CompileConfig::new(&src_path, None, None)) - .with_context(|| format!("Failed to load language at path {src_path:?}")) + .with_context(|| format!("Failed to load language at path {}", src_path.display())) .unwrap() } diff --git a/cli/generate/src/lib.rs b/cli/generate/src/lib.rs index 56b2cdc6..fa7973cb 100644 --- a/cli/generate/src/lib.rs +++ b/cli/generate/src/lib.rs @@ -183,7 +183,8 @@ pub fn generate_parser_in_directory( if grammar_path.file_name().unwrap() != "grammar.json" { fs::write(src_path.join("grammar.json"), &grammar_json).map_err(|e| { GenerateError::IO(format!( - "Failed to write grammar.json to {src_path:?} -- {e}" + "Failed to write grammar.json to {} -- {e}", + src_path.display() )) })?; } diff --git a/cli/loader/src/lib.rs b/cli/loader/src/lib.rs index 7d309265..06237dc3 100644 --- a/cli/loader/src/lib.rs +++ b/cli/loader/src/lib.rs @@ -561,8 +561,8 @@ impl Loader { // If multiple language configurations match, then determine which // one to use by applying the configurations' content regexes. else { - let file_contents = - fs::read(path).with_context(|| format!("Failed to read path {path:?}"))?; + let file_contents = fs::read(path) + .with_context(|| format!("Failed to read path {}", path.display()))?; let file_contents = String::from_utf8_lossy(&file_contents); let mut best_score = -2isize; let mut best_configuration_id = None; @@ -780,8 +780,8 @@ impl Loader { if recompile { fs::create_dir_all(lock_path.parent().unwrap()).with_context(|| { format!( - "Failed to create directory {:?}", - lock_path.parent().unwrap() + "Failed to create directory {}", + lock_path.parent().unwrap().display() ) })?; let lock_file = fs::OpenOptions::new() @@ -799,7 +799,7 @@ impl Loader { } let library = unsafe { Library::new(&output_path) } - .with_context(|| format!("Error opening dynamic library {output_path:?}"))?; + .with_context(|| format!("Error opening dynamic library {}", output_path.display()))?; let language = unsafe { let language_fn = library .get:: Language>>(language_fn_name.as_bytes()) @@ -1564,7 +1564,7 @@ impl LanguageConfiguration<'_> { error.row = source[range.start..offset_within_section] .matches('\n') .count(); - Error::from(error).context(format!("Error in query file {path:?}")) + Error::from(error).context(format!("Error in query file {}", path.display())) } #[allow(clippy::type_complexity)] @@ -1581,7 +1581,7 @@ impl LanguageConfiguration<'_> { let abs_path = self.root_path.join(path); let prev_query_len = query.len(); query += &fs::read_to_string(&abs_path) - .with_context(|| format!("Failed to read query file {path:?}"))?; + .with_context(|| format!("Failed to read query file {}", path.display()))?; path_ranges.push((path.clone(), prev_query_len..query.len())); } } else { @@ -1599,7 +1599,7 @@ impl LanguageConfiguration<'_> { let path = queries_path.join(default_path); if path.exists() { query = fs::read_to_string(&path) - .with_context(|| format!("Failed to read query file {path:?}"))?; + .with_context(|| format!("Failed to read query file {}", path.display()))?; path_ranges.push((PathBuf::from(default_path), 0..query.len())); } } @@ -1612,8 +1612,8 @@ fn needs_recompile(lib_path: &Path, paths_to_check: &[PathBuf]) -> Result if !lib_path.exists() { return Ok(true); } - let lib_mtime = - mtime(lib_path).with_context(|| format!("Failed to read mtime of {lib_path:?}"))?; + let lib_mtime = mtime(lib_path) + .with_context(|| format!("Failed to read mtime of {}", lib_path.display()))?; for path in paths_to_check { if mtime(path)? > lib_mtime { return Ok(true); diff --git a/cli/src/input.rs b/cli/src/input.rs index e22d19ef..5ab82087 100644 --- a/cli/src/input.rs +++ b/cli/src/input.rs @@ -89,8 +89,8 @@ pub fn get_input( let Some(path_str) = path.to_str() else { bail!("Invalid path: {}", path.display()); }; - let paths = - glob(path_str).with_context(|| format!("Invalid glob pattern {path:?}"))?; + let paths = glob(path_str) + .with_context(|| format!("Invalid glob pattern {}", path.display()))?; for path in paths { incorporate_path(path?, positive); } diff --git a/cli/src/query.rs b/cli/src/query.rs index ea961880..81ccea50 100644 --- a/cli/src/query.rs +++ b/cli/src/query.rs @@ -34,7 +34,7 @@ pub fn query_file_at_path( let mut stdout = stdout.lock(); let query_source = fs::read_to_string(query_path) - .with_context(|| format!("Error reading query file {query_path:?}"))?; + .with_context(|| format!("Error reading query file {}", query_path.display()))?; let query = Query::new(language, &query_source).with_context(|| "Query compilation failed")?; let mut query_cursor = QueryCursor::new(); @@ -55,7 +55,7 @@ pub fn query_file_at_path( } let source_code = - fs::read(path).with_context(|| format!("Error reading source file {path:?}"))?; + fs::read(path).with_context(|| format!("Error reading source file {}", path.display()))?; let tree = parser.parse(&source_code, None).unwrap(); let start = Instant::now(); diff --git a/cli/src/wasm.rs b/cli/src/wasm.rs index eca6ac24..eef6d08b 100644 --- a/cli/src/wasm.rs +++ b/cli/src/wasm.rs @@ -23,10 +23,18 @@ pub fn load_language_wasm_file(language_dir: &Path) -> Result<(String, Vec)> pub fn get_grammar_name(language_dir: &Path) -> Result { let src_dir = language_dir.join("src"); let grammar_json_path = src_dir.join("grammar.json"); - let grammar_json = fs::read_to_string(&grammar_json_path) - .with_context(|| format!("Failed to read grammar file {grammar_json_path:?}"))?; - let grammar: GrammarJSON = serde_json::from_str(&grammar_json) - .with_context(|| format!("Failed to parse grammar file {grammar_json_path:?}"))?; + let grammar_json = fs::read_to_string(&grammar_json_path).with_context(|| { + format!( + "Failed to read grammar file {}", + grammar_json_path.display() + ) + })?; + let grammar: GrammarJSON = serde_json::from_str(&grammar_json).with_context(|| { + format!( + "Failed to parse grammar file {}", + grammar_json_path.display() + ) + })?; Ok(grammar.name) } diff --git a/lib/binding_rust/build.rs b/lib/binding_rust/build.rs index 255740af..5e918034 100644 --- a/lib/binding_rust/build.rs +++ b/lib/binding_rust/build.rs @@ -112,7 +112,10 @@ fn generate_bindings(out_dir: &std::path::Path) { .expect("Failed to generate bindings"); let bindings_rs = out_dir.join("bindings.rs"); - bindings - .write_to_file(&bindings_rs) - .unwrap_or_else(|_| panic!("Failed to write bindings into path: {bindings_rs:?}")); + bindings.write_to_file(&bindings_rs).unwrap_or_else(|_| { + panic!( + "Failed to write bindings into path: {}", + bindings_rs.display() + ) + }); }