Skip to content

Commit 9cd1824

Browse files
authored
Merge pull request #248 from seddonym/cargo-fmt
Cargo fmt
2 parents e7e1d8d + 167e6e9 commit 9cd1824

4 files changed

Lines changed: 42 additions & 33 deletions

File tree

.github/workflows/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ jobs:
4848
toolchain: stable
4949
- name: Print versions
5050
run: cargo version --verbose && cargo clippy --version
51+
- name: Check formatting
52+
run: cargo fmt --check
53+
working-directory: ./rust
5154
- name: Run tests
5255
run: cargo test --no-default-features
5356
working-directory: ./rust

rust/src/filesystem.rs

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ use std::path::{Path, PathBuf};
99
use std::sync::LazyLock;
1010
use unindent::unindent;
1111

12-
13-
static ENCODING_RE: LazyLock<Regex> = LazyLock::new(|| {
14-
Regex::new(r"^[ \t\f]*#.*?coding[:=][ \t]*([-_.a-zA-Z0-9]+)").unwrap()
15-
});
12+
static ENCODING_RE: LazyLock<Regex> =
13+
LazyLock::new(|| Regex::new(r"^[ \t\f]*#.*?coding[:=][ \t]*([-_.a-zA-Z0-9]+)").unwrap());
1614

1715
pub trait FileSystem: Send + Sync {
1816
fn sep(&self) -> &str;
@@ -47,7 +45,9 @@ impl FileSystem for RealBasicFileSystem {
4745
for component in components {
4846
path.push(component);
4947
}
50-
path.to_str().expect("Path components should be valid unicode").to_string()
48+
path.to_str()
49+
.expect("Path components should be valid unicode")
50+
.to_string()
5151
}
5252

5353
fn split(&self, file_name: &str) -> (String, String) {
@@ -66,8 +66,12 @@ impl FileSystem for RealBasicFileSystem {
6666
};
6767

6868
(
69-
head.to_str().expect("Path components should be valid unicode").to_string(),
70-
tail.to_str().expect("Path components should be valid unicode").to_string(),
69+
head.to_str()
70+
.expect("Path components should be valid unicode")
71+
.to_string(),
72+
tail.to_str()
73+
.expect("Path components should be valid unicode")
74+
.to_string(),
7175
)
7276
}
7377

@@ -88,17 +92,17 @@ impl FileSystem for RealBasicFileSystem {
8892
})?;
8993

9094
let s = String::from_utf8_lossy(&bytes);
91-
9295

9396
let mut detected_encoding: Option<String> = None;
9497

9598
// Coding specification needs to be in the first two lines, or it's ignored.
9699
for line in s.lines().take(2) {
97100
if let Some(captures) = ENCODING_RE.captures(line)
98-
&& let Some(encoding_name) = captures.get(1) {
99-
detected_encoding = Some(encoding_name.as_str().to_string());
100-
break;
101-
}
101+
&& let Some(encoding_name) = captures.get(1)
102+
{
103+
detected_encoding = Some(encoding_name.as_str().to_string());
104+
break;
105+
}
102106
}
103107

104108
if let Some(enc_name) = detected_encoding {
@@ -217,8 +221,12 @@ impl FileSystem for FakeBasicFileSystem {
217221
tail = path.file_name().unwrap_or(OsStr::new(""));
218222
}
219223
(
220-
head.to_str().expect("Path components should be valid unicode").to_string(),
221-
tail.to_str().expect("Path components should be valid unicode").to_string(),
224+
head.to_str()
225+
.expect("Path components should be valid unicode")
226+
.to_string(),
227+
tail.to_str()
228+
.expect("Path components should be valid unicode")
229+
.to_string(),
222230
)
223231
}
224232

@@ -230,7 +238,9 @@ impl FileSystem for FakeBasicFileSystem {
230238
fn read(&self, file_name: &str) -> PyResult<String> {
231239
match self.contents.get(file_name) {
232240
Some(file_name) => Ok(file_name.clone()),
233-
None => Err(PyFileNotFoundError::new_err(format!("No such file: {file_name}"))),
241+
None => Err(PyFileNotFoundError::new_err(format!(
242+
"No such file: {file_name}"
243+
))),
234244
}
235245
}
236246
}
@@ -267,11 +277,11 @@ impl PyFakeBasicFileSystem {
267277
fn read(&self, file_name: &str) -> PyResult<String> {
268278
self.inner.read(file_name)
269279
}
270-
280+
271281
// Temporary workaround method for Python tests.
272282
fn convert_to_basic(&self) -> PyResult<Self> {
273283
Ok(PyFakeBasicFileSystem {
274-
inner: self.inner.clone()
284+
inner: self.inner.clone(),
275285
})
276286
}
277287
}
@@ -354,7 +364,10 @@ pub fn parse_indented_file_system_string(file_system_string: &str) -> HashMap<St
354364
// Edge case: If the very first line was a file and it ended up on the stack, it needs to be processed.
355365
// This handles single-file inputs like "myfile.txt"
356366
if !path_stack.is_empty()
357-
&& !path_stack.last().expect("path_stack should be non-empty").ends_with('/')
367+
&& !path_stack
368+
.last()
369+
.expect("path_stack should be non-empty")
370+
.ends_with('/')
358371
&& !file_paths_map.contains_key(&path_stack.join("/"))
359372
{
360373
file_paths_map.insert(path_stack.join("/"), String::new());

rust/src/graph/mod.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,12 @@ pub mod import_chain_queries;
1515

1616
pub(crate) mod pathfinding;
1717

18-
static MODULE_NAMES: LazyLock<RwLock<StringInterner<StringBackend>>> = LazyLock::new(|| {
19-
RwLock::new(StringInterner::default())
20-
});
21-
static IMPORT_LINE_CONTENTS: LazyLock<RwLock<StringInterner<StringBackend>>> = LazyLock::new(|| {
22-
RwLock::new(StringInterner::default())
23-
});
24-
static EMPTY_MODULE_TOKENS: LazyLock<FxHashSet<ModuleToken>> = LazyLock::new(|| {
25-
FxHashSet::default()
26-
});
27-
static EMPTY_IMPORT_DETAILS: LazyLock<FxHashSet<ImportDetails>> = LazyLock::new(|| {
28-
FxHashSet::default()
29-
});
18+
static MODULE_NAMES: LazyLock<RwLock<StringInterner<StringBackend>>> =
19+
LazyLock::new(|| RwLock::new(StringInterner::default()));
20+
static IMPORT_LINE_CONTENTS: LazyLock<RwLock<StringInterner<StringBackend>>> =
21+
LazyLock::new(|| RwLock::new(StringInterner::default()));
22+
static EMPTY_MODULE_TOKENS: LazyLock<FxHashSet<ModuleToken>> = LazyLock::new(FxHashSet::default);
23+
static EMPTY_IMPORT_DETAILS: LazyLock<FxHashSet<ImportDetails>> = LazyLock::new(FxHashSet::default);
3024

3125
new_key_type! { pub struct ModuleToken; }
3226

rust/src/module_expressions.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ use std::fmt::Display;
66
use std::str::FromStr;
77
use std::sync::LazyLock;
88

9-
static MODULE_EXPRESSION_PATTERN: LazyLock<Regex> = LazyLock::new(|| {
10-
Regex::new(r"^(\w+|\*{1,2})(\.(\w+|\*{1,2}))*$").unwrap()
11-
});
9+
static MODULE_EXPRESSION_PATTERN: LazyLock<Regex> =
10+
LazyLock::new(|| Regex::new(r"^(\w+|\*{1,2})(\.(\w+|\*{1,2}))*$").unwrap());
1211

1312
/// A module expression is used to refer to sets of modules.
1413
///

0 commit comments

Comments
 (0)