11#![ doc = include_str ! ( "../README.md" ) ]
22
3- use std:: collections:: HashMap ;
4- use std:: ffi:: { OsStr , OsString } ;
5- use std:: io:: { BufRead , BufReader } ;
6- use std:: ops:: Range ;
7- use std:: path:: { Path , PathBuf } ;
8- use std:: process:: Command ;
9- use std:: sync:: Mutex ;
10- use std:: time:: SystemTime ;
11- use std:: { env, fs, mem} ;
3+ use std:: {
4+ collections:: HashMap ,
5+ env,
6+ ffi:: { OsStr , OsString } ,
7+ fs,
8+ io:: { BufRead , BufReader } ,
9+ mem,
10+ ops:: Range ,
11+ path:: { Path , PathBuf } ,
12+ process:: Command ,
13+ sync:: Mutex ,
14+ time:: SystemTime ,
15+ } ;
1216
1317use anyhow:: { anyhow, Context , Error , Result } ;
1418use fs4:: FileExt ;
@@ -126,11 +130,12 @@ pub struct CompileConfig<'a> {
126130}
127131
128132impl < ' a > CompileConfig < ' a > {
133+ #[ must_use]
129134 pub fn new (
130135 src_path : & ' a Path ,
131136 externals : Option < & ' a [ PathBuf ] > ,
132137 output_path : Option < PathBuf > ,
133- ) -> CompileConfig < ' a > {
138+ ) -> Self {
134139 Self {
135140 src_path,
136141 header_paths : vec ! [ src_path] ,
@@ -445,7 +450,7 @@ impl Loader {
445450 let parser_path = config. src_path . join ( "parser.c" ) ;
446451 config. scanner_path = self . get_scanner_path ( config. src_path ) ;
447452
448- let mut paths_to_check = vec ! [ parser_path. clone ( ) ] ;
453+ let mut paths_to_check = vec ! [ parser_path] ;
449454
450455 if let Some ( scanner_path) = config. scanner_path . as_ref ( ) {
451456 paths_to_check. push ( scanner_path. clone ( ) ) ;
@@ -484,7 +489,9 @@ impl Loader {
484489 }
485490
486491 let lock_path = if env:: var ( "CROSS_RUNNER" ) . is_ok ( ) {
487- PathBuf :: from ( "/tmp" )
492+ tempfile:: tempdir ( )
493+ . unwrap ( )
494+ . path ( )
488495 . join ( "tree-sitter" )
489496 . join ( "lock" )
490497 . join ( format ! ( "{}.lock" , config. name) )
@@ -499,7 +506,8 @@ impl Loader {
499506 if let Ok ( lock_file) = fs:: OpenOptions :: new ( ) . write ( true ) . open ( & lock_path) {
500507 recompile = false ;
501508 if lock_file. try_lock_exclusive ( ) . is_err ( ) {
502- // if we can't acquire the lock, another process is compiling the parser, wait for it and don't recompile
509+ // if we can't acquire the lock, another process is compiling the parser, wait for
510+ // it and don't recompile
503511 lock_file. lock_exclusive ( ) ?;
504512 recompile = false ;
505513 } else {
@@ -1016,7 +1024,7 @@ impl Loader {
10161024 language_name : grammar_json. name . clone ( ) ,
10171025 scope : config_json. scope ,
10181026 language_id,
1019- file_types : config_json. file_types . unwrap_or ( Vec :: new ( ) ) ,
1027+ file_types : config_json. file_types . unwrap_or_default ( ) ,
10201028 content_regex : Self :: regex ( config_json. content_regex . as_deref ( ) ) ,
10211029 first_line_regex : Self :: regex ( config_json. first_line_regex . as_deref ( ) ) ,
10221030 injection_regex : Self :: regex ( config_json. injection_regex . as_deref ( ) ) ,
@@ -1043,8 +1051,11 @@ impl Loader {
10431051 . push ( self . language_configurations . len ( ) ) ;
10441052 }
10451053
1046- self . language_configurations
1047- . push ( unsafe { mem:: transmute ( configuration) } ) ;
1054+ self . language_configurations . push ( unsafe {
1055+ mem:: transmute :: < LanguageConfiguration < ' _ > , LanguageConfiguration < ' static > > (
1056+ configuration,
1057+ )
1058+ } ) ;
10481059
10491060 if set_current_path_config
10501061 && self . language_configuration_in_current_path . is_none ( )
@@ -1083,8 +1094,11 @@ impl Loader {
10831094 highlight_names : & self . highlight_names ,
10841095 use_all_highlight_names : self . use_all_highlight_names ,
10851096 } ;
1086- self . language_configurations
1087- . push ( unsafe { mem:: transmute ( configuration) } ) ;
1097+ self . language_configurations . push ( unsafe {
1098+ mem:: transmute :: < LanguageConfiguration < ' _ > , LanguageConfiguration < ' static > > (
1099+ configuration,
1100+ )
1101+ } ) ;
10881102 self . languages_by_id
10891103 . push ( ( parser_path. to_owned ( ) , OnceCell :: new ( ) , None ) ) ;
10901104 }
@@ -1322,8 +1336,7 @@ impl<'a> LanguageConfiguration<'a> {
13221336 . unwrap_or_else ( || ranges. last ( ) . unwrap ( ) ) ;
13231337 error. offset = offset_within_section - range. start ;
13241338 error. row = source[ range. start ..offset_within_section]
1325- . chars ( )
1326- . filter ( |c| * c == '\n' )
1339+ . matches ( |c| c == '\n' )
13271340 . count ( ) ;
13281341 Error :: from ( error) . context ( format ! ( "Error in query file {path:?}" ) )
13291342 }
0 commit comments