Skip to content

Commit 0933ed7

Browse files
committed
tools: rustfmt
1 parent 4f8eadd commit 0933ed7

File tree

10 files changed

+2588
-98
lines changed

10 files changed

+2588
-98
lines changed

tools/merge_rust/src/main.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use std::collections::HashMap;
2-
use std::fs::{self, File};
3-
use std::path::PathBuf;
1+
use clap::Parser;
42
use rust_util::collect::FileCollector;
53
use rust_util::item_span::item_spans;
64
use serde_json;
7-
use clap::Parser;
5+
use std::collections::HashMap;
6+
use std::fs::{self, File};
7+
use std::path::PathBuf;
88

99
/// Merge updated item definitions into a Rust codebase.
1010
#[derive(Parser)]
@@ -21,8 +21,7 @@ fn main() {
2121
let new_snippet_json_path = args.new_snippets_file;
2222

2323
let new_snippets_file = File::open(&new_snippet_json_path).unwrap();
24-
let new_snippets: HashMap<String, String> =
25-
serde_json::from_reader(new_snippets_file).unwrap();
24+
let new_snippets: HashMap<String, String> = serde_json::from_reader(new_snippets_file).unwrap();
2625

2726
let mut fc = FileCollector::default();
2827
fc.parse(&src_root_path, vec![], true).unwrap();
@@ -32,7 +31,7 @@ fn main() {
3231

3332
let mut rewrites = Vec::new();
3433
for (item_path, lo, hi) in item_spans(mod_path.to_owned(), ast) {
35-
let old_snippet = &old_src[lo .. hi];
34+
let old_snippet = &old_src[lo..hi];
3635
let item_path_str = item_path.join("::");
3736
if let Some(new_snippet) = new_snippets.get(&item_path_str) {
3837
if new_snippet != old_snippet {
@@ -49,9 +48,15 @@ fn main() {
4948
let mut new_src = String::with_capacity(old_src.len());
5049
let mut pos = 0;
5150
for &(lo, hi, new_snippet) in &rewrites {
52-
assert!(lo >= pos, "overlapping rewrites: previous rewrite ended at {}, \
53-
but current rewrite covers {} .. {}", pos, lo, hi);
54-
new_src.push_str(&old_src[pos .. lo]);
51+
assert!(
52+
lo >= pos,
53+
"overlapping rewrites: previous rewrite ended at {}, \
54+
but current rewrite covers {} .. {}",
55+
pos,
56+
lo,
57+
hi
58+
);
59+
new_src.push_str(&old_src[pos..lo]);
5560
new_src.push_str(new_snippet);
5661
pos = hi;
5762
}

0 commit comments

Comments
 (0)