mirror of
https://github.com/rust-lang/rustlings.git
synced 2025-08-24 19:49:25 +02:00
Apply Clippy lints
This commit is contained in:
@@ -20,10 +20,10 @@ struct ExerciseFiles {
|
||||
}
|
||||
|
||||
fn create_dir_if_not_exists(path: &str) -> Result<()> {
|
||||
if let Err(e) = create_dir(path) {
|
||||
if e.kind() != io::ErrorKind::AlreadyExists {
|
||||
return Err(Error::from(e).context(format!("Failed to create the directory {path}")));
|
||||
}
|
||||
if let Err(e) = create_dir(path)
|
||||
&& e.kind() != io::ErrorKind::AlreadyExists
|
||||
{
|
||||
return Err(Error::from(e).context(format!("Failed to create the directory {path}")));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@@ -48,17 +48,17 @@ fn run_bin(
|
||||
|
||||
let success = cmd_runner.run_debug_bin(bin_name, output.as_deref_mut())?;
|
||||
|
||||
if let Some(output) = output {
|
||||
if !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
|
||||
// leaves the user confused about why the exercise isn't done yet.
|
||||
write_ansi(output, SetAttribute(Attribute::Bold));
|
||||
write_ansi(output, SetForegroundColor(Color::Red));
|
||||
output.extend_from_slice(b"The exercise didn't run successfully (nonzero exit code)");
|
||||
write_ansi(output, ResetColor);
|
||||
output.push(b'\n');
|
||||
}
|
||||
if let Some(output) = output
|
||||
&& !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
|
||||
// leaves the user confused about why the exercise isn't done yet.
|
||||
write_ansi(output, SetAttribute(Attribute::Bold));
|
||||
write_ansi(output, SetForegroundColor(Color::Red));
|
||||
output.extend_from_slice(b"The exercise didn't run successfully (nonzero exit code)");
|
||||
write_ansi(output, ResetColor);
|
||||
output.push(b'\n');
|
||||
}
|
||||
|
||||
Ok(success)
|
||||
|
@@ -118,8 +118,8 @@ impl<'a> ListState<'a> {
|
||||
}
|
||||
|
||||
fn draw_exercise_name(&self, writer: &mut MaxLenWriter, exercise: &Exercise) -> io::Result<()> {
|
||||
if !self.search_query.is_empty() {
|
||||
if let Some((pre_highlight, highlight, post_highlight)) = exercise
|
||||
if !self.search_query.is_empty()
|
||||
&& let Some((pre_highlight, highlight, post_highlight)) = exercise
|
||||
.name
|
||||
.find(&self.search_query)
|
||||
.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())
|
||||
.map(|x| (pre_highlight, x.0, x.1))
|
||||
})
|
||||
{
|
||||
writer.write_str(pre_highlight)?;
|
||||
writer.stdout.queue(SetForegroundColor(Color::Magenta))?;
|
||||
writer.write_str(highlight)?;
|
||||
writer.stdout.queue(SetForegroundColor(Color::Reset))?;
|
||||
return writer.write_str(post_highlight);
|
||||
}
|
||||
{
|
||||
writer.write_str(pre_highlight)?;
|
||||
writer.stdout.queue(SetForegroundColor(Color::Magenta))?;
|
||||
writer.write_str(highlight)?;
|
||||
writer.stdout.queue(SetForegroundColor(Color::Reset))?;
|
||||
return writer.write_str(post_highlight);
|
||||
}
|
||||
|
||||
writer.write_str(exercise.name)
|
||||
|
Reference in New Issue
Block a user