Skip to content

Commit 92cdb2e

Browse files
Run clippy
1 parent ff5274f commit 92cdb2e

File tree

22 files changed

+175
-196
lines changed

22 files changed

+175
-196
lines changed

abnf_to_pest/src/lib.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ impl Pretty for Repeat {
6868
(0, None) => "*".into(),
6969
(1, None) => "+".into(),
7070
(0, Some(1)) => "?".into(),
71-
(min, None) => format!("{{{},}}", min),
72-
(min, Some(max)) if min == max => format!("{{{}}}", min),
73-
(min, Some(max)) => format!("{{{},{}}}", min, max),
71+
(min, None) => format!("{{{min},}}"),
72+
(min, Some(max)) if min == max => format!("{{{min}}}"),
73+
(min, Some(max)) => format!("{{{min},{max}}}"),
7474
})
7575
}
7676
}
@@ -124,7 +124,7 @@ fn format_char(x: u32) -> String {
124124
}
125125
}
126126
}
127-
format!("\\u{{{:02X}}}", x)
127+
format!("\\u{{{x:02X}}}")
128128
}
129129

130130
/// Allow control over some of the pest properties of the outputted rule
@@ -153,8 +153,7 @@ impl Pretty for (String, PestyRule) {
153153
pub fn parse_abnf(
154154
data: &str,
155155
) -> Result<IndexMap<String, PestyRule>, std::io::Error> {
156-
let make_err =
157-
|e| std::io::Error::new(std::io::ErrorKind::Other, format!("{}", e));
156+
let make_err = |e| std::io::Error::other(format!("{e}"));
158157
let rules: Vec<Rule> = abnf::rulelist(data).map_err(make_err)?;
159158
Ok(rules
160159
.into_iter()

dhall/build.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ fn convert_abnf_to_pest() -> std::io::Result<()> {
1010
let abnf_path = "src/syntax/text/dhall.abnf";
1111
let visibility_path = "src/syntax/text/dhall.pest.visibility";
1212
let grammar_path = Path::new(&out_dir).join("dhall.pest");
13-
println!("cargo:rerun-if-changed={}", abnf_path);
14-
println!("cargo:rerun-if-changed={}", visibility_path);
13+
println!("cargo:rerun-if-changed={abnf_path}");
14+
println!("cargo:rerun-if-changed={visibility_path}");
1515

1616
let mut data = read_to_string(abnf_path)?;
1717
data.push('\n');
@@ -128,7 +128,7 @@ fn generate_pest_parser() -> std::io::Result<()> {
128128
);
129129

130130
let mut file = File::create(output_path)?;
131-
writeln!(file, "{}", file_contents)
131+
writeln!(file, "{file_contents}")
132132
}
133133

134134
fn main() -> std::io::Result<()> {

dhall/src/builtins.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -345,27 +345,27 @@ fn apply_builtin<'cx>(
345345
(Builtin::OptionalNone, [t]) => {
346346
Ret::NirKind(EmptyOptionalLit(t.clone()))
347347
}
348-
(Builtin::NaturalIsZero, [n]) => match &*n.kind() {
348+
(Builtin::NaturalIsZero, [n]) => match n.kind() {
349349
Num(Natural(n)) => Ret::NirKind(Num(Bool(*n == 0))),
350350
_ => Ret::DoneAsIs,
351351
},
352-
(Builtin::NaturalEven, [n]) => match &*n.kind() {
352+
(Builtin::NaturalEven, [n]) => match n.kind() {
353353
Num(Natural(n)) => Ret::NirKind(Num(Bool(*n % 2 == 0))),
354354
_ => Ret::DoneAsIs,
355355
},
356-
(Builtin::NaturalOdd, [n]) => match &*n.kind() {
356+
(Builtin::NaturalOdd, [n]) => match n.kind() {
357357
Num(Natural(n)) => Ret::NirKind(Num(Bool(*n % 2 != 0))),
358358
_ => Ret::DoneAsIs,
359359
},
360-
(Builtin::NaturalToInteger, [n]) => match &*n.kind() {
360+
(Builtin::NaturalToInteger, [n]) => match n.kind() {
361361
Num(Natural(n)) => Ret::NirKind(Num(Integer(*n as i64))),
362362
_ => Ret::DoneAsIs,
363363
},
364-
(Builtin::NaturalShow, [n]) => match &*n.kind() {
364+
(Builtin::NaturalShow, [n]) => match n.kind() {
365365
Num(Natural(n)) => Ret::Nir(Nir::from_text(n)),
366366
_ => Ret::DoneAsIs,
367367
},
368-
(Builtin::NaturalSubtract, [a, b]) => match (&*a.kind(), &*b.kind()) {
368+
(Builtin::NaturalSubtract, [a, b]) => match (a.kind(), b.kind()) {
369369
(Num(Natural(a)), Num(Natural(b))) => {
370370
Ret::NirKind(Num(Natural(if b > a { b - a } else { 0 })))
371371
}
@@ -374,38 +374,38 @@ fn apply_builtin<'cx>(
374374
_ if a == b => Ret::NirKind(Num(Natural(0))),
375375
_ => Ret::DoneAsIs,
376376
},
377-
(Builtin::IntegerShow, [n]) => match &*n.kind() {
377+
(Builtin::IntegerShow, [n]) => match n.kind() {
378378
Num(Integer(n)) => {
379379
let s = if *n < 0 {
380380
n.to_string()
381381
} else {
382-
format!("+{}", n)
382+
format!("+{n}")
383383
};
384384
Ret::Nir(Nir::from_text(s))
385385
}
386386
_ => Ret::DoneAsIs,
387387
},
388-
(Builtin::IntegerToDouble, [n]) => match &*n.kind() {
388+
(Builtin::IntegerToDouble, [n]) => match n.kind() {
389389
Num(Integer(n)) => {
390390
Ret::NirKind(Num(Double(NaiveDouble::from(*n as f64))))
391391
}
392392
_ => Ret::DoneAsIs,
393393
},
394-
(Builtin::IntegerNegate, [n]) => match &*n.kind() {
394+
(Builtin::IntegerNegate, [n]) => match n.kind() {
395395
Num(Integer(n)) => Ret::NirKind(Num(Integer(-n))),
396396
_ => Ret::DoneAsIs,
397397
},
398-
(Builtin::IntegerClamp, [n]) => match &*n.kind() {
398+
(Builtin::IntegerClamp, [n]) => match n.kind() {
399399
Num(Integer(n)) => {
400400
Ret::NirKind(Num(Natural((*n).try_into().unwrap_or(0))))
401401
}
402402
_ => Ret::DoneAsIs,
403403
},
404-
(Builtin::DoubleShow, [n]) => match &*n.kind() {
404+
(Builtin::DoubleShow, [n]) => match n.kind() {
405405
Num(Double(n)) => Ret::Nir(Nir::from_text(n)),
406406
_ => Ret::DoneAsIs,
407407
},
408-
(Builtin::TextShow, [v]) => match &*v.kind() {
408+
(Builtin::TextShow, [v]) => match v.kind() {
409409
TextLit(tlit) => {
410410
if let Some(s) = tlit.as_text() {
411411
// Printing InterpolatedText takes care of all the escaping
@@ -422,7 +422,7 @@ fn apply_builtin<'cx>(
422422
(Builtin::TextReplace, [needle, replacement, haystack]) => {
423423
// Helper to match a Nir as a text literal
424424
fn nir_to_string(n: &Nir) -> Option<String> {
425-
match &*n.kind() {
425+
match n.kind() {
426426
TextLit(n_lit) => n_lit.as_text(),
427427
_ => None,
428428
}
@@ -464,26 +464,26 @@ fn apply_builtin<'cx>(
464464
_ => Ret::DoneAsIs,
465465
}
466466
}
467-
(Builtin::ListLength, [_, l]) => match &*l.kind() {
467+
(Builtin::ListLength, [_, l]) => match l.kind() {
468468
EmptyListLit(_) => Ret::NirKind(Num(Natural(0))),
469469
NEListLit(xs) => Ret::NirKind(Num(Natural(xs.len() as u64))),
470470
_ => Ret::DoneAsIs,
471471
},
472-
(Builtin::ListHead, [_, l]) => match &*l.kind() {
472+
(Builtin::ListHead, [_, l]) => match l.kind() {
473473
EmptyListLit(n) => Ret::NirKind(EmptyOptionalLit(n.clone())),
474474
NEListLit(xs) => {
475475
Ret::NirKind(NEOptionalLit(xs.iter().next().unwrap().clone()))
476476
}
477477
_ => Ret::DoneAsIs,
478478
},
479-
(Builtin::ListLast, [_, l]) => match &*l.kind() {
479+
(Builtin::ListLast, [_, l]) => match l.kind() {
480480
EmptyListLit(n) => Ret::NirKind(EmptyOptionalLit(n.clone())),
481481
NEListLit(xs) => Ret::NirKind(NEOptionalLit(
482-
xs.iter().rev().next().unwrap().clone(),
482+
xs.iter().next_back().unwrap().clone(),
483483
)),
484484
_ => Ret::DoneAsIs,
485485
},
486-
(Builtin::ListReverse, [_, l]) => match &*l.kind() {
486+
(Builtin::ListReverse, [_, l]) => match l.kind() {
487487
EmptyListLit(n) => Ret::NirKind(EmptyListLit(n.clone())),
488488
NEListLit(xs) => {
489489
Ret::NirKind(NEListLit(xs.iter().rev().cloned().collect()))
@@ -542,7 +542,7 @@ fn apply_builtin<'cx>(
542542
.app(EmptyListLit(t.clone()).into_nir()),
543543
)
544544
}
545-
(Builtin::ListFold, [_, l, _, cons, nil]) => match &*l.kind() {
545+
(Builtin::ListFold, [_, l, _, cons, nil]) => match l.kind() {
546546
EmptyListLit(_) => Ret::Nir(nil.clone()),
547547
NEListLit(xs) => {
548548
let mut v = nil.clone();
@@ -562,7 +562,7 @@ fn apply_builtin<'cx>(
562562
.app(Num(Natural(0)).into_nir()),
563563
),
564564

565-
(Builtin::NaturalFold, [n, t, succ, zero]) => match &*n.kind() {
565+
(Builtin::NaturalFold, [n, t, succ, zero]) => match n.kind() {
566566
Num(Natural(0)) => Ret::Nir(zero.clone()),
567567
Num(Natural(n)) => {
568568
let fold = Nir::from_builtin(cx, Builtin::NaturalFold)

dhall/src/error/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl ErrorBuilder {
115115
}
116116

117117
// TODO: handle multiple files
118-
#[allow(clippy::drop_ref)]
118+
#[allow(dropping_references)]
119119
pub fn format(&mut self) -> String {
120120
if self.consumed {
121121
panic!("tried to format the same ErrorBuilder twice")

dhall/src/error/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ impl std::fmt::Display for TypeError {
8585
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
8686
use TypeMessage::*;
8787
let msg = match &self.message {
88-
Custom(s) => format!("Type error: {}", s),
88+
Custom(s) => format!("Type error: {s}"),
8989
};
90-
write!(f, "{}", msg)
90+
write!(f, "{msg}")
9191
}
9292
}
9393

@@ -96,9 +96,9 @@ impl std::error::Error for TypeError {}
9696
impl std::fmt::Display for EncodeError {
9797
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
9898
let msg = match self {
99-
EncodeError::CBORError(e) => format!("Encode error: {}", e),
99+
EncodeError::CBORError(e) => format!("Encode error: {e}"),
100100
};
101-
write!(f, "{}", msg)
101+
write!(f, "{msg}")
102102
}
103103
}
104104

@@ -107,13 +107,13 @@ impl std::error::Error for EncodeError {}
107107
impl std::fmt::Display for Error {
108108
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
109109
match &self.kind {
110-
ErrorKind::IO(err) => write!(f, "{}", err),
111-
ErrorKind::Parse(err) => write!(f, "{}", err),
112-
ErrorKind::Decode(err) => write!(f, "{:?}", err),
113-
ErrorKind::Encode(err) => write!(f, "{:?}", err),
114-
ErrorKind::Resolve(err) => write!(f, "{:?}", err),
115-
ErrorKind::Typecheck(err) => write!(f, "{}", err),
116-
ErrorKind::Cache(err) => write!(f, "{:?}", err),
110+
ErrorKind::IO(err) => write!(f, "{err}"),
111+
ErrorKind::Parse(err) => write!(f, "{err}"),
112+
ErrorKind::Decode(err) => write!(f, "{err:?}"),
113+
ErrorKind::Encode(err) => write!(f, "{err:?}"),
114+
ErrorKind::Resolve(err) => write!(f, "{err:?}"),
115+
ErrorKind::Typecheck(err) => write!(f, "{err}"),
116+
ErrorKind::Cache(err) => write!(f, "{err:?}"),
117117
}
118118
}
119119
}

dhall/src/semantics/nze/nir.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,15 @@ impl<'cx> Nir<'cx> {
120120
}
121121

122122
pub fn as_const(&self) -> Option<Const> {
123-
match &*self.kind() {
123+
match self.kind() {
124124
NirKind::Const(c) => Some(*c),
125125
_ => None,
126126
}
127127
}
128128

129129
/// This is what you want if you want to pattern-match on the value.
130130
pub fn kind(&self) -> &NirKind<'cx> {
131-
&*self.0
131+
&self.0
132132
}
133133

134134
/// The contents of a `Nir` are immutable and shared. If however we happen to be the sole
@@ -440,7 +440,7 @@ impl<'cx> std::cmp::Eq for Closure<'cx> {}
440440
impl<'cx> std::fmt::Debug for Nir<'cx> {
441441
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
442442
if let NirKind::Const(c) = self.kind() {
443-
return write!(fmt, "{:?}", c);
443+
return write!(fmt, "{c:?}");
444444
}
445445
let mut x = fmt.debug_struct("Nir");
446446
x.field("kind", self.kind());

dhall/src/semantics/nze/normalize.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ pub fn apply_any<'cx>(f: &Nir<'cx>, a: Nir<'cx>) -> NirKind<'cx> {
1919
pub fn squash_textlit<'cx>(
2020
elts: impl Iterator<Item = InterpolatedTextContents<Nir<'cx>>>,
2121
) -> Vec<InterpolatedTextContents<Nir<'cx>>> {
22-
use std::mem::replace;
2322
use InterpolatedTextContents::{Expr, Text};
2423

2524
fn inner<'cx>(
@@ -36,7 +35,7 @@ pub fn squash_textlit<'cx>(
3635
}
3736
_ => {
3837
if !crnt_str.is_empty() {
39-
ret.push(Text(replace(crnt_str, String::new())))
38+
ret.push(Text(std::mem::take(crnt_str)))
4039
}
4140
ret.push(Expr(e.clone()))
4241
}
@@ -49,7 +48,7 @@ pub fn squash_textlit<'cx>(
4948
let mut ret = Vec::new();
5049
inner(elts, &mut crnt_str, &mut ret);
5150
if !crnt_str.is_empty() {
52-
ret.push(Text(replace(&mut crnt_str, String::new())))
51+
ret.push(Text(std::mem::take(&mut crnt_str)))
5352
}
5453
ret
5554
}

dhall/src/semantics/resolve/cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ fn write_cache_file<'cx>(
110110

111111
fn filename_for_hash(hash: &Hash) -> String {
112112
match hash {
113-
Hash::SHA256(sha) => format!("1220{}", hex::encode(&sha)),
113+
Hash::SHA256(sha) => format!("1220{}", hex::encode(sha)),
114114
}
115115
}
116116

dhall/src/semantics/resolve/hir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl<'cx> Hir<'cx> {
4848
}
4949

5050
pub fn kind(&self) -> &HirKind<'cx> {
51-
&*self.kind
51+
&self.kind
5252
}
5353
pub fn span(&self) -> Span {
5454
self.span.clone()

dhall/src/semantics/resolve/resolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ fn traverse_accumulate<'cx>(
445445
let cx = env.cx();
446446
let expr = desugar(expr);
447447
let kind = match expr.kind() {
448-
ExprKind::Var(var) => match name_env.unlabel_var(&var) {
448+
ExprKind::Var(var) => match name_env.unlabel_var(var) {
449449
Some(v) => HirKind::Var(v),
450450
None => HirKind::MissingVar(var.clone()),
451451
},

0 commit comments

Comments
 (0)