Skip to content

Commit 91d0327

Browse files
committed
lint: fix clippy::pedantic (16-20 entries)
1 parent ab83e1a commit 91d0327

File tree

18 files changed

+133
-99
lines changed

18 files changed

+133
-99
lines changed

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ print_stdout = "warn"
1717
print_stderr = "allow"
1818
dbg_macro = "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
@@ -428,17 +428,27 @@ fn prim_docs() {
428428
match Uiua::with_backend(WebBackend::default()).run_str(ex.input()) {
429429
Ok(mut comp) => {
430430
if let Some(diag) = comp.take_diagnostics().into_iter().next() {
431-
if !ex.should_error() {
432-
panic!("\nExample failed:\n{}\n{}", ex.input(), diag.report());
433-
}
434-
} else if ex.should_error() {
435-
panic!("Example should have failed: {}", ex.input());
431+
assert!(
432+
ex.should_error(),
433+
"\nExample failed:\n{}\n{}",
434+
ex.input(),
435+
diag.report()
436+
);
437+
} else {
438+
assert!(
439+
!ex.should_error(),
440+
"Example should have failed: {}",
441+
ex.input()
442+
);
436443
}
437444
}
438445
Err(e) => {
439-
if !ex.should_error() {
440-
panic!("\nExample failed:\n{}\n{}", ex.input(), e.report());
441-
}
446+
assert!(
447+
ex.should_error(),
448+
"\nExample failed:\n{}\n{}",
449+
ex.input(),
450+
e.report()
451+
);
442452
}
443453
}
444454
}

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
@@ -516,7 +516,7 @@ impl Value {
516516
if ishape.is_empty() {
517517
return Ok(Array::<f64>::new(0, CowSlice::new()).into());
518518
}
519-
let mut shape = Shape::from_iter(ishape.iter().map(|d| d.unsigned_abs()));
519+
let mut shape = ishape.iter().map(|d| d.unsigned_abs()).collect::<Shape>();
520520
shape.push(shape.len());
521521
let data = range(&ishape, start, env)?;
522522
let mut value: Value = match data {
@@ -534,9 +534,9 @@ impl Value {
534534
env,
535535
"Shape should be a single integer or a list of integers",
536536
)?;
537-
let shape = Shape::from_iter(ishape.iter().map(|n| n.unsigned_abs()));
537+
let shape = ishape.iter().map(|n| n.unsigned_abs()).collect::<Shape>();
538538
let elems: usize = validate_size::<f64>(shape.iter().copied(), env)?;
539-
let data = EcoVec::from_iter((0..elems).map(|i| i as f64));
539+
let data = (0..elems).map(|i| i as f64).collect::<EcoVec<_>>();
540540
let mut arr = Array::new(shape, data);
541541
let first_max = ishape.first().copied().unwrap_or(0);
542542
for (i, s) in ishape.into_iter().enumerate() {
@@ -1077,7 +1077,7 @@ impl<T: ArrayValue> Array<T> {
10771077
return;
10781078
}
10791079
let subshape = Shape::from(&self.shape[depth..]);
1080-
let newshape = Shape::from_iter(subshape.iter().rev().copied());
1080+
let newshape = subshape.iter().rev().copied().collect::<Shape>();
10811081
let chunk_size = subshape.elements();
10821082
let data_slice = self.data.as_mut_slice();
10831083
let mut temp = data_slice[..chunk_size].to_vec();
@@ -1787,7 +1787,10 @@ impl Value {
17871787
/// Convert a string value to a list of UTF-16 code units
17881788
pub fn utf16(&self, env: &Uiua) -> UiuaResult<Self> {
17891789
let s = self.as_string(env, "Argument to utf₁₆ must be a string")?;
1790-
Ok(Array::<f64>::from_iter(s.encode_utf16().map(|u| u as f64)).into())
1790+
Ok(s.encode_utf16()
1791+
.map(|u| u as f64)
1792+
.collect::<Array<f64>>()
1793+
.into())
17911794
}
17921795
/// Convert a list of UTF-8 bytes to a string value
17931796
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
@@ -499,9 +499,10 @@ impl<T: Clone> Array<T> {
499499
return row;
500500
}
501501
let row_count = self.row_count();
502-
if row >= row_count {
503-
panic!("row index out of bounds: {row} >= {row_count}");
504-
}
502+
assert!(
503+
row < row_count,
504+
"row index out of bounds: {row} >= {row_count}"
505+
);
505506
let row_len = self.row_len();
506507
let start = row * row_len;
507508
let end = start + row_len;
@@ -604,9 +605,10 @@ impl<T: ArrayValue> Array<T> {
604605
return row;
605606
}
606607
let row_count: usize = self.shape[..=depth].iter().product();
607-
if row >= row_count {
608-
panic!("row index out of bounds: {row} >= {row_count}");
609-
}
608+
assert!(
609+
row < row_count,
610+
"row index out of bounds: {row} >= {row_count}"
611+
);
610612
let row_len: usize = self.shape[depth + 1..].iter().product();
611613
let start = row * row_len;
612614
let end = start + row_len;

src/compile/data.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,13 @@ impl Compiler {
346346
self.compile_bind_const(
347347
name,
348348
local,
349-
Some(Array::from_iter(fields.iter().map(|f| f.name.as_str())).into()),
349+
Some(
350+
fields
351+
.iter()
352+
.map(|f| f.name.as_str())
353+
.collect::<Array<_>>()
354+
.into(),
355+
),
350356
span,
351357
BindingMeta {
352358
comment: Some(DocComment::from(comment.as_str())),

0 commit comments

Comments
 (0)