aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ansi/mod.rs10
-rw-r--r--src/completion.rs2
-rw-r--r--src/main.rs16
-rw-r--r--src/parse/mod.rs17
-rw-r--r--src/run/builtin.rs34
-rw-r--r--src/run/mod.rs11
6 files changed, 45 insertions, 45 deletions
diff --git a/src/ansi/mod.rs b/src/ansi/mod.rs
index 020713a..7a38ae4 100644
--- a/src/ansi/mod.rs
+++ b/src/ansi/mod.rs
@@ -24,10 +24,10 @@ pub fn read(debug: bool) -> Option<KbInput<'static>> {
}
println!("{}\r", kb.as_bytes().escape_ascii());
}
- if let KbInput::InvalidEscape(x) = &kb {
- if x.len() == 1 {
- break Some(KbInput::Key([x[0]]));
- }
+ if let KbInput::InvalidEscape(x) = &kb
+ && x.len() == 1
+ {
+ break Some(KbInput::Key([x[0]]));
}
break Some(kb);
}
@@ -172,7 +172,7 @@ fn trie_from_words(words: Vec<(&'static str, &[u8])>) -> EscapeTrie {
let mut all_empty = true;
for (key, val) in words.iter() {
- if let Some(byte) = val.get(0) {
+ if let Some(byte) = val.first() {
all_empty = false;
tree.entry(byte)
.or_insert_with(Vec::new)
diff --git a/src/completion.rs b/src/completion.rs
index 2913dba..1466814 100644
--- a/src/completion.rs
+++ b/src/completion.rs
@@ -185,7 +185,7 @@ impl CompletionResult {
pub fn completion(session: Arc<Mutex<Session>>, cmd: &[u8]) -> CompletionResult {
let comp = parse::completion_context(
- &cmd,
+ cmd,
&mut crate::run::Executor::new_for_completion(session.clone()),
);
diff --git a/src/main.rs b/src/main.rs
index fc44fa5..89b2e64 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -13,14 +13,14 @@ fn main() {
// it is quite annoying when the terminal window closes due to a crash, so let's just catch all panics
loop {
let res = std::panic::catch_unwind(pish::event_loop);
- match res {
- Ok(_) => break,
- Err(_) => {
- #[cfg(debug_assertions)]
- unsafe {
- pish::reload::continue_reload()
- }
- }
+
+ if res.is_ok() {
+ break;
+ }
+
+ #[cfg(debug_assertions)]
+ unsafe {
+ pish::reload::continue_reload()
}
// prevent incredibly fast panic loops
diff --git a/src/parse/mod.rs b/src/parse/mod.rs
index 2c578cb..e197000 100644
--- a/src/parse/mod.rs
+++ b/src/parse/mod.rs
@@ -26,6 +26,7 @@ impl Stage for PostExpansion {
type Res<T, E> = std::result::Result<T, E>;
+#[allow(clippy::type_complexity)]
pub trait Expander {
type Error;
fn expand_var(&mut self, v: BString, default: Option<BString>) -> Res<BString, Self::Error>;
@@ -696,7 +697,7 @@ impl StringDelimiter {
return None;
}
- let ident = peek_ident(&b.buf);
+ let ident = peek_ident(b.buf);
if b.buf[ident.len()..].starts_with(b"\"\"\"") {
b.advance(ident.len() + 3);
if b.has() && b.peek() == b'\n' {
@@ -754,13 +755,13 @@ impl StringDelimiter {
true
}
StringDelimiter::InterpCustom(delim)
- if buf.len() >= 3 && &buf[..3] == b"\"\"\"" && buf[3..].starts_with(&delim) =>
+ if buf.len() >= 3 && &buf[..3] == b"\"\"\"" && buf[3..].starts_with(delim) =>
{
b.advance(3 + delim.len());
true
}
StringDelimiter::StrictCustom(delim)
- if buf.len() >= 3 && &buf[..3] == b"'''" && buf[3..].starts_with(&delim) =>
+ if buf.len() >= 3 && &buf[..3] == b"'''" && buf[3..].starts_with(delim) =>
{
b.advance(3 + delim.len());
true
@@ -825,11 +826,11 @@ impl StringDelimiter {
StringDelimiter::Interp => out.push(b'"'),
StringDelimiter::Strict => out.push(b'\''),
StringDelimiter::InterpCustom(delim) => {
- out.push_all(&delim);
+ out.push_all(delim);
out.push_all(b"\"\"\"");
}
StringDelimiter::StrictCustom(delim) => {
- out.push_all(&delim);
+ out.push_all(delim);
out.push_all(b"'''");
}
}
@@ -842,11 +843,11 @@ impl StringDelimiter {
StringDelimiter::Strict => out.push(b'\''),
StringDelimiter::InterpCustom(delim) => {
out.push_all(b"\"\"\"");
- out.push_all(&delim);
+ out.push_all(delim);
}
StringDelimiter::StrictCustom(delim) => {
out.push_all(b"'''");
- out.push_all(&delim);
+ out.push_all(delim);
}
}
}
@@ -1075,7 +1076,7 @@ impl Command<PreExpansion> {
while self.cmd.parts.len() == 1
&& let StringPart::Boring(s) = &self.cmd.parts[0]
{
- if let Some((new_age, exp)) = e.expand_alias(&s, age.take())? {
+ if let Some((new_age, exp)) = e.expand_alias(s, age.take())? {
age = Some(new_age);
self.cmd = exp.first().unwrap().clone();
for e in exp.into_iter().skip(1).rev() {
diff --git a/src/run/builtin.rs b/src/run/builtin.rs
index b731b10..044206d 100644
--- a/src/run/builtin.rs
+++ b/src/run/builtin.rs
@@ -187,7 +187,7 @@ impl Builtin for _type {
) -> Result {
let session = session.lock().unwrap();
for arg in args {
- if session.aliases.get(&arg, AliasAge::MAX).is_some() {
+ if session.aliases.get(arg, AliasAge::MAX).is_some() {
// TODO: tell what it is aliased to
writeln!(stdout, "{} is an alias", String::from_utf8_lossy(arg))?;
continue;
@@ -383,7 +383,7 @@ impl Builtin for completion {
stdout: &mut dyn Write,
) -> Result {
for arg in args {
- let c = crate::completion(session.clone(), &arg);
+ let c = crate::completion(session.clone(), arg);
write!(stdout, "{:?} ", c.kind)?;
stdout.write_all(&c.shared_prefix)?;
for s in c.suggestions {
@@ -581,7 +581,7 @@ impl bind {
fn is_interactive(args: &[BString]) -> bool {
matches!(
- args.get(0).map(|x| &x[..]),
+ args.first().map(|x| &x[..]),
Some(b"i" | b"interactive" | b"del" | b"delete")
)
}
@@ -616,7 +616,7 @@ impl Builtin for bind {
Err(Error::Exit(1))
};
- if args.len() == 0 {
+ if args.is_empty() {
let mut dump = |map: &HashMap<BString, crate::parse::Command<PostExpansion>>,
category: &str|
-> std::io::Result<()> {
@@ -639,10 +639,6 @@ impl Builtin for bind {
return Ok(());
}
- if args.len() < 1 {
- return usage();
- }
-
let kind = &args[0];
let mut se = session.lock().unwrap();
@@ -701,7 +697,7 @@ impl Builtin for bind {
// print what gets bound
write!(stdout, "bind {x} ")?;
for arg in args.iter().skip(1) {
- stdout.write(&arg[..])?;
+ stdout.write_all(&arg[..])?;
write!(stdout, " ")?;
}
writeln!(stdout)?;
@@ -728,22 +724,22 @@ impl Builtin for exit {
}
fn special(&mut self, _session: Arc<Mutex<Session>>, args: &[BString]) {
- let exit_code: i32 = loop {
- let Some(arg) = args.get(0) else {
- break 0;
+ fn parse_exit_code(x: Option<&BString>) -> i32 {
+ let Some(arg) = x else {
+ return 0;
};
let Ok(arg) = String::from_utf8(arg.clone()) else {
- break 1;
+ return 1;
};
let Ok(num) = arg.parse() else {
- break 1;
+ return 1;
};
- break num;
- };
+ num
+ }
println!("bye!\r");
- std::process::exit(exit_code);
+ std::process::exit(parse_exit_code(args.first()));
}
fn io(
@@ -772,7 +768,7 @@ impl Builtin for ct {
_stdin: &mut dyn Read,
_stdout: &mut dyn Write,
) -> Result {
- let Some(arg) = args.get(0) else {
+ let Some(arg) = args.first() else {
return Err(Error::Exit(-1));
};
@@ -933,7 +929,7 @@ impl Builtin for export {
) -> Result {
let mut session = session.lock().unwrap();
for v in args.iter() {
- session.vars.allow_export(&v, true);
+ session.vars.allow_export(v, true);
}
Ok(())
}
diff --git a/src/run/mod.rs b/src/run/mod.rs
index 8be5fca..b3ed851 100644
--- a/src/run/mod.rs
+++ b/src/run/mod.rs
@@ -562,10 +562,7 @@ impl Aliases {
}
fn get(&self, name: &bstr, older_than: AliasAge) -> Option<(AliasAge, AliasBody)> {
- let Some(alias_set) = self.aliases.get(name) else {
- return None;
- };
-
+ let alias_set = self.aliases.get(name)?;
alias_set.iter().rev().find(|e| e.0 < older_than).cloned()
}
@@ -574,6 +571,12 @@ impl Aliases {
}
}
+impl Default for Aliases {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
fn exec(se: Arc<Mutex<Session>>, ast: Ast<PreExpansion>) -> Result<(), ExecError> {
let mut exec = Executor::new(se.clone());
let ast = ast.expand(&mut exec)?;