aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/ansi/mod.rs6
-rw-r--r--src/line/mod.rs6
-rw-r--r--src/parse/mod.rs23
-rw-r--r--src/parse/regex/byte_range.rs10
-rw-r--r--src/parse/regex/dfa.rs3
-rw-r--r--src/parse/regex/enfa.rs1
-rw-r--r--src/parse/span.rs16
-rw-r--r--src/run/builtin.rs12
-rw-r--r--src/run/mod.rs2
-rw-r--r--src/run/var/mod.rs2
-rw-r--r--src/syntax_highlighting.rs6
11 files changed, 51 insertions, 36 deletions
diff --git a/src/ansi/mod.rs b/src/ansi/mod.rs
index 4265b45..95966da 100644
--- a/src/ansi/mod.rs
+++ b/src/ansi/mod.rs
@@ -119,6 +119,12 @@ impl TerminalInput {
}
}
+impl Default for TerminalInput {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
// expecting a string of the form `\x1b[n;mR`
fn try_parse_cursor_position_message(mut msg: &[u8]) -> Option<CursorPos> {
if !msg.starts_with(b"\x1b[") || !msg.ends_with(b"R") {
diff --git a/src/line/mod.rs b/src/line/mod.rs
index 6e24f14..6fb6d63 100644
--- a/src/line/mod.rs
+++ b/src/line/mod.rs
@@ -156,6 +156,12 @@ impl Line {
}
}
+impl Default for Line {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
macro_rules! mutating_impls {
($(pub fn $fun:ident(&mut $self:ident $($arg:tt)*) -> $ty:ty $body:block )*) => {
impl Line {$(
diff --git a/src/parse/mod.rs b/src/parse/mod.rs
index e7a2d1d..b3855a8 100644
--- a/src/parse/mod.rs
+++ b/src/parse/mod.rs
@@ -1382,11 +1382,11 @@ impl HighlightKind {
/// all highlight kind variants *except* None
pub fn variants() -> impl Iterator<Item = HighlightKind> {
let a = Keyword::VARIANTS
- .into_iter()
+ .iter()
.cloned()
.map(HighlightKind::Keyword);
let b = OtherHighlights::VARIANTS
- .into_iter()
+ .iter()
.cloned()
.map(HighlightKind::Other);
a.chain(b)
@@ -1405,7 +1405,7 @@ impl HighlightKind {
match ident {
b"keywords" => {
return Keyword::VARIANTS
- .into_iter()
+ .iter()
.cloned()
.map(HighlightKind::Keyword)
.collect();
@@ -1421,15 +1421,14 @@ impl HighlightKind {
}
Self::variants()
- .into_iter()
.filter(|x| x.identifier() == ident)
.collect()
}
pub fn all_identifiers() -> Vec<BString> {
- let kw = Keyword::VARIANTS.into_iter().map(Keyword::identifier);
+ let kw = Keyword::VARIANTS.iter().map(Keyword::identifier);
let ot = OtherHighlights::VARIANTS
- .into_iter()
+ .iter()
.map(OtherHighlights::identifier);
let groups = [&b"keywords"[..], b"braces", b"all", b"everything"];
kw.chain(ot)
@@ -1650,13 +1649,11 @@ impl<'a> Cursor<'a> {
self.buf = &self.buf[bytes.len() + 1..];
self.spaces();
Ok(())
+ } else if self.is_completion() && self.buf.len() == bytes.len() {
+ self.buf = &self.buf[bytes.len()..];
+ Ok(())
} else {
- if self.is_completion() && self.buf.len() == bytes.len() {
- self.buf = &self.buf[bytes.len()..];
- Ok(())
- } else {
- Err(ParseError::ExpectedKeyword(kw))
- }
+ Err(ParseError::ExpectedKeyword(kw))
}
} else {
self.buf = &self.buf[bytes.len()..];
@@ -1931,7 +1928,7 @@ impl Parse for Case<PreExpansion> {
let mut branches = Vec::new();
loop {
b.spaces();
- if let Ok(_) = b.consume_keyword(Keyword::CloseBrace) {
+ if b.consume_keyword(Keyword::CloseBrace).is_ok() {
break;
}
branches.push(CaseBranch::parse(b)?);
diff --git a/src/parse/regex/byte_range.rs b/src/parse/regex/byte_range.rs
index 1ca6d8f..86b2c2b 100644
--- a/src/parse/regex/byte_range.rs
+++ b/src/parse/regex/byte_range.rs
@@ -49,11 +49,11 @@ impl ByteRange {
let mut out = Vec::new();
for (mut loc, delta) in edges {
- if let Some(last) = last {
- if last <= loc {
- out.push(ByteRange::new_range(last, loc));
- loc = loc + 1;
- }
+ if let Some(last) = last
+ && last <= loc
+ {
+ out.push(ByteRange::new_range(last, loc));
+ loc += 1;
}
depth += delta;
diff --git a/src/parse/regex/dfa.rs b/src/parse/regex/dfa.rs
index aba6238..7e5be7b 100644
--- a/src/parse/regex/dfa.rs
+++ b/src/parse/regex/dfa.rs
@@ -14,6 +14,7 @@ pub struct State {
accept: bool,
}
+#[allow(clippy::upper_case_acronyms)]
pub struct DFA {
start: StateId,
states: Vec<State>,
@@ -94,7 +95,7 @@ impl From<ENFA> for DFA {
.collect();
for ms in multi_states.iter() {
- let i: usize = multi_to_dfa[&ms];
+ let i: usize = multi_to_dfa[ms];
states[i].accept = ms.accept();
for t in ms.possible_transitions() {
let k = multi_to_dfa[&ms.transition(t)];
diff --git a/src/parse/regex/enfa.rs b/src/parse/regex/enfa.rs
index 71998c9..3809595 100644
--- a/src/parse/regex/enfa.rs
+++ b/src/parse/regex/enfa.rs
@@ -8,6 +8,7 @@ use super::byte_range::ByteRange;
/// NFA with epsilon transitions
#[derive(Clone)]
+#[allow(clippy::upper_case_acronyms)]
pub struct ENFA {
pub states: Vec<EState>,
}
diff --git a/src/parse/span.rs b/src/parse/span.rs
index 340a078..671c10d 100644
--- a/src/parse/span.rs
+++ b/src/parse/span.rs
@@ -22,6 +22,12 @@ impl FileId {
}
}
+impl Default for FileId {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
#[derive(Copy, Clone)]
pub struct SpanFrom {
pub file: FileId,
@@ -52,15 +58,7 @@ pub struct Span {
/// manual implementation of PartialOrd to ensure shorter Spans are first
impl PartialOrd for Span {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
- match self.file.partial_cmp(&other.file) {
- Some(core::cmp::Ordering::Equal) => {}
- ord => return ord,
- }
- match self.start.partial_cmp(&other.start) {
- Some(core::cmp::Ordering::Equal) => {}
- ord => return ord,
- }
- other.end.partial_cmp(&self.end)
+ Some(self.cmp(other))
}
}
diff --git a/src/run/builtin.rs b/src/run/builtin.rs
index 6f7cc5d..f3682f7 100644
--- a/src/run/builtin.rs
+++ b/src/run/builtin.rs
@@ -187,7 +187,7 @@ impl Builtin for _type {
let session = session.lock().unwrap();
for arg in args {
if let Some((_, a)) = session.aliases.get(arg, AliasAge::MAX) {
- stdout.write_all(&arg)?;
+ stdout.write_all(arg)?;
stdout.write_all(b" is aliased to ")?;
stdout.write_all(&a.unparsed)?;
stdout.write_all(b"\n")?;
@@ -385,7 +385,7 @@ impl Builtin for parse {
}
Err(e) => {
writeln!(stdout, "err {e:?} ")?;
- stdout.write_all(&c.remaining())?;
+ stdout.write_all(c.remaining())?;
}
}
}
@@ -508,7 +508,7 @@ impl Builtin for alias {
}
Err(err) => {
writeln!(stdout, "alias: unparseable argument ({err:?}): ",)?;
- stdout.write_all(&arg)?;
+ stdout.write_all(arg)?;
parse_fail = true;
}
}
@@ -525,7 +525,7 @@ impl Builtin for alias {
if !a.is_empty() {
a.push(b' ');
}
- a.push_all(&b);
+ a.push_all(b);
a
}),
parsed: alias_args,
@@ -995,7 +995,7 @@ impl Builtin for pish_theme {
stdout.write_all(b" ")?;
}
stdout.write_all(b"\n")?;
- return Err(Error::Exit(-1));
+ Err(Error::Exit(-1))
};
if args.is_empty() {
@@ -1066,7 +1066,7 @@ mod dbg {
}
_ => {
stdout.write_all(b"debug: unknown option ")?;
- stdout.write_all(&arg)?;
+ stdout.write_all(arg)?;
}
}
}
diff --git a/src/run/mod.rs b/src/run/mod.rs
index c3ceb76..009954b 100644
--- a/src/run/mod.rs
+++ b/src/run/mod.rs
@@ -640,7 +640,7 @@ pub fn run(se: Arc<Mutex<Session>>, parsed: Ast<PreExpansion>) -> String {
match result {
Ok(_) => String::new(),
- Err(e) => format!("{}", e.error_message()),
+ Err(e) => e.error_message(),
}
}
diff --git a/src/run/var/mod.rs b/src/run/var/mod.rs
index 1ccc195..57ff9e1 100644
--- a/src/run/var/mod.rs
+++ b/src/run/var/mod.rs
@@ -62,7 +62,7 @@ impl Vars {
for var in vars {
self.watched
.entry(var)
- .or_insert_with(Vec::new)
+ .or_default()
.push(watch.weak());
}
watch
diff --git a/src/syntax_highlighting.rs b/src/syntax_highlighting.rs
index 22a8c3e..f58d4a0 100644
--- a/src/syntax_highlighting.rs
+++ b/src/syntax_highlighting.rs
@@ -155,3 +155,9 @@ impl Highlighter {
Ok(())
}
}
+
+impl Default for Highlighter {
+ fn default() -> Self {
+ Self::new()
+ }
+}