Skip to content

Commit 97c776c

Browse files
authored
Merge branch 'tree-sitter:master' into master
2 parents d274b96 + 0b28226 commit 97c776c

File tree

25 files changed

+212
-86
lines changed

25 files changed

+212
-86
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
uses: actions-rust-lang/setup-rust-toolchain@v1
3333
with:
3434
toolchain: stable
35+
components: clippy, rustfmt
3536

3637
- name: Set up nightly Rust toolchain
3738
uses: actions-rust-lang/setup-rust-toolchain@v1
@@ -44,6 +45,11 @@ jobs:
4445
make lint
4546
make lint-web
4647
48+
- name: Lint files (Rust nightly)
49+
continue-on-error: true
50+
run: |
51+
make lint-nightly
52+
4753
sanitize:
4854
uses: ./.github/workflows/sanitize.yml
4955

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ test-wasm:
104104
cargo xtask test-wasm
105105

106106
lint:
107+
cargo update --workspace --locked --quiet
108+
cargo check --workspace --all-targets
109+
cargo +nightly fmt --all --check
110+
cargo +stable clippy --workspace --all-targets -- -D warnings
111+
112+
lint-nightly:
107113
cargo update --workspace --locked --quiet
108114
cargo check --workspace --all-targets
109115
cargo +nightly fmt --all --check

cli/benches/benchmark.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ fn main() {
112112

113113
parse(path, max_path_length, |source| {
114114
Query::new(&language, str::from_utf8(source).unwrap())
115-
.with_context(|| format!("Query file path: {path:?}"))
115+
.with_context(|| format!("Query file path: {}", path.display()))
116116
.expect("Failed to parse query");
117117
});
118118
}
@@ -201,7 +201,7 @@ fn parse(path: &Path, max_path_length: usize, mut action: impl FnMut(&[u8])) ->
201201
);
202202

203203
let source_code = fs::read(path)
204-
.with_context(|| format!("Failed to read {path:?}"))
204+
.with_context(|| format!("Failed to read {}", path.display()))
205205
.unwrap();
206206
let time = Instant::now();
207207
for _ in 0..*REPETITION_COUNT {
@@ -221,6 +221,6 @@ fn get_language(path: &Path) -> Language {
221221
let src_path = GRAMMARS_DIR.join(path).join("src");
222222
TEST_LOADER
223223
.load_language_at_path(CompileConfig::new(&src_path, None, None))
224-
.with_context(|| format!("Failed to load language at path {src_path:?}"))
224+
.with_context(|| format!("Failed to load language at path {}", src_path.display()))
225225
.unwrap()
226226
}

cli/generate/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ pub fn generate_parser_in_directory(
183183
if grammar_path.file_name().unwrap() != "grammar.json" {
184184
fs::write(src_path.join("grammar.json"), &grammar_json).map_err(|e| {
185185
GenerateError::IO(format!(
186-
"Failed to write grammar.json to {src_path:?} -- {e}"
186+
"Failed to write grammar.json to {} -- {e}",
187+
src_path.display()
187188
))
188189
})?;
189190
}

cli/generate/src/render.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const ABI_VERSION_WITH_RESERVED_WORDS: usize = 15;
2626
const BUILD_VERSION: &str = env!("CARGO_PKG_VERSION");
2727
const BUILD_SHA: Option<&'static str> = option_env!("BUILD_SHA");
2828

29+
#[clippy::format_args]
2930
macro_rules! add {
3031
($this: tt, $($arg: tt)*) => {{
3132
$this.buffer.write_fmt(format_args!($($arg)*)).unwrap();
@@ -40,6 +41,7 @@ macro_rules! add_whitespace {
4041
}};
4142
}
4243

44+
#[clippy::format_args]
4345
macro_rules! add_line {
4446
($this: tt, $($arg: tt)*) => {
4547
add_whitespace!($this);
@@ -1111,7 +1113,11 @@ impl Generator {
11111113
return;
11121114
}
11131115

1114-
add_line!(self, "const TSCharacterRange {}[] = {{", info.constant_name);
1116+
add_line!(
1117+
self,
1118+
"static const TSCharacterRange {}[] = {{",
1119+
info.constant_name
1120+
);
11151121

11161122
indent!(self);
11171123
for (ix, range) in characters.ranges().enumerate() {

cli/generate/src/rules.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ impl Symbol {
306306
}
307307

308308
impl From<Symbol> for Rule {
309-
#[must_use]
310309
fn from(symbol: Symbol) -> Self {
311310
Self::Symbol(symbol)
312311
}

cli/loader/src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,8 @@ impl Loader {
561561
// If multiple language configurations match, then determine which
562562
// one to use by applying the configurations' content regexes.
563563
else {
564-
let file_contents =
565-
fs::read(path).with_context(|| format!("Failed to read path {path:?}"))?;
564+
let file_contents = fs::read(path)
565+
.with_context(|| format!("Failed to read path {}", path.display()))?;
566566
let file_contents = String::from_utf8_lossy(&file_contents);
567567
let mut best_score = -2isize;
568568
let mut best_configuration_id = None;
@@ -780,8 +780,8 @@ impl Loader {
780780
if recompile {
781781
fs::create_dir_all(lock_path.parent().unwrap()).with_context(|| {
782782
format!(
783-
"Failed to create directory {:?}",
784-
lock_path.parent().unwrap()
783+
"Failed to create directory {}",
784+
lock_path.parent().unwrap().display()
785785
)
786786
})?;
787787
let lock_file = fs::OpenOptions::new()
@@ -799,7 +799,7 @@ impl Loader {
799799
}
800800

801801
let library = unsafe { Library::new(&output_path) }
802-
.with_context(|| format!("Error opening dynamic library {output_path:?}"))?;
802+
.with_context(|| format!("Error opening dynamic library {}", output_path.display()))?;
803803
let language = unsafe {
804804
let language_fn = library
805805
.get::<Symbol<unsafe extern "C" fn() -> Language>>(language_fn_name.as_bytes())
@@ -1564,7 +1564,7 @@ impl LanguageConfiguration<'_> {
15641564
error.row = source[range.start..offset_within_section]
15651565
.matches('\n')
15661566
.count();
1567-
Error::from(error).context(format!("Error in query file {path:?}"))
1567+
Error::from(error).context(format!("Error in query file {}", path.display()))
15681568
}
15691569

15701570
#[allow(clippy::type_complexity)]
@@ -1581,7 +1581,7 @@ impl LanguageConfiguration<'_> {
15811581
let abs_path = self.root_path.join(path);
15821582
let prev_query_len = query.len();
15831583
query += &fs::read_to_string(&abs_path)
1584-
.with_context(|| format!("Failed to read query file {path:?}"))?;
1584+
.with_context(|| format!("Failed to read query file {}", path.display()))?;
15851585
path_ranges.push((path.clone(), prev_query_len..query.len()));
15861586
}
15871587
} else {
@@ -1599,7 +1599,7 @@ impl LanguageConfiguration<'_> {
15991599
let path = queries_path.join(default_path);
16001600
if path.exists() {
16011601
query = fs::read_to_string(&path)
1602-
.with_context(|| format!("Failed to read query file {path:?}"))?;
1602+
.with_context(|| format!("Failed to read query file {}", path.display()))?;
16031603
path_ranges.push((PathBuf::from(default_path), 0..query.len()));
16041604
}
16051605
}
@@ -1612,8 +1612,8 @@ fn needs_recompile(lib_path: &Path, paths_to_check: &[PathBuf]) -> Result<bool>
16121612
if !lib_path.exists() {
16131613
return Ok(true);
16141614
}
1615-
let lib_mtime =
1616-
mtime(lib_path).with_context(|| format!("Failed to read mtime of {lib_path:?}"))?;
1615+
let lib_mtime = mtime(lib_path)
1616+
.with_context(|| format!("Failed to read mtime of {}", lib_path.display()))?;
16171617
for path in paths_to_check {
16181618
if mtime(path)? > lib_mtime {
16191619
return Ok(true);

cli/src/fuzz/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ fn regex_env_var(name: &'static str) -> Option<Regex> {
5656
pub fn new_seed() -> usize {
5757
int_env_var("TREE_SITTER_SEED").unwrap_or_else(|| {
5858
let mut rng = rand::thread_rng();
59-
rng.gen::<usize>()
59+
let seed = rng.gen::<usize>();
60+
eprintln!("Seed: {seed}");
61+
seed
6062
})
6163
}
6264

cli/src/input.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ pub fn get_input(
8989
let Some(path_str) = path.to_str() else {
9090
bail!("Invalid path: {}", path.display());
9191
};
92-
let paths =
93-
glob(path_str).with_context(|| format!("Invalid glob pattern {path:?}"))?;
92+
let paths = glob(path_str)
93+
.with_context(|| format!("Invalid glob pattern {}", path.display()))?;
9494
for path in paths {
9595
incorporate_path(path?, positive);
9696
}

cli/src/query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub fn query_file_at_path(
3434
let mut stdout = stdout.lock();
3535

3636
let query_source = fs::read_to_string(query_path)
37-
.with_context(|| format!("Error reading query file {query_path:?}"))?;
37+
.with_context(|| format!("Error reading query file {}", query_path.display()))?;
3838
let query = Query::new(language, &query_source).with_context(|| "Query compilation failed")?;
3939

4040
let mut query_cursor = QueryCursor::new();
@@ -55,7 +55,7 @@ pub fn query_file_at_path(
5555
}
5656

5757
let source_code =
58-
fs::read(path).with_context(|| format!("Error reading source file {path:?}"))?;
58+
fs::read(path).with_context(|| format!("Error reading source file {}", path.display()))?;
5959
let tree = parser.parse(&source_code, None).unwrap();
6060

6161
let start = Instant::now();

0 commit comments

Comments
 (0)