Skip to content

Commit 592175d

Browse files
committed
fix: run cargo clippy --fix
1 parent 73650fb commit 592175d

File tree

14 files changed

+136
-155
lines changed

14 files changed

+136
-155
lines changed

rewatch/src/build.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub struct CompilerArgs {
5858
pub fn get_compiler_args(path: &Path) -> Result<String> {
5959
let filename = &helpers::get_abs_path(path);
6060
let package_root =
61-
helpers::get_abs_path(&helpers::get_nearest_config(&path).expect("Couldn't find package root"));
61+
helpers::get_abs_path(&helpers::get_nearest_config(path).expect("Couldn't find package root"));
6262
let workspace_root = get_workspace_root(&package_root).map(|p| helpers::get_abs_path(&p));
6363
let root_rescript_config =
6464
packages::read_config(&workspace_root.to_owned().unwrap_or(package_root.to_owned()))?;
@@ -77,7 +77,7 @@ pub fn get_compiler_args(path: &Path) -> Result<String> {
7777
let (ast_path, parser_args) = parser_args(
7878
&rescript_config,
7979
&root_rescript_config,
80-
&relative_filename,
80+
relative_filename,
8181
&workspace_root,
8282
workspace_root.as_ref().unwrap_or(&package_root),
8383
&contents,
@@ -94,7 +94,7 @@ pub fn get_compiler_args(path: &Path) -> Result<String> {
9494
&rescript_config,
9595
&root_rescript_config,
9696
&ast_path,
97-
&relative_filename,
97+
relative_filename,
9898
is_interface,
9999
has_interface,
100100
&package_root,
@@ -216,7 +216,7 @@ pub fn initialize_build(
216216

217217
if show_progress {
218218
if snapshot_output {
219-
println!("Cleaned {}/{}", diff_cleanup, total_cleanup)
219+
println!("Cleaned {diff_cleanup}/{total_cleanup}")
220220
} else {
221221
println!(
222222
"{}{} {}Cleaned {}/{} {:.2}s",
@@ -234,7 +234,7 @@ pub fn initialize_build(
234234
}
235235

236236
fn format_step(current: usize, total: usize) -> console::StyledObject<String> {
237-
style(format!("[{}/{}]", current, total)).bold().dim()
237+
style(format!("[{current}/{total}]")).bold().dim()
238238
}
239239

240240
#[derive(Debug, Clone)]
@@ -254,23 +254,23 @@ impl fmt::Display for IncrementalBuildError {
254254
match &self.kind {
255255
IncrementalBuildErrorKind::SourceFileParseError => {
256256
if self.snapshot_output {
257-
write!(f, "{} Could not parse Source Files", LINE_CLEAR,)
257+
write!(f, "{LINE_CLEAR} Could not parse Source Files",)
258258
} else {
259-
write!(f, "{} {}Could not parse Source Files", LINE_CLEAR, CROSS,)
259+
write!(f, "{LINE_CLEAR} {CROSS}Could not parse Source Files",)
260260
}
261261
}
262262
IncrementalBuildErrorKind::CompileError(Some(e)) => {
263263
if self.snapshot_output {
264-
write!(f, "{} Failed to Compile. Error: {e}", LINE_CLEAR,)
264+
write!(f, "{LINE_CLEAR} Failed to Compile. Error: {e}",)
265265
} else {
266-
write!(f, "{} {}Failed to Compile. Error: {e}", LINE_CLEAR, CROSS,)
266+
write!(f, "{LINE_CLEAR} {CROSS}Failed to Compile. Error: {e}",)
267267
}
268268
}
269269
IncrementalBuildErrorKind::CompileError(None) => {
270270
if self.snapshot_output {
271-
write!(f, "{} Failed to Compile. See Errors Above", LINE_CLEAR,)
271+
write!(f, "{LINE_CLEAR} Failed to Compile. See Errors Above",)
272272
} else {
273-
write!(f, "{} {}Failed to Compile. See Errors Above", LINE_CLEAR, CROSS,)
273+
write!(f, "{LINE_CLEAR} {CROSS}Failed to Compile. See Errors Above",)
274274
}
275275
}
276276
}
@@ -312,7 +312,7 @@ pub fn incremental_build(
312312
Ok(_ast) => {
313313
if show_progress {
314314
if snapshot_output {
315-
println!("Parsed {} source files", num_dirty_modules)
315+
println!("Parsed {num_dirty_modules} source files")
316316
} else {
317317
println!(
318318
"{}{} {}Parsed {} source files in {:.2}s",
@@ -370,7 +370,7 @@ pub fn incremental_build(
370370
if log_enabled!(log::Level::Trace) {
371371
for (module_name, module) in build_state.modules.iter() {
372372
if module.compile_dirty {
373-
println!("compile dirty: {}", module_name);
373+
println!("compile dirty: {module_name}");
374374
}
375375
}
376376
};
@@ -411,7 +411,7 @@ pub fn incremental_build(
411411
if !compile_errors.is_empty() {
412412
if show_progress {
413413
if snapshot_output {
414-
println!("Compiled {} modules", num_compiled_modules)
414+
println!("Compiled {num_compiled_modules} modules")
415415
} else {
416416
println!(
417417
"{}{} {}Compiled {} modules in {:.2}s",
@@ -436,7 +436,7 @@ pub fn incremental_build(
436436
} else {
437437
if show_progress {
438438
if snapshot_output {
439-
println!("Compiled {} modules", num_compiled_modules)
439+
println!("Compiled {num_compiled_modules} modules")
440440
} else {
441441
println!(
442442
"{}{} {}Compiled {} modules in {:.2}s",

rewatch/src/build/compile.rs

Lines changed: 64 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,8 @@ pub fn compiler_args(
417417

418418
specs
419419
.iter()
420-
.map(|spec| {
421-
return vec![
420+
.flat_map(|spec| {
421+
vec![
422422
"-bs-package-output".to_string(),
423423
format!(
424424
"{}:{}:{}",
@@ -437,9 +437,8 @@ pub fn compiler_args(
437437
},
438438
root_config.get_suffix(spec),
439439
),
440-
];
440+
]
441441
})
442-
.flatten()
443442
.collect()
444443
};
445444

@@ -614,8 +613,7 @@ fn compile_file(
614613
Err(stderr.to_string() + &stdout)
615614
}
616615
Err(e) => Err(format!(
617-
"Could not compile file. Error: {}. Path to AST: {:?}",
618-
e, ast_path
616+
"Could not compile file. Error: {e}. Path to AST: {ast_path:?}"
619617
)),
620618
Ok(x) => {
621619
let err = std::str::from_utf8(&x.stderr)
@@ -633,15 +631,15 @@ fn compile_file(
633631
// because editor tooling doesn't support namespace entries yet
634632
// we just remove the @ for now. This makes sure the editor support
635633
// doesn't break
636-
.join(format!("{}.cmi", module_name)),
637-
ocaml_build_path_abs.join(format!("{}.cmi", module_name)),
634+
.join(format!("{module_name}.cmi")),
635+
ocaml_build_path_abs.join(format!("{module_name}.cmi")),
638636
);
639637
let _ = std::fs::copy(
640638
package
641639
.get_build_path()
642640
.join(dir)
643-
.join(format!("{}.cmj", module_name)),
644-
ocaml_build_path_abs.join(format!("{}.cmj", module_name)),
641+
.join(format!("{module_name}.cmj")),
642+
ocaml_build_path_abs.join(format!("{module_name}.cmj")),
645643
);
646644
let _ = std::fs::copy(
647645
package
@@ -650,98 +648,89 @@ fn compile_file(
650648
// because editor tooling doesn't support namespace entries yet
651649
// we just remove the @ for now. This makes sure the editor support
652650
// doesn't break
653-
.join(format!("{}.cmt", module_name)),
654-
ocaml_build_path_abs.join(format!("{}.cmt", module_name)),
651+
.join(format!("{module_name}.cmt")),
652+
ocaml_build_path_abs.join(format!("{module_name}.cmt")),
655653
);
656654
} else {
657655
let _ = std::fs::copy(
658656
package
659657
.get_build_path()
660658
.join(dir)
661-
.join(format!("{}.cmti", module_name)),
662-
ocaml_build_path_abs.join(format!("{}.cmti", module_name)),
659+
.join(format!("{module_name}.cmti")),
660+
ocaml_build_path_abs.join(format!("{module_name}.cmti")),
663661
);
664662
let _ = std::fs::copy(
665663
package
666664
.get_build_path()
667665
.join(dir)
668-
.join(format!("{}.cmi", module_name)),
669-
ocaml_build_path_abs.join(format!("{}.cmi", module_name)),
666+
.join(format!("{module_name}.cmi")),
667+
ocaml_build_path_abs.join(format!("{module_name}.cmi")),
670668
);
671669
}
672670

673-
match &module.source_type {
674-
SourceType::SourceFile(SourceFile {
671+
if let SourceType::SourceFile(SourceFile {
675672
interface: Some(Interface { path, .. }),
676673
..
677-
}) => {
678-
// we need to copy the source file to the build directory.
679-
// editor tools expects the source file in lib/bs for finding the current package
680-
// and in lib/ocaml when referencing modules in other packages
681-
let _ = std::fs::copy(
682-
Path::new(&package.path).join(path),
683-
package.get_build_path().join(path),
684-
)
685-
.expect("copying source file failed");
686-
687-
let _ = std::fs::copy(
688-
Path::new(&package.path).join(path),
689-
package
690-
.get_ocaml_build_path()
691-
.join(std::path::Path::new(path).file_name().unwrap()),
692-
)
693-
.expect("copying source file failed");
694-
}
695-
_ => (),
674+
}) = &module.source_type {
675+
// we need to copy the source file to the build directory.
676+
// editor tools expects the source file in lib/bs for finding the current package
677+
// and in lib/ocaml when referencing modules in other packages
678+
let _ = std::fs::copy(
679+
Path::new(&package.path).join(path),
680+
package.get_build_path().join(path),
681+
)
682+
.expect("copying source file failed");
683+
684+
let _ = std::fs::copy(
685+
Path::new(&package.path).join(path),
686+
package
687+
.get_ocaml_build_path()
688+
.join(std::path::Path::new(path).file_name().unwrap()),
689+
)
690+
.expect("copying source file failed");
696691
}
697-
match &module.source_type {
698-
SourceType::SourceFile(SourceFile {
692+
if let SourceType::SourceFile(SourceFile {
699693
implementation: Implementation { path, .. },
700694
..
701-
}) => {
702-
// we need to copy the source file to the build directory.
703-
// editor tools expects the source file in lib/bs for finding the current package
704-
// and in lib/ocaml when referencing modules in other packages
705-
let _ = std::fs::copy(
706-
Path::new(&package.path).join(path),
707-
package.get_build_path().join(path),
708-
)
709-
.expect("copying source file failed");
710-
711-
let _ = std::fs::copy(
712-
Path::new(&package.path).join(path),
713-
package
714-
.get_ocaml_build_path()
715-
.join(std::path::Path::new(path).file_name().unwrap()),
716-
)
717-
.expect("copying source file failed");
718-
}
719-
_ => (),
695+
}) = &module.source_type {
696+
// we need to copy the source file to the build directory.
697+
// editor tools expects the source file in lib/bs for finding the current package
698+
// and in lib/ocaml when referencing modules in other packages
699+
let _ = std::fs::copy(
700+
Path::new(&package.path).join(path),
701+
package.get_build_path().join(path),
702+
)
703+
.expect("copying source file failed");
704+
705+
let _ = std::fs::copy(
706+
Path::new(&package.path).join(path),
707+
package
708+
.get_ocaml_build_path()
709+
.join(std::path::Path::new(path).file_name().unwrap()),
710+
)
711+
.expect("copying source file failed");
720712
}
721713

722714
// copy js file
723715
root_package.config.get_package_specs().iter().for_each(|spec| {
724716
if spec.in_source {
725-
match &module.source_type {
726-
SourceType::SourceFile(SourceFile {
717+
if let SourceType::SourceFile(SourceFile {
727718
implementation: Implementation { path, .. },
728719
..
729-
}) => {
730-
let source = helpers::get_source_file_from_rescript_file(
731-
&Path::new(&package.path).join(path),
732-
&root_package.config.get_suffix(spec),
733-
);
734-
let destination = helpers::get_source_file_from_rescript_file(
735-
&package.get_build_path().join(path),
736-
&root_package.config.get_suffix(spec),
737-
);
738-
739-
if source.exists() {
740-
let _ =
741-
std::fs::copy(&source, &destination).expect("copying source file failed");
742-
}
720+
}) = &module.source_type {
721+
let source = helpers::get_source_file_from_rescript_file(
722+
&Path::new(&package.path).join(path),
723+
&root_package.config.get_suffix(spec),
724+
);
725+
let destination = helpers::get_source_file_from_rescript_file(
726+
&package.get_build_path().join(path),
727+
&root_package.config.get_suffix(spec),
728+
);
729+
730+
if source.exists() {
731+
let _ =
732+
std::fs::copy(&source, &destination).expect("copying source file failed");
743733
}
744-
_ => (),
745734
}
746735
}
747736
});

rewatch/src/build/compile/dependency_cycle.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ fn find_shortest_cycle(modules: &Vec<(&String, &Module)>) -> Vec<String> {
6060
}
6161

6262
// Skip nodes with no incoming edges
63-
if in_degrees.get(&start_node).map_or(true, |&d| d == 0) {
63+
if in_degrees.get(&start_node).is_none_or(|&d| d == 0) {
6464
no_cycle_cache.insert(start_node.clone());
6565
continue;
6666
}
6767

68-
if let Some(cycle) = find_cycle_bfs(&start_node, &graph, current_shortest_length) {
68+
if let Some(cycle) = find_cycle_bfs(start_node, &graph, current_shortest_length) {
6969
if shortest_cycle.is_empty() || cycle.len() < shortest_cycle.len() {
7070
shortest_cycle = cycle.clone();
7171
current_shortest_length = cycle.len();

rewatch/src/build/deps.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn get_dep_modules(
5252
.cloned()
5353
.collect();
5454

55-
return deps
55+
deps
5656
.iter()
5757
.map(|dep| {
5858
let dep_first = dep.split('.').next().unwrap();
@@ -101,7 +101,7 @@ fn get_dep_modules(
101101

102102
true
103103
})
104-
.collect::<AHashSet<String>>();
104+
.collect::<AHashSet<String>>()
105105
}
106106

107107
pub fn get_deps(build_state: &mut BuildState, deleted_modules: &AHashSet<String>) {
@@ -122,7 +122,7 @@ pub fn get_deps(build_state: &mut BuildState, deleted_modules: &AHashSet<String>
122122
package.namespace.to_suffix(),
123123
package.modules.as_ref().unwrap(),
124124
all_mod,
125-
&package,
125+
package,
126126
build_state,
127127
);
128128

@@ -134,7 +134,7 @@ pub fn get_deps(build_state: &mut BuildState, deleted_modules: &AHashSet<String>
134134
package.namespace.to_suffix(),
135135
package.modules.as_ref().unwrap(),
136136
all_mod,
137-
&package,
137+
package,
138138
build_state,
139139
))
140140
}

rewatch/src/build/namespaces.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub fn gen_mlmap(
3131
// recompile in a different way but we need to put it in the file for it to
3232
// be readable.
3333

34-
let path = build_path_abs.join(format!("{}.mlmap", namespace));
34+
let path = build_path_abs.join(format!("{namespace}.mlmap"));
3535
let mut file = File::create(&path).expect("Unable to create mlmap");
3636

3737
file.write_all(b"randjbuildsystem\n")
@@ -53,7 +53,7 @@ pub fn gen_mlmap(
5353

5454
pub fn compile_mlmap(package: &packages::Package, namespace: &str, bsc_path: &Path) {
5555
let build_path_abs = package.get_build_path();
56-
let mlmap_name = format!("{}.mlmap", namespace);
56+
let mlmap_name = format!("{namespace}.mlmap");
5757
let args = vec!["-w", "-49", "-color", "always", "-no-alias-deps", &mlmap_name];
5858

5959
let _ = Command::new(bsc_path)

0 commit comments

Comments
 (0)