Skip to content

Commit e36a271

Browse files
committed
lint: fix clippy::pedantic (8-9 entries)
1 parent 93a43c3 commit e36a271

File tree

22 files changed

+104
-117
lines changed

22 files changed

+104
-117
lines changed

Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ print_stdout = "warn"
1717
print_stderr = "allow"
1818
dbg_macro = "warn"
1919
pedantic = {level = "warn", priority = -1}
20-
unnested_or_patterns = "allow" # 8
21-
borrow_as_ptr = "allow" # 9
22-
explicit_iter_loop = "allow" # 9
23-
ignored_unit_patterns = "allow" # 9
24-
many_single_char_names = "allow" # 9
2520
single_match_else = "allow" # 11
2621
manual_string_new = "allow" # 12
2722
trivially_copy_pass_by_ref = "allow" # 12

pad/editor/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ pub fn Editor<'a>(
690690
let first_char = *chars.first().unwrap();
691691
let class = char_class(first_char);
692692
let mut encountered_space = false;
693-
for &c in chars.iter() {
693+
for &c in &chars {
694694
if c.is_whitespace() && c != '\n'
695695
|| char_class(c) == class && !encountered_space
696696
{

pad/editor/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1678,7 +1678,7 @@ pub fn element<T: JsCast>(id: &str) -> T {
16781678
pub fn format_insert_file_code(path: &Path, content: Vec<u8>) -> String {
16791679
let function = match path.extension().and_then(|ext| ext.to_str()) {
16801680
Some("ua") => "~",
1681-
Some("txt") | Some("md") | Some("json") | None => "&fras",
1681+
Some("txt" | "md" | "json") | None => "&fras",
16821682
_ => "&frab",
16831683
};
16841684

site/src/markdown.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub fn Fetch<S: Into<String>, F: Fn(&str) -> View + 'static>(src: S, f: F) -> im
2222
let (src, _) = create_signal(src);
2323
let once = create_resource(
2424
|| (),
25-
move |_| async move { fetch(&src.get_untracked()).await.unwrap() },
25+
move |()| async move { fetch(&src.get_untracked()).await.unwrap() },
2626
);
2727
view! {{
2828
move || match once.get() {
@@ -345,7 +345,7 @@ fn node_html<'a>(node: &'a AstNode<'a>) -> String {
345345
line.push_str(&" ".repeat(max_len - line_len));
346346
}
347347
match comp.load_str(line).and_then(|comp| env.run_compiler(comp)) {
348-
Ok(_) => {
348+
Ok(()) => {
349349
let values = env.take_stack();
350350
if !values.is_empty() && !values.iter().any(|v| v.shape.elements() > 200) {
351351
let formatted: Vec<String> = values.iter().map(Value::show).collect();
@@ -467,7 +467,7 @@ fn text_code_blocks() {
467467
.load_str(&block)
468468
.and_then(|comp| env.run_compiler(comp));
469469
let failure_report = match res {
470-
Ok(_) => comp
470+
Ok(()) => comp
471471
.take_diagnostics()
472472
.into_iter()
473473
.next()

src/algorithm/dyadic/search.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -509,9 +509,7 @@ impl<T: ArrayValue> Array<T> {
509509
if haystack.shape.iter().all(|&d| d > 0) {
510510
'windows: loop {
511511
// Reset curr
512-
for i in curr.iter_mut() {
513-
*i = 0;
514-
}
512+
curr.fill(0);
515513
// Search the window whose top-left is the current corner
516514
'items: loop {
517515
// Get index for the current item in the haystack

src/algorithm/encode.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,7 @@ impl Value {
268268
let mut rows = Vec::new();
269269
for result in reader.records() {
270270
let record = result.map_err(|e| env.error(e))?;
271-
let mut row = EcoVec::new();
272-
for field in record.iter() {
273-
row.push(Boxed(field.into()));
274-
}
271+
let row: EcoVec<_> = record.iter().map(|x| Boxed(x.into())).collect();
275272
rows.push(Array::new(row.len(), row));
276273
}
277274
Array::from_row_arrays(rows, env).map(Into::into)

src/algorithm/ga.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,9 @@ fn fast_dyadic_complex(
367367
drop(b);
368368
for chunk in a.data.as_mut_slice().chunks_exact_mut(2) {
369369
let [ar, ai] = [chunk[0], chunk[1]];
370-
let [r, i] = f(ar, ai, ar, ai);
371-
chunk[0] = r;
372-
chunk[1] = i;
370+
let [real, imag] = f(ar, ai, ar, ai);
371+
chunk[0] = real;
372+
chunk[1] = imag;
373373
}
374374
Ok(a)
375375
} else {
@@ -381,29 +381,29 @@ fn fast_dyadic_complex(
381381
.zip(b.data.as_mut_slice().chunks_exact_mut(2))
382382
{
383383
let [ar, ai, br, bi] = [a[0], a[1], b[0], b[1]];
384-
let [r, i] = f(ar, ai, br, bi);
385-
b[0] = r;
386-
b[1] = i;
384+
let [real, imag] = f(ar, ai, br, bi);
385+
b[0] = real;
386+
b[1] = imag;
387387
}
388388
Ok(b)
389389
}
390390
(_, [2]) => {
391391
let [br, bi] = [b.data[0], b.data[1]];
392392
for a in a.data.as_mut_slice().chunks_exact_mut(2) {
393393
let [ar, ai] = [a[0], a[1]];
394-
let [r, i] = f(ar, ai, br, bi);
395-
a[0] = r;
396-
a[1] = i;
394+
let [real, imag] = f(ar, ai, br, bi);
395+
a[0] = real;
396+
a[1] = imag;
397397
}
398398
Ok(a)
399399
}
400400
([2], _) => {
401401
let [ar, ai] = [a.data[0], a.data[1]];
402402
for b in b.data.as_mut_slice().chunks_exact_mut(2) {
403403
let [br, bi] = [b[0], b[1]];
404-
let [r, i] = f(ar, ai, br, bi);
405-
b[0] = r;
406-
b[1] = i;
404+
let [real, imag] = f(ar, ai, br, bi);
405+
b[0] = real;
406+
b[1] = imag;
407407
}
408408
Ok(b)
409409
}

src/algorithm/media.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,7 @@ builtin_params!(
849849
(Camera, "The position of the camera"),
850850
);
851851

852+
#[expect(clippy::many_single_char_names, reason = "TODO")]
852853
pub(crate) fn voxels(val: &Value, env: &mut Uiua) -> UiuaResult<Value> {
853854
let args = take(&mut env.rt.set_args);
854855
let converted: Array<f64>;
@@ -1482,7 +1483,7 @@ fn layout_text_impl(size: Value, text: Value, env: &mut Uiua) -> UiuaResult<Valu
14821483
let mut canvas_data = if let Some(bg) = bg {
14831484
let color = match &*bg.shape {
14841485
[] | [1] => [bg.data[0], bg.data[0], bg.data[0], 1.0],
1485-
[3] | [4] => {
1486+
[3 | 4] => {
14861487
let alpha = bg.data.get(3).copied().unwrap_or(1.0);
14871488
[bg.data[0], bg.data[1], bg.data[2], alpha]
14881489
}

src/algorithm/monadic/mod.rs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -893,8 +893,8 @@ impl<T: ArrayValue> Array<T> {
893893
for i in 0..chunk_row_count / 2 {
894894
let left = i * chunk_row_len;
895895
let right = (chunk_row_count - i - 1) * chunk_row_len;
896-
let left = &mut data[left] as *mut T;
897-
let right = &mut data[right] as *mut T;
896+
let left = &raw mut data[left];
897+
let right = &raw mut data[right];
898898
unsafe {
899899
ptr::swap_nonoverlapping(left, right, chunk_row_len);
900900
}
@@ -2060,7 +2060,7 @@ impl Array<f64> {
20602060
let max = r.max(g).max(b);
20612061
let min = r.min(g).min(b);
20622062
let delta = max - min;
2063-
let h = if delta == 0.0 {
2063+
let hue = if delta == 0.0 {
20642064
0.0
20652065
} else {
20662066
(TAU * if max == r {
@@ -2071,11 +2071,11 @@ impl Array<f64> {
20712071
(r - g) / delta + 4.0
20722072
}) / 6.0
20732073
};
2074-
let s = if max == 0.0 { 0.0 } else { 1.0 - min / max };
2075-
let v = max;
2076-
rgb[0] = h;
2077-
rgb[1] = s;
2078-
rgb[2] = v;
2074+
let sat = if max == 0.0 { 0.0 } else { 1.0 - min / max };
2075+
let val = max;
2076+
rgb[0] = hue;
2077+
rgb[1] = sat;
2078+
rgb[2] = val;
20792079
}
20802080
self.meta.take_sorted_flags();
20812081
self.validate();
@@ -2092,10 +2092,10 @@ impl Array<f64> {
20922092
}
20932093
let channels = *self.shape.last().unwrap();
20942094
for hsv in self.data.as_mut_slice().chunks_exact_mut(channels) {
2095-
let [h, s, v, ..] = *hsv else {
2095+
let [hue, sat, val, ..] = *hsv else {
20962096
unreachable!();
20972097
};
2098-
let [r, g, b] = hsv_to_rgb(h, s, v);
2098+
let [r, g, b] = hsv_to_rgb(hue, sat, val);
20992099
hsv[0] = r;
21002100
hsv[1] = g;
21012101
hsv[2] = b;
@@ -2106,20 +2106,22 @@ impl Array<f64> {
21062106
}
21072107
}
21082108

2109-
pub(crate) fn hsv_to_rgb(h: f64, s: f64, v: f64) -> [f64; 3] {
2110-
let h = h / TAU * 6.0;
2111-
let i = h.floor() as isize;
2112-
let f = h - i as f64;
2113-
let p = v * (1.0 - s);
2114-
let q = v * (1.0 - f * s);
2115-
let t = v * (1.0 - (1.0 - f) * s);
2116-
match i.rem_euclid(6) {
2117-
0 => [v, t, p],
2118-
1 => [q, v, p],
2119-
2 => [p, v, t],
2120-
3 => [p, q, v],
2121-
4 => [t, p, v],
2122-
_ => [v, p, q],
2109+
pub(crate) fn hsv_to_rgb(hue: f64, sat: f64, val: f64) -> [f64; 3] {
2110+
let hue = hue / TAU * 6.0;
2111+
let sect = hue.floor() as isize;
2112+
let f = hue - sect as f64;
2113+
let chroma = val * sat;
2114+
let min = val - chroma;
2115+
let mid1 = val - f * chroma;
2116+
let mid0 = val - (1.0 - f) * chroma;
2117+
match sect.rem_euclid(6) {
2118+
0 => [val, mid0, min],
2119+
1 => [mid1, val, min],
2120+
2 => [min, val, mid0],
2121+
3 => [min, mid1, val],
2122+
4 => [mid0, min, val],
2123+
5 => [val, min, mid1],
2124+
_ => unreachable!(),
21232125
}
21242126
}
21252127

src/algorithm/reduce.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ where
833833
return arr;
834834
}
835835
let mut acc = arr.data[0];
836-
for val in arr.data.as_mut_slice()[1..].iter_mut() {
836+
for val in &mut arr.data.as_mut_slice()[1..] {
837837
acc = f(acc, *val);
838838
*val = acc;
839839
}
@@ -1018,10 +1018,8 @@ where
10181018
return arr;
10191019
}
10201020
let mut acc = arr.data[0];
1021-
for val in arr.data.as_mut_slice()[1..].iter_mut() {
1022-
let temp = *val;
1023-
*val = f(acc, *val);
1024-
acc = temp;
1021+
for val in &mut arr.data.as_mut_slice()[1..] {
1022+
acc = std::mem::replace(val, f(acc, *val));
10251023
}
10261024
arr
10271025
}

0 commit comments

Comments
 (0)