Skip to content

Commit ea3412a

Browse files
committed
lint: fix clippy::format_push_string
1 parent 3255c71 commit ea3412a

File tree

10 files changed

+63
-46
lines changed

10 files changed

+63
-46
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ print_stderr = "allow"
1818
dbg_macro = "warn"
1919
pedantic = {level = "warn", priority = -1}
2020
inline_always = "allow" # TODO: benchmark inlines
21-
format_push_string = "allow" # 27
2221
missing_panics_doc = "allow" # 37
2322
used_underscore_binding = "allow" # 39
2423
float_cmp = "allow" # 40

pad/editor/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub mod utils;
33

44
use std::{
55
cell::Cell,
6+
fmt::Write,
67
iter::{once, repeat_n},
78
mem::take,
89
path::PathBuf,
@@ -2275,7 +2276,7 @@ pub fn Prim(
22752276
let href = format!("/docs/{}", prim.name());
22762277
let mut title = String::new();
22772278
if let Some(ascii) = prim.ascii() {
2278-
title.push_str(&format!("({ascii})"));
2279+
write!(title, "({ascii})").ok();
22792280
}
22802281
if prim.glyph().is_some() && glyph_only {
22812282
if !title.is_empty() {

site/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ fn NotFound() -> impl IntoView {
403403

404404
#[cfg(test)]
405405
fn prim_html(prim: Primitive, glyph_only: bool, hide_docs: bool) -> String {
406+
use std::fmt::Write;
406407
use uiua::PrimDoc;
407408

408409
let symbol_class = format!("prim-glyph {}", uiua_editor::prim_class(prim));
@@ -415,7 +416,7 @@ fn prim_html(prim: Primitive, glyph_only: bool, hide_docs: bool) -> String {
415416
let href = format!("/docs/{}", prim.name());
416417
let mut title = String::new();
417418
if let Some(ascii) = prim.ascii() {
418-
title.push_str(&format!("({ascii})"));
419+
write!(title, "({ascii})").ok();
419420
}
420421
if prim.glyph().is_some() && glyph_only {
421422
if !title.is_empty() {

site/src/markdown.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ fn node_html<'a>(node: &'a AstNode<'a>) -> String {
353353
line.push('\n');
354354
for formatted in formatted {
355355
for fline in formatted.lines() {
356-
line.push_str(&format!("\n# {fline}"));
356+
write!(line, "\n# {fline}").ok();
357357
}
358358
}
359359
} else {
@@ -372,7 +372,9 @@ fn node_html<'a>(node: &'a AstNode<'a>) -> String {
372372
{
373373
break;
374374
}
375-
Err(e) => line.push_str(&format!("# {e}")),
375+
Err(e) => {
376+
write!(line, "# {e}").ok();
377+
}
376378
}
377379
}
378380
let text = lines.join("\n");

site/src/other.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use leptos::*;
22
use leptos_meta::*;
3+
use std::fmt::Write;
34
use uiua::{ConstClass, Primitive, SysOp, CONSTANTS};
45
use uiua_editor::{lang, Editor};
56

@@ -459,7 +460,7 @@ pub fn Combinators() -> impl IntoView {
459460
if !line.starts_with('#') {
460461
for i in 0..inputs {
461462
let a = i * 3 + 1;
462-
ex.push_str(&format!(" {}_{}_{}", a, a + 1, a + 2));
463+
write!(ex, " {}_{}_{}", a, a+1, a+2).ok();
463464
}
464465
ex.push_str(" ");
465466
}

site/src/primitive.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use leptos::*;
22
use leptos_router::*;
3+
use std::fmt::Write;
34
use uiua::{PrimClass, PrimDoc, PrimDocFragment, PrimDocLine, Primitive, SysOp};
45
use uiua_editor::Editor;
56

@@ -49,11 +50,12 @@ pub fn PrimDocs(prim: Primitive) -> impl IntoView {
4950
sig.push_str("Constant");
5051
} else if let Some(margs) = prim.modifier_args() {
5152
match margs {
52-
1 => sig.push_str("Monadic"),
53-
2 => sig.push_str("Dyadic"),
54-
3 => sig.push_str("Triadic"),
55-
n => sig.push_str(&format!("{n}-function")),
53+
1 => write!(sig, "Monadic"),
54+
2 => write!(sig, "Dyadic"),
55+
3 => write!(sig, "Triadic"),
56+
n => write!(sig, "{n}-function"),
5657
}
58+
.ok();
5759
if let Some(args) = prim.args() {
5860
sig.push(' ');
5961
sig.push_str(&args.to_string());
@@ -62,16 +64,17 @@ pub fn PrimDocs(prim: Primitive) -> impl IntoView {
6264
sig.push_str(" modifier");
6365
} else {
6466
match prim.args() {
65-
Some(0) => sig.push_str("Noadic"),
66-
Some(1) => sig.push_str("Monadic"),
67-
Some(2) => sig.push_str("Dyadic"),
68-
Some(3) => sig.push_str("Triadic"),
69-
Some(n) => sig.push_str(&format!("{n}-argument")),
70-
None => sig.push_str("Variadic"),
67+
Some(0) => write!(sig, "Noadic"),
68+
Some(1) => write!(sig, "Monadic"),
69+
Some(2) => write!(sig, "Dyadic"),
70+
Some(3) => write!(sig, "Triadic"),
71+
Some(n) => write!(sig, "{n}-argument"),
72+
None => write!(sig, "Variadic"),
7173
}
74+
.ok();
7275
if let Some(outputs) = prim.outputs() {
7376
if outputs != 1 {
74-
sig.push_str(&format!(" {outputs}-output"));
77+
write!(sig, " {outputs}-output").ok();
7578
}
7679
} else {
7780
sig.push_str(" variable-output");

src/assembly.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::{
2-
fmt,
2+
fmt::{self, Write},
33
hash::{DefaultHasher, Hash, Hasher},
44
ops::{Index, IndexMut},
55
path::PathBuf,
@@ -263,7 +263,7 @@ impl Assembly {
263263
if map.len() == 1 {
264264
let key = map.keys().next().unwrap();
265265
let value = map.values().next().unwrap();
266-
uasm.push_str(&format!("{key} {value}\n"));
266+
writeln!(uasm, "{key} {value}").ok();
267267
continue;
268268
}
269269
}
@@ -293,7 +293,7 @@ impl Assembly {
293293
for entry in &self.inputs.files {
294294
let key = entry.key();
295295
let value = entry.value();
296-
uasm.push_str(&format!("{}: {:?}\n", key.display(), value));
296+
writeln!(uasm, "{}: {:?}", key.display(), value).ok();
297297
}
298298

299299
if !self.inputs.strings.is_empty() {

src/format.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ macro_rules! create_config {
113113

114114
#[test]
115115
fn generate_format_cfg_docs() {
116+
use std::fmt::Write;
116117
paste! {
117118
let mut s: String = r"
118119
# Uiua Formatter Configuration
@@ -125,19 +126,20 @@ Example with default values:
125126
```uiua
126127
".into();
127128
$(
128-
s.push_str(&format!("{} ← {}\n", stringify!([<$name:camel>]), default_to_uiua!($default)));
129+
write!(s, "{} ← {}\n", stringify!([<$name:camel>]), default_to_uiua!($default)).ok()
130+
;
129131
)*
130132
s.push_str(r"```
131133
The following configuration options are available:
132134
133135
");
134136

135137
$(
136-
s.push_str(&format!("### {}\n", stringify!([<$name:camel>])));
137-
s.push_str(&format!("Type: {}\n\n", param_type!($ty)));
138-
s.push_str(&format!("Default: `{}`\n\n", default_to_uiua!($default)));
139-
$(s.push_str(&format!("{}\n", $doc.trim()));)*
140-
s.push_str("\n---\n\n");
138+
writeln!(s, "### {}", stringify!([<$name:camel>])).ok();
139+
writeln!(s, "Type: {}\n", param_type!($ty)).ok();
140+
writeln!(s, "Default: `{}`\n", default_to_uiua!($default)).ok();
141+
$(writeln!(s, "{}", $doc.trim()).ok();)*
142+
writeln!(s, "\n---\n").ok();
141143
)*
142144

143145
fs::write("site/text/format_config.md", s).unwrap();

src/grid_fmt.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use std::{
44
collections::HashMap,
55
f64::consts::{E, PI, TAU},
6+
fmt::Write,
67
iter::{once, repeat_n},
78
mem::take,
89
};
@@ -274,10 +275,12 @@ impl GridFmt for f64 {
274275
round_sig_dec(mean, 4).grid_string(false)
275276
);
276277
if nan_count > 0 {
277-
s.push_str(&format!(
278+
write!(
279+
s,
278280
" ({nan_count} NaN{})",
279281
if nan_count > 1 { "s" } else { "" }
280-
));
282+
)
283+
.ok();
281284
}
282285
s
283286
}

src/lsp.rs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ pub use server::run_language_server;
845845

846846
#[cfg(feature = "lsp")]
847847
mod server {
848-
use std::{char::decode_utf16, env::current_dir, path::Path, sync::Arc};
848+
use std::{char::decode_utf16, env::current_dir, fmt::Write, path::Path, sync::Arc};
849849

850850
use dashmap::DashMap;
851851
use tower_lsp::{
@@ -1127,7 +1127,7 @@ mod server {
11271127
span.as_str(&doc.asm.inputs, |s| value.push_str(s));
11281128
match docs.kind {
11291129
BindingDocsKind::Function { sig, .. } => {
1130-
value.push_str(&format!(" {sig}"));
1130+
write!(value, " {sig}").ok();
11311131
}
11321132
_ => {}
11331133
}
@@ -1148,7 +1148,7 @@ mod server {
11481148
}
11491149
value.push_str("\n```");
11501150
if let Some(escape) = &docs.escape {
1151-
value.push_str(&format!("\n`{escape}`"));
1151+
write!(value, "\n`{escape}`").ok();
11521152
}
11531153
match docs.kind {
11541154
BindingDocsKind::Function {
@@ -2435,20 +2435,21 @@ mod server {
24352435

24362436
fn doc_frag_markdown(md: &mut String, frag: &PrimDocFragment) {
24372437
match frag {
2438-
PrimDocFragment::Text(text) => md.push_str(text),
2439-
PrimDocFragment::Code(text) => md.push_str(&format!("`{text}`")),
2440-
PrimDocFragment::Emphasis(text) => md.push_str(&format!("*{text}*")),
2441-
PrimDocFragment::Strong(text) => md.push_str(&format!("**{text}**")),
2442-
PrimDocFragment::Link { text, url } => md.push_str(&format!("[{text}]({url})")),
2438+
PrimDocFragment::Text(text) => write!(md, "{text}"),
2439+
PrimDocFragment::Code(text) => write!(md, "`{text}`"),
2440+
PrimDocFragment::Emphasis(text) => write!(md, "*{text}*"),
2441+
PrimDocFragment::Strong(text) => write!(md, "**{text}**"),
2442+
PrimDocFragment::Link { text, url } => write!(md, "[{text}]({url})"),
24432443
PrimDocFragment::Primitive { prim, named } => {
24442444
let text = if *named {
24452445
format!("`{}`", prim.format())
24462446
} else {
24472447
prim.to_string()
24482448
};
2449-
md.push_str(&format!("[{text}](https://uiua.org/docs/{})", prim.name()))
2449+
write!(md, "[{}](https://uiua.org/docs/{})", text, prim.name())
24502450
}
24512451
}
2452+
.ok();
24522453
}
24532454

24542455
fn full_prim_doc_markdown(prim: Primitive) -> String {
@@ -2459,12 +2460,12 @@ mod server {
24592460
for frag in &doc.short {
24602461
doc_frag_markdown(&mut value, frag);
24612462
}
2462-
value.push_str("\n\n");
2463-
value.push_str(&format!(
2464-
"[Documentation](https://uiua.org/docs/{})",
2463+
write!(
2464+
value,
2465+
"\n\n[Documentation](https://uiua.org/docs/{})\n\n",
24652466
prim.name()
2466-
));
2467-
value.push_str("\n\n");
2467+
)
2468+
.ok();
24682469
for line in &doc.lines {
24692470
match line {
24702471
PrimDocLine::Text(frags) => {
@@ -2474,22 +2475,26 @@ mod server {
24742475
value.push('\n');
24752476
}
24762477
PrimDocLine::Example(ex) => {
2477-
value.push_str(&format!(
2478+
write!(
2479+
value,
24782480
"\
24792481
```uiua
24802482
{}
24812483
```
24822484
> ```
24832485
",
24842486
ex.input()
2485-
));
2487+
)
2488+
.ok();
24862489
match ex.output_strings() {
24872490
Ok(lines) => {
24882491
for line in lines.iter().flat_map(|l| l.lines()) {
2489-
value.push_str(&format!("> {line}\n"));
2492+
writeln!(value, "> {line}").ok();
24902493
}
24912494
}
2492-
Err(err) => value.push_str(&format!("> Error: {err}\n")),
2495+
Err(err) => {
2496+
writeln!(value, "> Error: {err}").ok();
2497+
}
24932498
}
24942499
value.push_str("> ```\n\n");
24952500
}

0 commit comments

Comments
 (0)