Skip to content

Commit a953774

Browse files
committed
style: Resolve various clippy warnings
1 parent 0942b8c commit a953774

10 files changed

Lines changed: 84 additions & 86 deletions

File tree

src/engines/http_file.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl BackupEngine<HttpFile> for HttpFileEngine {
157157
tokio::fs::remove_file(&temp_path)
158158
.await
159159
.unwrap_or_else(|e| {
160-
tracing::error!(
160+
error!(
161161
"Failed to remove temporary backup file '{}': {}",
162162
temp_path.display(),
163163
e
@@ -175,7 +175,7 @@ impl BackupEngine<HttpFile> for HttpFileEngine {
175175
tokio::fs::remove_file(&temp_path)
176176
.await
177177
.unwrap_or_else(|e| {
178-
tracing::error!(
178+
error!(
179179
"Failed to remove temporary backup file '{}': {}",
180180
temp_path.display(),
181181
e

src/errors.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
human_errors::error_shim!(Error);
22

3-
use std::convert;
4-
53
use reqwest::StatusCode;
64

7-
impl convert::From<reqwest::Error> for Error {
5+
impl From<reqwest::Error> for Error {
86
fn from(err: reqwest::Error) -> Self {
97
if err.is_connect() {
108
user_with_internal(
@@ -35,7 +33,7 @@ impl convert::From<reqwest::Error> for Error {
3533
}
3634
}
3735

38-
impl convert::From<reqwest::Response> for Error {
36+
impl From<reqwest::Response> for Error {
3937
fn from(resp: reqwest::Response) -> Self {
4038
match resp.status() {
4139
StatusCode::NOT_FOUND => user(
@@ -55,7 +53,7 @@ impl convert::From<reqwest::Response> for Error {
5553
}
5654
}
5755

58-
impl convert::From<reqwest::header::InvalidHeaderValue> for Error {
56+
impl From<reqwest::header::InvalidHeaderValue> for Error {
5957
fn from(err: reqwest::header::InvalidHeaderValue) -> Self {
6058
system_with_internal(
6159
"Could not parse header value due to an internal error.",

src/filter/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl Debug for Expr<'_> {
4949
}
5050

5151
struct ExprPrinter<'a, 'b>(&'a mut std::fmt::Formatter<'b>);
52-
impl<'a, 'b> ExprVisitor<std::fmt::Result> for ExprPrinter<'a, 'b> {
52+
impl ExprVisitor<std::fmt::Result> for ExprPrinter<'_, '_> {
5353
fn visit_literal(&mut self, value: &FilterValue) -> std::fmt::Result {
5454
write!(self.0, "{}", value)
5555
}

src/filter/interpreter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ impl<'a, T: Filterable> FilterContext<'a, T> {
1414
}
1515
}
1616

17-
impl<'a, T: Filterable> ExprVisitor<FilterValue> for FilterContext<'a, T> {
17+
impl<T: Filterable> ExprVisitor<FilterValue> for FilterContext<'_, T> {
1818
fn visit_literal(&mut self, value: &FilterValue) -> FilterValue {
1919
value.clone()
2020
}

src/filter/lexer.rs

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -159,81 +159,81 @@ impl<'a> Iterator for Scanner<'a> {
159159
))));
160160
}
161161
'&' => {
162-
if self.match_char('&') {
163-
return Some(Ok(Token::And(Loc::new(
162+
return if self.match_char('&') {
163+
Some(Ok(Token::And(Loc::new(
164164
self.line,
165165
1 + idx - self.line_start,
166-
))));
166+
))))
167167
} else {
168-
return Some(Err(errors::user(
169-
&format!("Filter included an orphaned '&' at {} which is not a valid operator.", Loc::new(self.line, 1 + idx - self.line_start)),
170-
"Ensure that you are using the '&&' operator to implement a logical AND within your filter."
171-
)));
168+
Some(Err(errors::user(
169+
&format!("Filter included an orphaned '&' at {} which is not a valid operator.", Loc::new(self.line, 1 + idx - self.line_start)),
170+
"Ensure that you are using the '&&' operator to implement a logical AND within your filter."
171+
)))
172172
}
173173
}
174174
'|' => {
175-
if self.match_char('|') {
176-
return Some(Ok(Token::Or(Loc::new(
175+
return if self.match_char('|') {
176+
Some(Ok(Token::Or(Loc::new(
177177
self.line,
178178
1 + idx - self.line_start,
179-
))));
179+
))))
180180
} else {
181-
return Some(Err(errors::user(
182-
&format!("Filter included an orphaned '|' at {} which is not a valid operator.", Loc::new(self.line, 1 + idx - self.line_start)),
183-
"Ensure that you are using the '||' operator to implement a logical OR within your filter."
184-
)));
181+
Some(Err(errors::user(
182+
&format!("Filter included an orphaned '|' at {} which is not a valid operator.", Loc::new(self.line, 1 + idx - self.line_start)),
183+
"Ensure that you are using the '||' operator to implement a logical OR within your filter."
184+
)))
185185
}
186186
}
187187
'=' => {
188-
if self.match_char('=') {
189-
return Some(Ok(Token::Equals(Loc::new(
188+
return if self.match_char('=') {
189+
Some(Ok(Token::Equals(Loc::new(
190190
self.line,
191191
1 + idx - self.line_start,
192-
))));
192+
))))
193193
} else {
194-
return Some(Err(errors::user(
195-
&format!("Filter included an orphaned '=' at {} which is not a valid operator.", Loc::new(self.line, 1 + idx - self.line_start)),
196-
"Ensure that you are using the '==' operator to implement a logical equality within your filter."
197-
)));
194+
Some(Err(errors::user(
195+
&format!("Filter included an orphaned '=' at {} which is not a valid operator.", Loc::new(self.line, 1 + idx - self.line_start)),
196+
"Ensure that you are using the '==' operator to implement a logical equality within your filter."
197+
)))
198198
}
199199
}
200200
'!' => {
201-
if self.match_char('=') {
202-
return Some(Ok(Token::NotEquals(Loc::new(
201+
return if self.match_char('=') {
202+
Some(Ok(Token::NotEquals(Loc::new(
203203
self.line,
204204
1 + idx - self.line_start,
205-
))));
205+
))))
206206
} else {
207-
return Some(Ok(Token::Not(Loc::new(
207+
Some(Ok(Token::Not(Loc::new(
208208
self.line,
209209
1 + idx - self.line_start,
210-
))));
210+
))))
211211
}
212212
}
213213
'>' => {
214-
if self.match_char('=') {
215-
return Some(Ok(Token::GreaterEqual(Loc::new(
214+
return if self.match_char('=') {
215+
Some(Ok(Token::GreaterEqual(Loc::new(
216216
self.line,
217217
1 + idx - self.line_start,
218-
))));
218+
))))
219219
} else {
220-
return Some(Ok(Token::GreaterThan(Loc::new(
220+
Some(Ok(Token::GreaterThan(Loc::new(
221221
self.line,
222222
idx - self.line_start,
223-
))));
223+
))))
224224
}
225225
}
226226
'<' => {
227-
if self.match_char('=') {
228-
return Some(Ok(Token::SmallerEqual(Loc::new(
227+
return if self.match_char('=') {
228+
Some(Ok(Token::SmallerEqual(Loc::new(
229229
self.line,
230230
1 + idx - self.line_start,
231-
))));
231+
))))
232232
} else {
233-
return Some(Ok(Token::SmallerThan(Loc::new(
233+
Some(Ok(Token::SmallerThan(Loc::new(
234234
self.line,
235235
idx - self.line_start,
236-
))));
236+
))))
237237
}
238238
}
239239
'"' => {

src/filter/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ impl Filter {
2424
let filter_ptr = NonNull::from(&filter);
2525
let pinned = Box::into_pin(filter);
2626

27-
let tokens = crate::filter::lexer::Scanner::new(unsafe { filter_ptr.as_ref() });
28-
let ast = crate::filter::parser::Parser::parse(tokens.into_iter())?;
27+
let tokens = lexer::Scanner::new(unsafe { filter_ptr.as_ref() });
28+
let ast = parser::Parser::parse(tokens.into_iter())?;
2929
Ok(Self {
3030
filter: pinned,
3131
ast,
@@ -71,6 +71,13 @@ impl<'de> serde::Deserialize<'de> for Filter {
7171
formatter.write_str("a valid filter expression")
7272
}
7373

74+
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
75+
where
76+
E: serde::de::Error,
77+
{
78+
Filter::new(v).map_err(serde::de::Error::custom)
79+
}
80+
7481
fn visit_none<E>(self) -> Result<Self::Value, E>
7582
where
7683
E: serde::de::Error,
@@ -84,13 +91,6 @@ impl<'de> serde::Deserialize<'de> for Filter {
8491
{
8592
deserializer.deserialize_str(self)
8693
}
87-
88-
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
89-
where
90-
E: serde::de::Error,
91-
{
92-
Filter::new(v).map_err(serde::de::Error::custom)
93-
}
9494
}
9595

9696
deserializer.deserialize_option(FilterVisitor)

src/filter/parser.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl<'a, I: Iterator<Item = Result<Token<'a>, Error>>> Parser<'a, I> {
6767
self.tokens.peek(),
6868
Some(Ok(Token::Equals(..)) | Ok(Token::NotEquals(..)))
6969
) {
70-
let token = self.tokens.next().unwrap().unwrap();
70+
let token = self.tokens.next().unwrap()?;
7171
let right = self.comparison()?;
7272
expr = Expr::Binary(Box::new(expr), token, Box::new(right));
7373
}
@@ -89,7 +89,7 @@ impl<'a, I: Iterator<Item = Result<Token<'a>, Error>>> Parser<'a, I> {
8989
| Some(Ok(Token::SmallerThan(..)))
9090
| Some(Ok(Token::SmallerEqual(..)))
9191
) {
92-
let token = self.tokens.next().unwrap().unwrap();
92+
let token = self.tokens.next().unwrap()?;
9393
let right = self.unary()?;
9494
expr = Expr::Binary(Box::new(expr), token, Box::new(right));
9595
}
@@ -99,7 +99,7 @@ impl<'a, I: Iterator<Item = Result<Token<'a>, Error>>> Parser<'a, I> {
9999

100100
fn unary(&mut self) -> Result<Expr<'a>, Error> {
101101
if matches!(self.tokens.peek(), Some(Ok(Token::Not(..)))) {
102-
let token = self.tokens.next().unwrap().unwrap();
102+
let token = self.tokens.next().unwrap()?;
103103
let right = self.unary()?;
104104
Ok(Expr::Unary(token, Box::new(right)))
105105
} else {
@@ -110,7 +110,7 @@ impl<'a, I: Iterator<Item = Result<Token<'a>, Error>>> Parser<'a, I> {
110110
fn primary(&mut self) -> Result<Expr<'a>, Error> {
111111
match self.tokens.peek() {
112112
Some(Ok(Token::LeftParen(..))) => {
113-
let start = self.tokens.next().unwrap().unwrap();
113+
let start = self.tokens.next().unwrap()?;
114114
let expr = self.or()?;
115115
if let Some(Ok(Token::RightParen(..))) = self.tokens.next() {
116116
Ok(expr)
@@ -122,7 +122,7 @@ impl<'a, I: Iterator<Item = Result<Token<'a>, Error>>> Parser<'a, I> {
122122
}
123123
}
124124
Some(Ok(Token::LeftBracket(..))) => {
125-
let start = self.tokens.next().unwrap().unwrap();
125+
let start = self.tokens.next().unwrap()?;
126126
let mut items = Vec::new();
127127
while !matches!(self.tokens.peek(), Some(Ok(Token::RightBracket(..)))) {
128128
items.push(self.literal()?);
@@ -162,13 +162,13 @@ impl<'a, I: Iterator<Item = Result<Token<'a>, Error>>> Parser<'a, I> {
162162
match self.tokens.next() {
163163
Some(Ok(Token::True(..))) => Ok(true.into()),
164164
Some(Ok(Token::False(..))) => Ok(false.into()),
165-
Some(Ok(Token::Number(loc, n))) => Ok(super::FilterValue::Number(n.parse().map_err(|e| errors::user_with_internal(
165+
Some(Ok(Token::Number(loc, n))) => Ok(FilterValue::Number(n.parse().map_err(|e| errors::user_with_internal(
166166
&format!("Failed to parse the number '{n}' which you provided at {}.", loc),
167167
"Please make sure that the number is well formatted. It should be in the form 123, or 123.45.",
168168
e,
169169
))?)),
170170
Some(Ok(Token::String(.., s))) => Ok(s.replace("\\\"", "\"").replace("\\\\", "\\").into()),
171-
Some(Ok(Token::Null(..))) => Ok(super::FilterValue::Null),
171+
Some(Ok(Token::Null(..))) => Ok(FilterValue::Null),
172172
Some(Ok(token)) => Err(errors::user(
173173
&format!("While parsing your filter, we found an unexpected '{}' at {}.", token, token.location()),
174174
"Make sure that you have written a valid filter query.",

src/filter/value.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,27 @@ impl PartialEq for FilterValue {
9494
}
9595

9696
impl PartialOrd for FilterValue {
97+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
98+
match (self, other) {
99+
(FilterValue::Null, FilterValue::Null) => Some(Ordering::Equal),
100+
(FilterValue::Bool(a), FilterValue::Bool(b)) => a.partial_cmp(b),
101+
(FilterValue::Number(a), FilterValue::Number(b)) => a.partial_cmp(b),
102+
(FilterValue::String(a), FilterValue::String(b)) => a.partial_cmp(b),
103+
(FilterValue::Tuple(a), FilterValue::Tuple(b)) => {
104+
if a.len() != b.len() {
105+
a.len().partial_cmp(&b.len())
106+
} else {
107+
a.iter()
108+
.zip(b.iter())
109+
.map(|(x, y)| x.partial_cmp(y))
110+
.find(|&cmp| cmp != Some(Ordering::Equal))
111+
.unwrap_or(Some(Ordering::Equal))
112+
}
113+
}
114+
_ => None, // Return None for non-comparable types
115+
}
116+
}
117+
97118
fn lt(&self, other: &Self) -> bool {
98119
match (self, other) {
99120
(FilterValue::Null, FilterValue::Null) => true,
@@ -145,27 +166,6 @@ impl PartialOrd for FilterValue {
145166
_ => false,
146167
}
147168
}
148-
149-
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
150-
match (self, other) {
151-
(FilterValue::Null, FilterValue::Null) => Some(Ordering::Equal),
152-
(FilterValue::Bool(a), FilterValue::Bool(b)) => a.partial_cmp(b),
153-
(FilterValue::Number(a), FilterValue::Number(b)) => a.partial_cmp(b),
154-
(FilterValue::String(a), FilterValue::String(b)) => a.partial_cmp(b),
155-
(FilterValue::Tuple(a), FilterValue::Tuple(b)) => {
156-
if a.len() != b.len() {
157-
a.len().partial_cmp(&b.len())
158-
} else {
159-
a.iter()
160-
.zip(b.iter())
161-
.map(|(x, y)| x.partial_cmp(y))
162-
.find(|&cmp| cmp != Some(Ordering::Equal))
163-
.unwrap_or(Some(Ordering::Equal))
164-
}
165-
}
166-
_ => None, // Return None for non-comparable types
167-
}
168-
}
169169
}
170170

171171
impl Display for FilterValue {

src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ async fn run(args: Args) -> Result<(), Error> {
7070
.and_then(|s| s.find_next_occurrence(&chrono::Utc::now(), false).ok());
7171

7272
{
73-
let _span = tracing::info_span!("backup.all").entered();
73+
let _span = info_span!("backup.all").entered();
7474

7575
for policy in config.backups.iter() {
76-
let _policy_span = tracing::info_span!("backup.policy", policy = %policy).entered();
76+
let _policy_span = info_span!("backup.policy", policy = %policy).entered();
7777

7878
match policy.kind.as_str() {
7979
k if k == GitHubArtifactKind::Repo.as_str() => {
@@ -130,7 +130,7 @@ impl<E: BackupEntity> PairingHandler<E> for LoggingPairingHandler {
130130
info!(" - {} ({})", entity, state);
131131
}
132132

133-
fn on_error(&self, error: crate::Error) {
133+
fn on_error(&self, error: Error) {
134134
warn!("Error: {}", error);
135135
}
136136
}

src/telemetry/traced_stream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub struct TracedStream<T: Stream> {
1010
}
1111

1212
pub trait StreamExt: Stream + Sized {
13-
fn trace(self, span: tracing::Span) -> TracedStream<Self> {
13+
fn trace(self, span: Span) -> TracedStream<Self> {
1414
TracedStream { stream: self, span }
1515
}
1616
}

0 commit comments

Comments
 (0)