Method paths for 18 closures that only call a method (SonarCloud S1612)

SonarCloud's analysis of main at b4da59f0c lists 23 closures such as `|v| v.as_slice()` that hand their argument straight to one method. This passes the method itself: `Vec::as_slice`, `str::to_ascii_lowercase`, `f64::total_cmp` and the like, all forms the repo already uses elsewhere. Behaviour is unchanged.

Five stay. The four in crates/proof/src/es/mod.rs sit in code that #4191 replaces, and its replacement already uses `PoisonError::into_inner`. In crates/engine/src/io/safe_save.rs the path would be `<dyn std::error::Error + Send + Sync>::is::<Guided>`, which reads worse than `|inner| inner.is::<Guided>()`.
This commit is contained in:
VoiceLessQ
2026-10-25 01:19:28 -02:00
parent b4da59f0c3
commit 65a0dc8dc6
14 changed files with 18 additions and 18 deletions
+1 -1
View File
@@ -208,7 +208,7 @@ fn save_exts(name: &str) -> Vec<String> {
let suggested = std::path::Path::new(name)
.extension()
.and_then(std::ffi::OsStr::to_str)
.map(|e| e.to_ascii_lowercase())
.map(str::to_ascii_lowercase)
.filter(|e| wordcraft_engine::io::SAVE_EXTS.contains(&e.as_str()))
.unwrap_or_else(|| "docx".to_string());
let mut exts: Vec<String> = Vec::with_capacity(wordcraft_engine::io::SAVE_EXTS.len());
+1 -1
View File
@@ -238,7 +238,7 @@ pub(crate) fn ideograph_zodiac_traditional(n: u32) -> String {
/// The `n`th (1-based) item of a sequence, or decimal past its end.
fn nth(set: &[char], n: u32) -> String {
n.checked_sub(1).and_then(|i| set.get(i as usize)).map(|c| c.to_string()).unwrap_or_else(|| n.to_string())
n.checked_sub(1).and_then(|i| set.get(i as usize)).map(ToString::to_string).unwrap_or_else(|| n.to_string())
}
/// Code points `first..` enclosing 1 to `count`, decimal beyond.
+1 -1
View File
@@ -113,7 +113,7 @@ impl PieceTable {
}
PrmRef::Sprm0 { isprm, val: (p.prm >> 8) as u8 }
} else {
PrmRef::Grpprl(self.prc_grpprls.get((p.prm >> 1) as usize).map(|v| v.as_slice()))
PrmRef::Grpprl(self.prc_grpprls.get((p.prm >> 1) as usize).map(Vec::as_slice))
}
}
+1 -1
View File
@@ -2291,7 +2291,7 @@ fn css_string(v: &str) -> String {
out.push(d);
}
// One whitespace after the escape is its terminator, not part of the value.
if chars.clone().next().is_some_and(|w| w.is_whitespace()) {
if chars.clone().next().is_some_and(char::is_whitespace) {
chars.next();
}
}
+1 -1
View File
@@ -68,7 +68,7 @@ impl<'d> EmbedWriter<'d> {
"[content_types].xml",
]
.iter()
.map(|s| s.to_string())
.map(ToString::to_string)
.collect();
taken.insert(VBA_PROJECT_PART.to_ascii_lowercase());
// The bibliography writer uses these names when sources are present (#532).
+1 -1
View File
@@ -1243,7 +1243,7 @@ impl FontDb {
stack.push(p);
continue;
}
let ext = p.extension().and_then(std::ffi::OsStr::to_str).map(|e| e.to_ascii_lowercase());
let ext = p.extension().and_then(std::ffi::OsStr::to_str).map(str::to_ascii_lowercase);
if !matches!(ext.as_deref(), Some("ttf" | "otf" | "ttc" | "otc")) {
continue;
}
+1 -1
View File
@@ -182,7 +182,7 @@ pub(crate) fn find_ui_font(dirs: &[std::path::PathBuf], names: &[&str], needed:
if !tried.insert(path.clone()) {
continue;
}
let Some(size) = std::fs::metadata(&path).ok().filter(|m| m.is_file()).map(|m| m.len()) else { continue };
let Some(size) = std::fs::metadata(&path).ok().filter(std::fs::Metadata::is_file).map(|m| m.len()) else { continue };
if size > MAX_FILE {
continue;
}
+1 -1
View File
@@ -440,7 +440,7 @@ impl Writer {
/// Paragraph `p`, or with `chain` the paragraphs joined at deleted paragraph marks (`p`
/// is the first).
fn para_in(&mut self, p: &Para, chain: Option<&Vec<Para>>, out: &mut String) {
let paras: &[Para] = chain.map(|c| c.as_slice()).unwrap_or(std::slice::from_ref(p));
let paras: &[Para] = chain.map(Vec::as_slice).unwrap_or(std::slice::from_ref(p));
let start = self.master.take();
self.chain = chain.map(|c| c.iter().map(|q| self.para_style(q)).collect()).unwrap_or_default();
self.part = 0;
+4 -4
View File
@@ -1304,7 +1304,7 @@ fn layout_box(
let float_y = if float.v_rel == Anchor::Paragraph { para_top } else { y };
let r = float_rect(frame, (0.0, width), float_y, w, h, float);
let outline = ctx.wrap_outline(o);
excl.extend(wrap_area(r, float, outline.as_deref().map(|v| v.as_slice())));
excl.extend(wrap_area(r, float, outline.as_deref().map(Vec::as_slice)));
floats.insert(oi, r);
}
let rel = rel_exclusions(&excl, 0.0, y);
@@ -3045,8 +3045,8 @@ impl PageFrame<'_> {
/// Alignment `a` across the page: inside and outside become right and left on an even page.
fn h_align(frame: Option<&Self>, a: Option<FloatAlign>) -> Option<FloatAlign> {
match a {
Some(FloatAlign::Inside) if frame.is_some_and(|f| f.even()) => Some(FloatAlign::End),
Some(FloatAlign::Outside) if frame.is_some_and(|f| f.even()) => Some(FloatAlign::Start),
Some(FloatAlign::Inside) if frame.is_some_and(Self::even) => Some(FloatAlign::End),
Some(FloatAlign::Outside) if frame.is_some_and(Self::even) => Some(FloatAlign::Start),
a => a,
}
}
@@ -3365,7 +3365,7 @@ fn anchor_floats(
// Positions relative to the paragraph start above its space before (Word for Windows).
let mut r = float_rect(Some(frame), (col_x, width), y0 - before, w, h, float);
let outline = ctx.wrap_outline(o);
let outline = outline.as_deref().map(|v| v.as_slice());
let outline = outline.as_deref().map(Vec::as_slice);
let mut area = wrap_area(r, float, outline);
if pb.settle && text_before {
let seed = early.and_then(|v| v.iter().find(|(b, k, _)| (*b, *k) == (block, oi))).map(|(_, _, a)| a);
+2 -2
View File
@@ -1518,7 +1518,7 @@ impl Ctx {
}
segs_rows.push(segs.into_iter().map(hcat).collect());
}
let ncols = segs_rows.iter().map(|r| r.len()).max().unwrap_or(1);
let ncols = segs_rows.iter().map(Vec::len).max().unwrap_or(1);
// Rows without `&` are centred below, so they don't widen the aligned columns.
let mut col_w = vec![0.0f32; ncols];
let mut lone_w = 0.0f32;
@@ -1829,7 +1829,7 @@ impl Ctx {
}
cells.push(row);
}
let ncols = cells.iter().map(|r| r.len()).max().unwrap_or(0);
let ncols = cells.iter().map(Vec::len).max().unwrap_or(0);
let mut col_w = vec![0.0f32; ncols];
for r in &cells {
for (i, b) in r.iter().enumerate() {
+1 -1
View File
@@ -103,7 +103,7 @@ pub(crate) fn subpaths(pts: &[P], counts: &[usize], close: bool) -> Vec<Op> {
let mut at = 0usize;
for &c in counts {
let end = at.saturating_add(c).min(pts.len());
let Some((first, rest)) = pts.get(at..end).and_then(|s| s.split_first()) else {
let Some((first, rest)) = pts.get(at..end).and_then(<[_]>::split_first) else {
at = end;
continue;
};
+1 -1
View File
@@ -419,7 +419,7 @@ impl AffixDict {
}
stems.push((word, flags));
}
AffixDict::build(rules, stems, comments.iter().map(|s| s.to_string()).collect())
AffixDict::build(rules, stems, comments.iter().map(ToString::to_string).collect())
}
fn build(rules: Rules, mut stems: Vec<(String, String)>, comments: Vec<String>) -> Result<AffixDict, String> {
+1 -1
View File
@@ -27,7 +27,7 @@ fn step(h: &mut egui_kittest::Harness<'_, WordApp>) -> f64 {
fn stats(v: &[f64]) -> serde_json::Value {
let mut s = v.to_vec();
s.sort_by(|a, b| a.total_cmp(b));
s.sort_by(f64::total_cmp);
let at = |q: f64| s.get(((s.len() as f64 - 1.0) * q).round() as usize).copied().unwrap_or(0.0);
json!({"n": s.len(), "med": (at(0.5) * 10.0).round() / 10.0, "p95": (at(0.95) * 10.0).round() / 10.0, "max": (at(1.0) * 10.0).round() / 10.0})
}
+1 -1
View File
@@ -192,7 +192,7 @@ pub fn check(crates: &[Crate]) -> Vec<Violation> {
}
}
}
out.sort_by_key(|v| v.to_string());
out.sort_by_key(ToString::to_string);
out.dedup();
out
}