Skip to content

Commit

Permalink
Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
neunenak committed Jun 27, 2023
1 parent 3814867 commit b8e1ba2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
20 changes: 7 additions & 13 deletions src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl Loader {
}
}

pub(crate) fn load_and_compile<'src>(&'src self, path: &Path) -> RunResult<Compilation> {
pub(crate) fn load_and_compile(&self, path: &Path) -> RunResult<Compilation> {
let root_src = self.load_and_alloc(path)?;
let root_ast = Compiler::parse(root_src)?;
let root_imports = Analyzer::get_imports(&root_ast);
Expand Down Expand Up @@ -46,29 +46,23 @@ impl Loader {
let mut imported_asts = vec![];

let mut seen: HashSet<PathBuf> = HashSet::new();
seen.insert(Self::canonicalize_path(&root_path, &root_path)?);
seen.insert(Self::canonicalize_path(root_path, root_path)?);

let mut queue: VecDeque<(PathBuf, Vec<Import>)> = VecDeque::new();
queue.push_back((root_path.to_owned(), root_imports));

loop {
let (cur_path, imports) = match queue.pop_front() {
Some(item) => item,
None => break,
};

for mut import in imports.into_iter() {
while let Some((cur_path, imports)) = queue.pop_front() {
for mut import in imports {
let given_path = import.path();
let canonical_path = Self::canonicalize_path(&given_path, &cur_path)?;
let canonical_path = Self::canonicalize_path(given_path, &cur_path)?;

if seen.contains(&canonical_path) {
return Err(Error::CircularInclude {
current: cur_path.to_owned(),
current: cur_path,
include: canonical_path,
});
} else {
seen.insert(canonical_path.clone());
}
seen.insert(canonical_path.clone());

let src = self.load_and_alloc(&canonical_path)?;
let ast = Compiler::parse(src)?;
Expand Down
9 changes: 5 additions & 4 deletions src/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ pub fn summary(path: &Path) -> Result<Result<Summary, String>, io::Error> {

match loader.load_and_compile(path) {
Ok(compilation) => Ok(Ok(Summary::new(compilation.justfile()))),
Err(error) => Ok(Err(match error {
Error::Compile { compile_error } => compile_error.to_string(),
_ => format!("{:?}", error),
Err(error) => Ok(Err(if let Error::Compile { compile_error } = error {
compile_error.to_string()
} else {
format!("{error:?}")
})),
}
}
Expand Down Expand Up @@ -61,7 +62,7 @@ impl Summary {
.iter()
.map(|(name, recipe)| {
(
name.to_string(),
(*name).to_string(),
Recipe::new(recipe, aliases.remove(name).unwrap_or_default()),
)
})
Expand Down
2 changes: 0 additions & 2 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,6 @@ impl Test {
}

if let Some(ref stderr_regex) = self.stderr_regex {
println!("AAAA:\n{}", output_stderr);
println!("{:?}", stderr_regex);
if !stderr_regex.is_match(output_stderr) {
panic!("Stderr regex mismatch:\n{output_stderr:?}\n!~=\n/{stderr_regex:?}/");
}
Expand Down

0 comments on commit b8e1ba2

Please sign in to comment.