1
0
mirror of https://github.com/rust-lang/rustlings.git synced 2025-11-27 22:38:18 +02:00

Apply Clippy lints

This commit is contained in:
mo8it
2025-08-22 00:01:03 +02:00
parent 295ad2e4bd
commit 6ec2e194ae
3 changed files with 23 additions and 24 deletions

View File

@@ -20,10 +20,10 @@ struct ExerciseFiles {
} }
fn create_dir_if_not_exists(path: &str) -> Result<()> { fn create_dir_if_not_exists(path: &str) -> Result<()> {
if let Err(e) = create_dir(path) { if let Err(e) = create_dir(path)
if e.kind() != io::ErrorKind::AlreadyExists { && e.kind() != io::ErrorKind::AlreadyExists
return Err(Error::from(e).context(format!("Failed to create the directory {path}"))); {
} return Err(Error::from(e).context(format!("Failed to create the directory {path}")));
} }
Ok(()) Ok(())

View File

@@ -48,17 +48,17 @@ fn run_bin(
let success = cmd_runner.run_debug_bin(bin_name, output.as_deref_mut())?; let success = cmd_runner.run_debug_bin(bin_name, output.as_deref_mut())?;
if let Some(output) = output { if let Some(output) = output
if !success { && !success
// This output is important to show the user that something went wrong. {
// Otherwise, calling something like `exit(1)` in an exercise without further output // This output is important to show the user that something went wrong.
// leaves the user confused about why the exercise isn't done yet. // Otherwise, calling something like `exit(1)` in an exercise without further output
write_ansi(output, SetAttribute(Attribute::Bold)); // leaves the user confused about why the exercise isn't done yet.
write_ansi(output, SetForegroundColor(Color::Red)); write_ansi(output, SetAttribute(Attribute::Bold));
output.extend_from_slice(b"The exercise didn't run successfully (nonzero exit code)"); write_ansi(output, SetForegroundColor(Color::Red));
write_ansi(output, ResetColor); output.extend_from_slice(b"The exercise didn't run successfully (nonzero exit code)");
output.push(b'\n'); write_ansi(output, ResetColor);
} output.push(b'\n');
} }
Ok(success) Ok(success)

View File

@@ -118,8 +118,8 @@ impl<'a> ListState<'a> {
} }
fn draw_exercise_name(&self, writer: &mut MaxLenWriter, exercise: &Exercise) -> io::Result<()> { fn draw_exercise_name(&self, writer: &mut MaxLenWriter, exercise: &Exercise) -> io::Result<()> {
if !self.search_query.is_empty() { if !self.search_query.is_empty()
if let Some((pre_highlight, highlight, post_highlight)) = exercise && let Some((pre_highlight, highlight, post_highlight)) = exercise
.name .name
.find(&self.search_query) .find(&self.search_query)
.and_then(|ind| exercise.name.split_at_checked(ind)) .and_then(|ind| exercise.name.split_at_checked(ind))
@@ -127,13 +127,12 @@ impl<'a> ListState<'a> {
rest.split_at_checked(self.search_query.len()) rest.split_at_checked(self.search_query.len())
.map(|x| (pre_highlight, x.0, x.1)) .map(|x| (pre_highlight, x.0, x.1))
}) })
{ {
writer.write_str(pre_highlight)?; writer.write_str(pre_highlight)?;
writer.stdout.queue(SetForegroundColor(Color::Magenta))?; writer.stdout.queue(SetForegroundColor(Color::Magenta))?;
writer.write_str(highlight)?; writer.write_str(highlight)?;
writer.stdout.queue(SetForegroundColor(Color::Reset))?; writer.stdout.queue(SetForegroundColor(Color::Reset))?;
return writer.write_str(post_highlight); return writer.write_str(post_highlight);
}
} }
writer.write_str(exercise.name) writer.write_str(exercise.name)