Skip to content

Commit d9649de

Browse files
committed
lint: fix clippy::pedantic (6 entries)
1 parent 18bb3c4 commit d9649de

File tree

10 files changed

+66
-84
lines changed

10 files changed

+66
-84
lines changed

Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ print_stdout = "warn"
1717
print_stderr = "allow"
1818
dbg_macro = "warn"
1919
pedantic = {level = "warn", priority = -1}
20-
if_not_else = "allow" # 6
21-
manual_let_else = "allow" # 6
22-
single_char_pattern = "allow" # 6
2320
needless_raw_string_hashes = "allow" # 7
2421
non_std_lazy_statics = "allow" # 7
2522
unnecessary_wraps = "allow" # 7

pad/editor/src/backend.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,7 @@ impl SysBackend for WebBackend {
258258
}
259259
fn file_write_all(&self, path: &Path, contents: &[u8]) -> Result<(), String> {
260260
FILES.with(|files| {
261-
if !files.borrow().contains_key(path) {
262-
files.borrow_mut().insert(path.into(), contents.to_vec());
263-
} else {
264-
*files.borrow_mut().get_mut(path).unwrap() = contents.to_vec();
265-
}
261+
files.borrow_mut().insert(path.into(), contents.to_vec());
266262
});
267263
Ok(())
268264
}

parser/src/parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,7 @@ impl Parser<'_> {
17531753
loop {
17541754
self.ignore_whitespace();
17551755
if let Some(span) = self.exact(Comment) {
1756-
let s = span.as_str(self.inputs, |s| s.trim_start_matches("#").trim().into());
1756+
let s = span.as_str(self.inputs, |s| s.trim_start_matches('#').trim().into());
17571757
lines.push(span.sp(s));
17581758
} else if let Some(sem) = self.next_token_map(Token::as_semantic_comment) {
17591759
semantic.insert(sem.value, sem.span);

site/src/idioms.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn aliases() -> impl IntoView {
4545
.map(|&s| view!(<code>{s}</code>" "))
4646
.collect::<Vec<_>>()
4747
}{
48-
(p.aliases().iter().any(|a| a.contains("&")) || matches!(p, Primitive::Sys(_)))
48+
(p.aliases().iter().any(|a| a.contains('&')) || matches!(p, Primitive::Sys(_)))
4949
.then(|| view!(<span style="opacity: 0.7">"Temporary"</span>))
5050
}</td></tr>)
5151
})

site/src/markdown.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,10 @@ fn node_html<'a>(node: &'a AstNode<'a>) -> String {
291291
if let Some(prim) = Primitive::from_name(name).or_else(|| Primitive::from_name(&text)) {
292292
let symbol_class = format!("prim-glyph {}", prim_class(prim));
293293
let symbol = prim.to_string();
294-
let name = if symbol != prim.name() {
295-
format!(" {}", prim.name())
296-
} else {
294+
let name = if symbol == prim.name() {
297295
"".to_string()
296+
} else {
297+
format!(" {}", prim.name())
298298
};
299299
format!(
300300
r#"<a

site/src/primitive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ fn listed_examples() {
462462
continue;
463463
}
464464
let line = line.replace("\\\"", "<double quote>");
465-
let Some(end) = line.rfind("\"") else {
465+
let Some(end) = line.rfind('"') else {
466466
continue;
467467
};
468468
eprintln!("{line}");

src/algorithm/dyadic/combine.rs

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -355,33 +355,7 @@ impl<T: ArrayValue> Array<T> {
355355
}))?
356356
}
357357

358-
if self.shape[1..] != other.shape[1..] {
359-
// Fill
360-
match ctx.scalar_fill::<T>() {
361-
Ok(fill) => {
362-
if map_keys.is_some() {
363-
return Err(ctx.error(format!(
364-
"Cannot {} {} map arrays",
365-
Primitive::Fill,
366-
Primitive::Join
367-
)));
368-
}
369-
let new_row_shape = max_shape(&self.shape[1..], &other.shape[1..]);
370-
for (array, fill) in [(&mut self, fill.clone()), (&mut other, fill)]
371-
{
372-
let mut new_shape = new_row_shape.clone();
373-
new_shape.prepend(array.shape[0]);
374-
array.fill_to_shape(&new_shape, fill);
375-
}
376-
}
377-
Err(e) => {
378-
return Err(C::fill_error(ctx.error(format!(
379-
"Cannot join arrays of shapes {} and {}. {e}",
380-
self.shape, other.shape
381-
))));
382-
}
383-
}
384-
} else {
358+
if self.shape[1..] == other.shape[1..] {
385359
// Set sorted flags
386360
match (self.row_count(), other.row_count()) {
387361
(0, 0) => {
@@ -412,6 +386,32 @@ impl<T: ArrayValue> Array<T> {
412386
}
413387
}
414388
}
389+
} else {
390+
// Fill
391+
match ctx.scalar_fill::<T>() {
392+
Ok(fill) => {
393+
if map_keys.is_some() {
394+
return Err(ctx.error(format!(
395+
"Cannot {} {} map arrays",
396+
Primitive::Fill,
397+
Primitive::Join
398+
)));
399+
}
400+
let new_row_shape = max_shape(&self.shape[1..], &other.shape[1..]);
401+
for (array, fill) in [(&mut self, fill.clone()), (&mut other, fill)]
402+
{
403+
let mut new_shape = new_row_shape.clone();
404+
new_shape.prepend(array.shape[0]);
405+
array.fill_to_shape(&new_shape, fill);
406+
}
407+
}
408+
Err(e) => {
409+
return Err(C::fill_error(ctx.error(format!(
410+
"Cannot join arrays of shapes {} and {}. {e}",
411+
self.shape, other.shape
412+
))));
413+
}
414+
}
415415
}
416416

417417
if self.data.len() >= other.data.len() {
@@ -1046,9 +1046,8 @@ impl Value {
10461046
}
10471047
}
10481048
row_values = values.into_iter();
1049-
let arr = match row_values.next().unwrap() {
1050-
Value::Num(arr) => arr,
1051-
_ => unreachable!(),
1049+
let Value::Num(arr) = row_values.next().unwrap() else {
1050+
unreachable!()
10521051
};
10531052
if let Some(box_rank) = box_rank {
10541053
Value::Box(arr.box_depth(box_rank))
@@ -1074,9 +1073,8 @@ impl Value {
10741073
}
10751074
}
10761075
row_values = values.into_iter();
1077-
let arr = match row_values.next().unwrap() {
1078-
Value::Byte(arr) => arr,
1079-
_ => unreachable!(),
1076+
let Value::Byte(arr) = row_values.next().unwrap() else {
1077+
unreachable!()
10801078
};
10811079
if let Some(box_rank) = box_rank {
10821080
Value::Box(arr.box_depth(box_rank))
@@ -1100,9 +1098,8 @@ impl Value {
11001098
}
11011099
}
11021100
row_values = values.into_iter();
1103-
let arr = match row_values.next().unwrap() {
1104-
Value::Complex(arr) => arr,
1105-
_ => unreachable!(),
1101+
let Value::Complex(arr) = row_values.next().unwrap() else {
1102+
unreachable!()
11061103
};
11071104
if let Some(box_rank) = box_rank {
11081105
Value::Box(arr.box_depth(box_rank))
@@ -1125,9 +1122,8 @@ impl Value {
11251122
}
11261123
}
11271124
row_values = values.into_iter();
1128-
let arr = match row_values.next().unwrap() {
1129-
Value::Char(arr) => arr,
1130-
_ => unreachable!(),
1125+
let Value::Char(arr) = row_values.next().unwrap() else {
1126+
unreachable!()
11311127
};
11321128
if let Some(box_rank) = box_rank {
11331129
Value::Box(arr.box_depth(box_rank))

src/algorithm/dyadic/structure.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,20 @@ impl Value {
9696
Value::Num(arr) => {
9797
let mut index_data = Vec::with_capacity(arr.element_count());
9898
for &n in &arr.data {
99-
index_data.push(if n.fract() != 0.0 {
100-
if filled {
101-
isize::MAX
102-
} else if n.fract().is_nan() {
103-
return Err(env.error(format!(
104-
"{} cannot be used as an index without a fill",
105-
n.grid_string(false)
106-
)));
107-
} else {
108-
return Err(env.error(format!(
109-
"Index must be an array of integers, but {} is not an integer",
110-
n.grid_string(false)
111-
)));
112-
}
113-
} else {
99+
index_data.push(if n.fract() == 0.0 {
114100
n as isize
101+
} else if filled {
102+
isize::MAX
103+
} else if n.fract().is_nan() {
104+
return Err(env.error(format!(
105+
"{} cannot be used as an index without a fill",
106+
n.grid_string(false)
107+
)));
108+
} else {
109+
return Err(env.error(format!(
110+
"Index must be an array of integers, but {} is not an integer",
111+
n.grid_string(false)
112+
)));
115113
});
116114
}
117115
(&arr.shape, index_data)

src/algorithm/monadic/mod.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,9 @@ impl Value {
223223
(0 | 1, Value::Char(arr)) => {
224224
let s: String = arr.data.iter().copied().collect();
225225
match (
226-
s.strip_suffix("i").and_then(|s| s.split_once("r")),
227-
s.strip_suffix("i").and_then(|s| s.split_once("+")),
228-
s.strip_suffix("i").and_then(|s| s.split_once("-")),
226+
s.strip_suffix('i').and_then(|s| s.split_once('r')),
227+
s.strip_suffix('i').and_then(|s| s.split_once('+')),
228+
s.strip_suffix('i').and_then(|s| s.split_once('-')),
229229
) {
230230
(Some((re, im)), None, _) | (None, Some((re, im)), _) => {
231231
let re = parse_uiua_num(re.into(), env);
@@ -2060,17 +2060,16 @@ 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 recip_delta = if delta != 0.0 { 1.0 / delta } else { 0.0 };
2064-
let h = if delta != 0.0 {
2063+
let h = if delta == 0.0 {
2064+
0.0
2065+
} else {
20652066
(TAU * if max == r {
2066-
((g - b) * recip_delta).rem_euclid(6.0)
2067+
((g - b) / delta).rem_euclid(6.0)
20672068
} else if max == g {
2068-
(b - r).mul_add(recip_delta, 2.0)
2069+
(b - r) / delta + 2.0
20692070
} else {
2070-
(r - g).mul_add(recip_delta, 4.0)
2071+
(r - g) / delta + 4.0
20712072
}) / 6.0
2072-
} else {
2073-
0.0
20742073
};
20752074
let s = if max == 0.0 { 0.0 } else { 1.0 - min / max };
20762075
let v = max;

src/lsp.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,9 +1313,7 @@ mod server {
13131313
}
13141314

13151315
let doc_uri = &params.text_document_position.text_document.uri;
1316-
let doc = if let Some(doc) = self.doc(doc_uri) {
1317-
doc
1318-
} else {
1316+
let Some(doc) = self.doc(doc_uri) else {
13191317
return Ok(None);
13201318
};
13211319
let (line, col) = lsp_pos_to_uiua(params.text_document_position.position, &doc.input);
@@ -1431,9 +1429,7 @@ mod server {
14311429
&self,
14321430
params: DocumentFormattingParams,
14331431
) -> Result<Option<Vec<TextEdit>>> {
1434-
let doc = if let Some(doc) = self.doc(&params.text_document.uri) {
1435-
doc
1436-
} else {
1432+
let Some(doc) = self.doc(&params.text_document.uri) else {
14371433
return Ok(None);
14381434
};
14391435
match format_str(&doc.input, &FormatConfig::find().unwrap_or_default()) {

0 commit comments

Comments
 (0)