Skip to content

Commit a6056c5

Browse files
committed
lint: fix clippy::pedantic (8-9 entries)
1 parent 7b55162 commit a6056c5

File tree

21 files changed

+102
-115
lines changed

21 files changed

+102
-115
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
@@ -702,7 +702,7 @@ pub fn Editor<'a>(
702702
let first_char = *chars.first().unwrap();
703703
let class = char_class(first_char);
704704
let mut encountered_space = false;
705-
for &c in chars.iter() {
705+
for &c in &chars {
706706
if c.is_whitespace() && c != '\n'
707707
|| char_class(c) == class && !encountered_space
708708
{

pad/editor/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,7 @@ pub fn element<T: JsCast>(id: &str) -> T {
16941694
pub fn format_insert_file_code(path: &Path, content: Vec<u8>) -> String {
16951695
let function = match path.extension().and_then(|ext| ext.to_str()) {
16961696
Some("ua") => "~",
1697-
Some("txt") | Some("md") | Some("json") | None => "&fras",
1697+
Some("txt" | "md" | "json") | None => "&fras",
16981698
_ => "&frab",
16991699
};
17001700

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
@@ -503,9 +503,7 @@ impl<T: ArrayValue> Array<T> {
503503
if haystack.shape.iter().all(|&d| d > 0) {
504504
'windows: loop {
505505
// Reset curr
506-
for i in curr.iter_mut() {
507-
*i = 0;
508-
}
506+
curr.fill(0);
509507
// Search the window whose top-left is the current corner
510508
'items: loop {
511509
// 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
@@ -1136,8 +1136,8 @@ impl<T: ArrayValue> Array<T> {
11361136
for i in 0..chunk_row_count / 2 {
11371137
let left = i * chunk_row_len;
11381138
let right = (chunk_row_count - i - 1) * chunk_row_len;
1139-
let left = &mut data[left] as *mut T;
1140-
let right = &mut data[right] as *mut T;
1139+
let left = &raw mut data[left];
1140+
let right = &raw mut data[right];
11411141
unsafe {
11421142
ptr::swap_nonoverlapping(left, right, chunk_row_len);
11431143
}
@@ -2303,7 +2303,7 @@ impl Array<f64> {
23032303
let max = r.max(g).max(b);
23042304
let min = r.min(g).min(b);
23052305
let delta = max - min;
2306-
let h = if delta == 0.0 {
2306+
let hue = if delta == 0.0 {
23072307
0.0
23082308
} else {
23092309
(TAU * if max == r {
@@ -2314,11 +2314,11 @@ impl Array<f64> {
23142314
(r - g) / delta + 4.0
23152315
}) / 6.0
23162316
};
2317-
let s = if max == 0.0 { 0.0 } else { 1.0 - min / max };
2318-
let v = max;
2319-
rgb[0] = h;
2320-
rgb[1] = s;
2321-
rgb[2] = v;
2317+
let sat = if max == 0.0 { 0.0 } else { 1.0 - min / max };
2318+
let val = max;
2319+
rgb[0] = hue;
2320+
rgb[1] = sat;
2321+
rgb[2] = val;
23222322
}
23232323
self.meta.take_sorted_flags();
23242324
self.validate();
@@ -2335,10 +2335,10 @@ impl Array<f64> {
23352335
}
23362336
let channels = *self.shape.last().unwrap();
23372337
for hsv in self.data.as_mut_slice().chunks_exact_mut(channels) {
2338-
let [h, s, v, ..] = *hsv else {
2338+
let [hue, sat, val, ..] = *hsv else {
23392339
unreachable!();
23402340
};
2341-
let [r, g, b] = hsv_to_rgb(h, s, v);
2341+
let [r, g, b] = hsv_to_rgb(hue, sat, val);
23422342
hsv[0] = r;
23432343
hsv[1] = g;
23442344
hsv[2] = b;
@@ -2349,20 +2349,22 @@ impl Array<f64> {
23492349
}
23502350
}
23512351

2352-
pub(crate) fn hsv_to_rgb(h: f64, s: f64, v: f64) -> [f64; 3] {
2353-
let h = h / TAU * 6.0;
2354-
let i = h.floor() as isize;
2355-
let f = h - i as f64;
2356-
let p = v * (1.0 - s);
2357-
let q = v * (1.0 - f * s);
2358-
let t = v * (1.0 - (1.0 - f) * s);
2359-
match i.rem_euclid(6) {
2360-
0 => [v, t, p],
2361-
1 => [q, v, p],
2362-
2 => [p, v, t],
2363-
3 => [p, q, v],
2364-
4 => [t, p, v],
2365-
_ => [v, p, q],
2352+
pub(crate) fn hsv_to_rgb(hue: f64, sat: f64, val: f64) -> [f64; 3] {
2353+
let hue = hue / TAU * 6.0;
2354+
let sect = hue.floor() as isize;
2355+
let f = hue - sect as f64;
2356+
let chroma = val * sat;
2357+
let min = val - chroma;
2358+
let mid1 = val - f * chroma;
2359+
let mid0 = val - (1.0 - f) * chroma;
2360+
match sect.rem_euclid(6) {
2361+
0 => [val, mid0, min],
2362+
1 => [mid1, val, min],
2363+
2 => [min, val, mid0],
2364+
3 => [min, mid1, val],
2365+
4 => [mid0, min, val],
2366+
5 => [val, min, mid1],
2367+
_ => unreachable!(),
23662368
}
23672369
}
23682370

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)