Skip to content

Commit 6701ecf

Browse files
authored
chore: additional clippy fixes (#661)
1 parent 8cca145 commit 6701ecf

9 files changed

Lines changed: 22 additions & 23 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ jobs:
336336

337337
- name: Clippy check
338338
if: matrix.rust-version == 'stable'
339-
run: cargo clippy --all-features --all-targets
339+
run: cargo clippy --workspace --all-features --all-targets
340340

341341
# Check for unneeded dependencies.
342342
check-deps:

brush-core/src/builtins/exit.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@ impl builtins::Command for ExitCommand {
1414
&self,
1515
context: commands::ExecutionContext<'_>,
1616
) -> Result<crate::builtins::ExitCode, crate::error::Error> {
17-
let code_8bit: u8;
18-
1917
#[expect(clippy::cast_sign_loss)]
20-
if let Some(code_32bit) = &self.code {
21-
code_8bit = (code_32bit & 0xFF) as u8;
18+
let code_8bit = if let Some(code_32bit) = &self.code {
19+
(code_32bit & 0xFF) as u8
2220
} else {
23-
code_8bit = context.shell.last_exit_status;
24-
}
21+
context.shell.last_exit_status
22+
};
2523

2624
Ok(builtins::ExitCode::ExitShell(code_8bit))
2725
}

brush-core/src/builtins/return_.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ impl builtins::Command for ReturnCommand {
1515
&self,
1616
context: commands::ExecutionContext<'_>,
1717
) -> Result<crate::builtins::ExitCode, crate::error::Error> {
18-
let code_8bit: u8;
1918
#[expect(clippy::cast_sign_loss)]
20-
if let Some(code_32bit) = &self.code {
21-
code_8bit = (code_32bit & 0xFF) as u8;
19+
let code_8bit = if let Some(code_32bit) = &self.code {
20+
(code_32bit & 0xFF) as u8
2221
} else {
23-
code_8bit = context.shell.last_exit_status;
24-
}
22+
context.shell.last_exit_status
23+
};
2524

2625
if context.shell.in_function() || context.shell.in_sourced_script() {
2726
Ok(builtins::ExitCode::ReturnFromFunctionOrScript(code_8bit))

brush-core/src/builtins/set.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ impl builtins::Command for SetCommand {
186186
}
187187

188188
#[expect(clippy::too_many_lines)]
189+
#[allow(clippy::useless_let_if_seq)]
189190
async fn execute(
190191
&self,
191192
context: commands::ExecutionContext<'_>,

brush-core/src/completion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ impl Spec {
395395
CompleteAction::Alias => {
396396
for name in shell.aliases.keys() {
397397
if name.starts_with(token) {
398-
candidates.insert(name.to_string());
398+
candidates.insert(name.clone());
399399
}
400400
}
401401
}

brush-core/src/shell.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ impl Shell {
540540
shell
541541
.history
542542
.as_ref()
543-
.map_or("0".into(), |h| h.count().to_string().into())
543+
.map_or_else(|| "0".into(), |h| h.count().to_string().into())
544544
},
545545
setter: |_| (),
546546
});

brush-core/src/variables.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ impl ShellVariable {
430430
new_value.push_str(value.as_str());
431431
}
432432

433-
arr.insert(array_index, new_value.to_string());
433+
arr.insert(array_index, new_value.clone());
434434
} else {
435435
arr.insert(array_index, value);
436436
}

brush-parser/src/error.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub enum ParseError {
2323
}
2424

2525
#[cfg(feature = "diagnostics")]
26+
#[allow(clippy::cast_sign_loss)]
2627
pub mod miette {
2728
use super::ParseError;
2829
use miette::SourceOffset;
@@ -32,15 +33,15 @@ pub mod miette {
3233
pub fn to_pretty_error(self, input: impl Into<String>) -> PrettyError {
3334
let input = input.into();
3435
let location = match self {
35-
ParseError::ParsingNearToken(ref token) => Some(SourceOffset::from_location(
36+
Self::ParsingNearToken(ref token) => Some(SourceOffset::from_location(
3637
&input,
3738
token.location().start.line as usize,
3839
token.location().start.column as usize,
3940
)),
40-
ParseError::Tokenizing { ref position, .. } => position.as_ref().map(|p| {
41+
Self::Tokenizing { ref position, .. } => position.as_ref().map(|p| {
4142
SourceOffset::from_location(&input, p.line as usize, p.column as usize)
4243
}),
43-
ParseError::ParsingAtEndOfInput => {
44+
Self::ParsingAtEndOfInput => {
4445
Some(SourceOffset::from_location(&input, usize::MAX, usize::MAX))
4546
}
4647
};

xtask/src/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ enum DocsCommand {
3131

3232
#[derive(Parser)]
3333
enum CompletionCommand {
34-
/// Generate completion script for bash.
34+
/// Generate completion script for `bash`.
3535
Bash,
36-
/// Generate completion script for elvish.
36+
/// Generate completion script for `elvish`.
3737
Elvish,
38-
/// Generate completion script for fish.
38+
/// Generate completion script for `fish`.
3939
Fish,
40-
/// Generate completion script for PowerShell.
40+
/// Generate completion script for `PowerShell`.
4141
PowerShell,
42-
/// Generate completion script for zsh.
42+
/// Generate completion script for `zsh`.
4343
Zsh,
4444
}
4545

0 commit comments

Comments
 (0)