Skip to content

Commit c83a758

Browse files
committed
lint: fix clippy::pedantic (16-20 entries)
1 parent 8c62d83 commit c83a758

File tree

19 files changed

+136
-102
lines changed

19 files changed

+136
-102
lines changed

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ dbg_macro = "warn"
1717
print_stdout = "warn"
1818
non_std_lazy_statics = "warn"
1919
pedantic = {level = "warn", priority = -1}
20-
manual_assert = "allow" # 16
21-
inline_always = "allow" # 18
22-
from_iter_instead_of_collect = "allow" # 20
20+
inline_always = "allow" # TODO: benchmark inlines
2321
default_trait_access = "allow" # 23
2422
format_push_string = "allow" # 27
2523
missing_panics_doc = "allow" # 37

site/src/main.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -665,19 +665,21 @@ fn site() {
665665
(Err(_), true) => {}
666666
(Ok(mut comp), should_fail) => {
667667
if let Some(diag) = comp.take_diagnostics().into_iter().next() {
668-
if !should_fail {
669-
panic!(
670-
"Test failed in {}\n{}\n{}",
671-
path.display(),
672-
code,
673-
diag.report()
674-
);
675-
}
668+
assert!(
669+
should_fail,
670+
"Test failed in {}\n{}\n{}",
671+
path.display(),
672+
code,
673+
diag.report()
674+
);
676675
continue;
677676
}
678-
if should_fail {
679-
panic!("Test should have failed in {}\n{}", path.display(), code);
680-
}
677+
assert!(
678+
!should_fail,
679+
"Test should have failed in {}\n{}",
680+
path.display(),
681+
code
682+
)
681683
}
682684
}
683685
}

site/src/markdown.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -475,11 +475,9 @@ fn text_code_blocks() {
475475
Err(e) => Some(e.report()),
476476
};
477477
if let Some(report) = failure_report {
478-
if !should_fail {
479-
panic!("\nBlock failed:\n{block}\n{report}")
480-
}
481-
} else if should_fail {
482-
panic!("\nBlock should have failed:\n{block}")
478+
assert!(should_fail, "\nBlock failed:\n{block}\n{report}");
479+
} else {
480+
assert!(!should_fail, "\nBlock should have failed:\n{block}");
483481
}
484482
}
485483
}

site/src/primitive.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -433,17 +433,27 @@ fn prim_docs() {
433433
match Uiua::with_backend(WebBackend::default()).run_str(ex.input()) {
434434
Ok(mut comp) => {
435435
if let Some(diag) = comp.take_diagnostics().into_iter().next() {
436-
if !ex.should_error() {
437-
panic!("\nExample failed:\n{}\n{}", ex.input(), diag.report());
438-
}
439-
} else if ex.should_error() {
440-
panic!("Example should have failed: {}", ex.input());
436+
assert!(
437+
ex.should_error(),
438+
"\nExample failed:\n{}\n{}",
439+
ex.input(),
440+
diag.report()
441+
);
442+
} else {
443+
assert!(
444+
!ex.should_error(),
445+
"Example should have failed: {}",
446+
ex.input()
447+
);
441448
}
442449
}
443450
Err(e) => {
444-
if !ex.should_error() {
445-
panic!("\nExample failed:\n{}\n{}", ex.input(), e.report());
446-
}
451+
assert!(
452+
ex.should_error(),
453+
"\nExample failed:\n{}\n{}",
454+
ex.input(),
455+
e.report()
456+
);
447457
}
448458
}
449459
}

src/algorithm/dyadic/structure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1615,7 +1615,7 @@ impl<T: ArrayValue> Array<T> {
16151615
.map(|&i| normalize_index(i, indices.len()))
16161616
.collect();
16171617
let outer_rank = indices_shape.last().copied().unwrap_or(1);
1618-
let mut outer_shape = Shape::from_iter(repeat_n(0, outer_rank));
1618+
let mut outer_shape = repeat_n(0, outer_rank).collect::<Shape>();
16191619
if !normalized_indices.is_empty() {
16201620
for index in normalized_indices.chunks_exact(index_size) {
16211621
for (d, &i) in outer_shape.iter_mut().zip(index) {

src/algorithm/map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ fn coerce_values(
818818
}
819819
if let Value::Box(b_arr) = &b {
820820
if b_arr.rank() == 0 && !matches!(a, Value::Box(_)) {
821-
*a = Array::from_iter(a.rows().map(Boxed)).into();
821+
*a = a.rows().map(Boxed).collect::<Array<_>>().into();
822822
return Ok(b);
823823
}
824824
}

src/algorithm/monadic/mod.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ impl Value {
765765
if ishape.is_empty() {
766766
return Ok(Array::<f64>::new(0, CowSlice::new()).into());
767767
}
768-
let mut shape = Shape::from_iter(ishape.iter().map(|d| d.unsigned_abs()));
768+
let mut shape = ishape.iter().map(|d| d.unsigned_abs()).collect::<Shape>();
769769
shape.push(shape.len());
770770
let data = range(&ishape, start, env)?;
771771
let mut value: Value = match data {
@@ -783,9 +783,9 @@ impl Value {
783783
env,
784784
"Shape should be a single integer or a list of integers",
785785
)?;
786-
let shape = Shape::from_iter(ishape.iter().map(|n| n.unsigned_abs()));
786+
let shape = ishape.iter().map(|n| n.unsigned_abs()).collect::<Shape>();
787787
let elems: usize = validate_size::<f64>(shape.iter().copied(), env)?;
788-
let data = EcoVec::from_iter((0..elems).map(|i| i as f64));
788+
let data = (0..elems).map(|i| i as f64).collect::<EcoVec<_>>();
789789
let mut arr = Array::new(shape, data);
790790
let first_max = ishape.first().copied().unwrap_or(0);
791791
for (i, s) in ishape.into_iter().enumerate() {
@@ -1298,7 +1298,7 @@ impl<T: ArrayValue> Array<T> {
12981298
return;
12991299
}
13001300
let subshape = Shape::from(&self.shape[depth..]);
1301-
let newshape = Shape::from_iter(subshape.iter().rev().copied());
1301+
let newshape = subshape.iter().rev().copied().collect::<Shape>();
13021302
let chunk_size = subshape.elements();
13031303
let data_slice = self.data.as_mut_slice();
13041304
let mut temp = data_slice[..chunk_size].to_vec();
@@ -2014,7 +2014,10 @@ impl Value {
20142014
/// Convert a string value to a list of UTF-16 code units
20152015
pub fn utf16(&self, env: &Uiua) -> UiuaResult<Self> {
20162016
let s = self.as_string(env, "Argument to utf₁₆ must be a string")?;
2017-
Ok(Array::<f64>::from_iter(s.encode_utf16().map(|u| u as f64)).into())
2017+
Ok(s.encode_utf16()
2018+
.map(|u| u as f64)
2019+
.collect::<Array<f64>>()
2020+
.into())
20182021
}
20192022
/// Convert a list of UTF-8 bytes to a string value
20202023
pub fn unutf8(&self, env: &Uiua) -> UiuaResult<Self> {

src/algorithm/stencil.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ where
8686
let total_len = *s + 2 * d.fill * d.stride;
8787
shape_prefix.push((total_len + d.stride).saturating_sub(d.size) / d.stride);
8888
}
89-
let window_shape = Shape::from_iter(
90-
dims.iter()
91-
.map(|d| d.size)
92-
.chain(arr.shape.iter().skip(dims.len()).copied()),
93-
);
89+
let window_shape = dims
90+
.iter()
91+
.map(|d| d.size)
92+
.chain(arr.shape.iter().skip(dims.len()).copied())
93+
.collect::<Shape>();
9494
if shape_prefix.contains(&0) {
9595
let mut shape = shape_prefix;
9696
shape.extend(window_shape);

src/array.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,10 @@ impl<T: Clone> Array<T> {
500500
return row;
501501
}
502502
let row_count = self.row_count();
503-
if row >= row_count {
504-
panic!("row index out of bounds: {row} >= {row_count}");
505-
}
503+
assert!(
504+
row < row_count,
505+
"row index out of bounds: {row} >= {row_count}"
506+
);
506507
let row_len = self.row_len();
507508
let start = row * row_len;
508509
let end = start + row_len;
@@ -605,9 +606,10 @@ impl<T: ArrayValue> Array<T> {
605606
return row;
606607
}
607608
let row_count: usize = self.shape[..=depth].iter().product();
608-
if row >= row_count {
609-
panic!("row index out of bounds: {row} >= {row_count}");
610-
}
609+
assert!(
610+
row < row_count,
611+
"row index out of bounds: {row} >= {row_count}"
612+
);
611613
let row_len: usize = self.shape[depth + 1..].iter().product();
612614
let start = row * row_len;
613615
let end = start + row_len;

src/compile/data.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,13 @@ impl Compiler {
348348
self.compile_bind_const(
349349
name,
350350
local,
351-
Some(Array::from_iter(fields.iter().map(|f| f.name.as_str())).into()),
351+
Some(
352+
fields
353+
.iter()
354+
.map(|f| f.name.as_str())
355+
.collect::<Array<_>>()
356+
.into(),
357+
),
352358
span,
353359
BindingMeta {
354360
comment: Some(DocComment::from(comment.as_str())),

0 commit comments

Comments
 (0)