Skip to content

Commit 02a1373

Browse files
committed
Clippy fixes
1 parent 599090e commit 02a1373

File tree

12 files changed

+46
-48
lines changed

12 files changed

+46
-48
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "chumsky"
3-
version = "0.10.1"
3+
version = "0.11.0"
44
description = "A parser library for humans with powerful error recovery"
55
authors = ["Joshua Barretto <joshua.s.barretto@gmail.com>", "Elijah Hartvigsen <elijah.reed@hartvigsen.xyz", "Jakob Wiesmore <runetynan@gmail.com>"]
66
repository = "https://github.com/zesterer/chumsky"

examples/brainfuck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ fn main() {
6868

6969
match parser().parse(src.trim()).into_result() {
7070
Ok(ast) => execute(&ast, &mut 0, &mut [0; TAPE_LEN]),
71-
Err(errs) => errs.into_iter().for_each(|e| println!("{:?}", e)),
71+
Err(errs) => errs.into_iter().for_each(|e| println!("{e:?}")),
7272
};
7373
}

examples/foo.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ fn eval<'src>(
130130
if let Some((_, val)) = vars.iter().rev().find(|(var, _)| var == name) {
131131
Ok(*val)
132132
} else {
133-
Err(format!("Cannot find variable `{}` in scope", name))
133+
Err(format!("Cannot find variable `{name}` in scope"))
134134
}
135135
}
136136
Expr::Let { name, rhs, then } => {
@@ -158,14 +158,13 @@ fn eval<'src>(
158158
output
159159
} else {
160160
Err(format!(
161-
"Wrong number of arguments for function `{}`: expected {}, found {}",
162-
name,
161+
"Wrong number of arguments for function `{name}`: expected {}, found {}",
163162
arg_names.len(),
164163
args.len(),
165164
))
166165
}
167166
} else {
168-
Err(format!("Cannot find function `{}` in scope", name))
167+
Err(format!("Cannot find function `{name}` in scope"))
169168
}
170169
}
171170
Expr::Fn {
@@ -188,11 +187,11 @@ fn main() {
188187

189188
match parser().parse(&src).into_result() {
190189
Ok(ast) => match eval(&ast, &mut Vec::new(), &mut Vec::new()) {
191-
Ok(output) => println!("{}", output),
192-
Err(eval_err) => println!("Evaluation error: {}", eval_err),
190+
Ok(output) => println!("{output}"),
191+
Err(eval_err) => println!("Evaluation error: {eval_err}"),
193192
},
194193
Err(parse_errs) => parse_errs
195194
.into_iter()
196-
.for_each(|e| println!("Parse error: {}", e)),
195+
.for_each(|err| println!("Parse error: {err}")),
197196
};
198197
}

examples/io.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ fn main() {
4747
let json = parser::<extra::Err<Rich<_>>>()
4848
.parse(IoInput::new(src))
4949
.into_result();
50-
println!("{:#?}", json);
50+
println!("{json:#?}");
5151
}

examples/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ fn main() {
140140
.expect("Failed to read file");
141141

142142
let (json, errs) = parser().parse(src.trim()).into_output_errors();
143-
println!("{:#?}", json);
143+
println!("{json:#?}");
144144
errs.into_iter().for_each(|e| {
145145
Report::build(ReportKind::Error, ((), e.span().into_range()))
146146
.with_config(ariadne::Config::new().with_index_type(ariadne::IndexType::Byte))

examples/json_fast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn parser<'a>() -> impl Parser<'a, &'a str, Json> {
7373
.padded()
7474
.delimited_by(just('['), just(']'));
7575

76-
let member = string.clone().then_ignore(just(':').padded()).then(value);
76+
let member = string.then_ignore(just(':').padded()).then(value);
7777
let object = member
7878
.clone()
7979
.separated_by(just(',').padded())
@@ -99,5 +99,5 @@ fn main() {
9999
.expect("Failed to read file");
100100

101101
let json = parser().parse(src.trim()).unwrap();
102-
println!("{:#?}", json);
102+
println!("{json:#?}");
103103
}

examples/logos.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ enum Token<'a> {
3838
impl fmt::Display for Token<'_> {
3939
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4040
match self {
41-
Self::Float(s) => write!(f, "{}", s),
41+
Self::Float(s) => write!(f, "{s}"),
4242
Self::Add => write!(f, "+"),
4343
Self::Sub => write!(f, "-"),
4444
Self::Mul => write!(f, "*"),
@@ -148,8 +148,8 @@ fn main() {
148148
match parser().parse(token_stream).into_result() {
149149
// If parsing was successful, attempt to evaluate the s-expression
150150
Ok(sexpr) => match sexpr.eval() {
151-
Ok(out) => println!("Result = {}", out),
152-
Err(err) => println!("Runtime error: {}", err),
151+
Ok(out) => println!("Result = {out}"),
152+
Err(err) => println!("Runtime error: {err}"),
153153
},
154154
// If parsing was unsuccessful, generate a nice user-friendly diagnostic with ariadne. You could also use
155155
// codespan, or whatever other diagnostic library you care about. You could even just display-print the errors

examples/nano_rust.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ impl fmt::Display for Token<'_> {
3131
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3232
match self {
3333
Token::Null => write!(f, "null"),
34-
Token::Bool(x) => write!(f, "{}", x),
35-
Token::Num(n) => write!(f, "{}", n),
36-
Token::Str(s) => write!(f, "{}", s),
37-
Token::Op(s) => write!(f, "{}", s),
38-
Token::Ctrl(c) => write!(f, "{}", c),
39-
Token::Ident(s) => write!(f, "{}", s),
34+
Token::Bool(x) => write!(f, "{x}"),
35+
Token::Num(n) => write!(f, "{n}"),
36+
Token::Str(s) => write!(f, "{s}"),
37+
Token::Op(s) => write!(f, "{s}"),
38+
Token::Ctrl(c) => write!(f, "{c}"),
39+
Token::Ident(s) => write!(f, "{s}"),
4040
Token::Fn => write!(f, "fn"),
4141
Token::Let => write!(f, "let"),
4242
Token::Print => write!(f, "print"),
@@ -119,7 +119,7 @@ impl Value<'_> {
119119
} else {
120120
Err(Error {
121121
span,
122-
msg: format!("'{}' is not a number", self),
122+
msg: format!("'{self}' is not a number"),
123123
})
124124
}
125125
}
@@ -129,9 +129,9 @@ impl std::fmt::Display for Value<'_> {
129129
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
130130
match self {
131131
Self::Null => write!(f, "null"),
132-
Self::Bool(x) => write!(f, "{}", x),
133-
Self::Num(x) => write!(f, "{}", x),
134-
Self::Str(x) => write!(f, "{}", x),
132+
Self::Bool(x) => write!(f, "{x}"),
133+
Self::Num(x) => write!(f, "{x}"),
134+
Self::Str(x) => write!(f, "{x}"),
135135
Self::List(xs) => write!(
136136
f,
137137
"[{}]",
@@ -140,7 +140,7 @@ impl std::fmt::Display for Value<'_> {
140140
.collect::<Vec<_>>()
141141
.join(", ")
142142
),
143-
Self::Func(name) => write!(f, "<function: {}>", name),
143+
Self::Func(name) => write!(f, "<function: {name}>"),
144144
}
145145
}
146146
}
@@ -435,7 +435,7 @@ where
435435
if funcs.insert(name, f).is_some() {
436436
emitter.emit(Rich::custom(
437437
name_span,
438-
format!("Function '{}' already exists", name),
438+
format!("Function '{name}' already exists"),
439439
));
440440
}
441441
}
@@ -470,7 +470,7 @@ fn eval_expr<'src>(
470470
.or_else(|| Some(Value::Func(name)).filter(|_| funcs.contains_key(name)))
471471
.ok_or_else(|| Error {
472472
span: expr.1,
473-
msg: format!("No such variable '{}' in scope", name),
473+
msg: format!("No such variable '{name}' in scope"),
474474
})?,
475475
Expr::Let(local, val, body) => {
476476
let val = eval_expr(val, funcs, stack)?;
@@ -509,7 +509,7 @@ fn eval_expr<'src>(
509509
let mut stack = if f.args.len() != args.0.len() {
510510
return Err(Error {
511511
span: expr.1,
512-
msg: format!("'{}' called with wrong number of arguments (expected {}, found {})", name, f.args.len(), args.0.len()),
512+
msg: format!("'{}' called with wrong number of arguments (expected {name}, found {})", f.args.len(), args.0.len()),
513513
});
514514
} else {
515515
f.args
@@ -523,7 +523,7 @@ fn eval_expr<'src>(
523523
f => {
524524
return Err(Error {
525525
span: func.1,
526-
msg: format!("'{:?}' is not callable", f),
526+
msg: format!("'{f:?}' is not callable"),
527527
})
528528
}
529529
}
@@ -536,14 +536,14 @@ fn eval_expr<'src>(
536536
c => {
537537
return Err(Error {
538538
span: cond.1,
539-
msg: format!("Conditions must be booleans, found '{:?}'", c),
539+
msg: format!("Conditions must be booleans, found '{c:?}'"),
540540
})
541541
}
542542
}
543543
}
544544
Expr::Print(a) => {
545545
let val = eval_expr(a, funcs, stack)?;
546-
println!("{}", val);
546+
println!("{val}");
547547
val
548548
}
549549
})
@@ -574,7 +574,7 @@ fn main() {
574574
))
575575
} else {
576576
match eval_expr(&main.body, &funcs, &mut Vec::new()) {
577-
Ok(val) => println!("Return value: {}", val),
577+
Ok(val) => println!("Return value: {val}"),
578578
Err(e) => errs.push(Rich::custom(e.span, e.msg)),
579579
}
580580
}
@@ -609,7 +609,7 @@ fn main() {
609609
)
610610
.with_labels(e.contexts().map(|(label, span)| {
611611
Label::new((filename.clone(), span.into_range()))
612-
.with_message(format!("while parsing this {}", label))
612+
.with_message(format!("while parsing this {label}"))
613613
.with_color(Color::Yellow)
614614
}))
615615
.finish()

src/combinator.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,6 @@ where
526526
go_extra!(I::Span);
527527
}
528528

529-
530529
/// See [`Parser::try_foldl`].
531530
pub struct TryFoldl<F, A, B, OB, E> {
532531
pub(crate) parser_a: A,
@@ -579,7 +578,7 @@ where
579578
Err(err) => {
580579
inp.add_alt_err(&before.inner, err);
581580
break Err(());
582-
},
581+
}
583582
}
584583
}
585584
Ok(None) => break Ok(M::bind(|| out)),

0 commit comments

Comments
 (0)