Skip to content

Commit e6b3f11

Browse files
committed
lint: fix clippy::pedantic (11-12 entries)
1 parent e36a271 commit e6b3f11

File tree

19 files changed

+156
-183
lines changed

19 files changed

+156
-183
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-
single_match_else = "allow" # 11
21-
manual_string_new = "allow" # 12
22-
trivially_copy_pass_by_ref = "allow" # 12
2320
ptr_cast_constness = "allow" # 15
2421
redundant_else = "allow" # 15
2522
unnecessary_semicolon = "allow" # 15

pad/editor/src/backend.rs

Lines changed: 50 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl SysBackend for WebBackend {
189189
stdout.push(OutputItem::String(line.into()));
190190
}
191191
if s.ends_with('\n') {
192-
stdout.push(OutputItem::String("".into()));
192+
stdout.push(OutputItem::String(String::new()));
193193
}
194194
Ok(())
195195
}
@@ -510,64 +510,61 @@ impl SysBackend for WebBackend {
510510
))
511511
.await;
512512

513-
match tree_res {
514-
Err(_) => {
515-
cache_url(&url, tree_res);
513+
if tree_res.is_err() {
514+
cache_url(&url, tree_res);
515+
unmark_working(&original_url);
516+
return;
517+
} else {
518+
let tree = tree_res.unwrap();
519+
let tree: serde_json::Value = serde_json::from_str(&tree).unwrap();
520+
let tree = tree.get("tree").unwrap().as_array().unwrap();
521+
let paths = tree
522+
.iter()
523+
.filter_map(|entry| {
524+
let path = entry.get("path")?.as_str()?;
525+
if Path::new(path)
526+
.extension()
527+
.is_some_and(|ext| ext.eq_ignore_ascii_case("ua"))
528+
{
529+
Some(path.to_string())
530+
} else {
531+
None
532+
}
533+
})
534+
.collect::<HashSet<_>>();
535+
536+
if !paths.contains("lib.ua") {
537+
cache_url(&url, Err("lib.ua not found".into()));
516538
unmark_working(&original_url);
517539
return;
518540
}
519-
Ok(_) => {
520-
let tree = tree_res.unwrap();
521-
let tree: serde_json::Value = serde_json::from_str(&tree).unwrap();
522-
let tree = tree.get("tree").unwrap().as_array().unwrap();
523-
let paths = tree
524-
.iter()
525-
.filter_map(|entry| {
526-
let path = entry.get("path")?.as_str()?;
527-
if Path::new(path)
528-
.extension()
529-
.is_some_and(|ext| ext.eq_ignore_ascii_case("ua"))
530-
{
531-
Some(path.to_string())
532-
} else {
533-
None
534-
}
535-
})
536-
.collect::<HashSet<_>>();
537-
538-
if !paths.contains("lib.ua") {
539-
cache_url(&url, Err("lib.ua not found".into()));
540-
unmark_working(&original_url);
541-
return;
542-
}
543541

544-
let results = join_all(paths.iter().map(|path| {
545-
let repo_owner = repo_owner.clone();
546-
let repo_name = repo_name.clone();
547-
async move {
548-
let fetch_url = format!(
549-
"https://raw.githubusercontent.com\
550-
/{repo_owner}/{repo_name}/main/{path}",
551-
);
552-
let internal_path = Path::new("uiua-modules")
553-
.join(repo_owner)
554-
.join(repo_name)
555-
.join(path.clone());
556-
557-
(path, internal_path, fetch(fetch_url.as_str()).await)
558-
}
559-
}))
560-
.await;
542+
let results = join_all(paths.iter().map(|path| {
543+
let repo_owner = repo_owner.clone();
544+
let repo_name = repo_name.clone();
545+
async move {
546+
let fetch_url = format!(
547+
"https://raw.githubusercontent.com\
548+
/{repo_owner}/{repo_name}/main/{path}",
549+
);
550+
let internal_path = Path::new("uiua-modules")
551+
.join(repo_owner)
552+
.join(repo_name)
553+
.join(path.clone());
554+
555+
(path, internal_path, fetch(fetch_url.as_str()).await)
556+
}
557+
}))
558+
.await;
561559

562-
for (original_path, internal_path, res) in results {
563-
if original_path.eq("lib.ua") {
564-
cache_url(&url, res.clone());
565-
}
560+
for (original_path, internal_path, res) in results {
561+
if original_path.eq("lib.ua") {
562+
cache_url(&url, res.clone());
563+
}
566564

567-
if let Ok(text) = res {
568-
let contents = text.as_bytes().to_vec();
569-
drop_file(internal_path.clone(), contents);
570-
}
565+
if let Ok(text) = res {
566+
let contents = text.as_bytes().to_vec();
567+
drop_file(internal_path.clone(), contents);
571568
}
572569
}
573570
}

pad/editor/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,7 +1854,7 @@ pub fn Editor<'a>(
18541854

18551855
let editor_style = move || {
18561856
if !fullscreen_enabled.get() {
1857-
return "".to_string();
1857+
return String::new();
18581858
}
18591859

18601860
let ratio = splitter_ratio.get();
@@ -2250,7 +2250,7 @@ pub fn Prim(
22502250
let name = if !glyph_only && symbol != prim.name() {
22512251
format!(" {}", prim.name())
22522252
} else {
2253-
"".to_string()
2253+
String::new()
22542254
};
22552255
let href = format!("/docs/{}", prim.name());
22562256
let mut title = String::new();

pad/editor/src/utils.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ fn run_code_single(id: &str, code: &str) -> (Vec<OutputItem>, Option<UiuaError>)
12411241
}
12421242
if !stdout.is_empty() {
12431243
if !output.is_empty() {
1244-
output.push(OutputItem::String("".into()));
1244+
output.push(OutputItem::String(String::new()));
12451245
}
12461246
if label {
12471247
output.push(OutputItem::String("stdout:".to_string()));
@@ -1250,7 +1250,7 @@ fn run_code_single(id: &str, code: &str) -> (Vec<OutputItem>, Option<UiuaError>)
12501250
}
12511251
if !stderr.is_empty() {
12521252
if !output.is_empty() {
1253-
output.push(OutputItem::String("".into()));
1253+
output.push(OutputItem::String(String::new()));
12541254
}
12551255
if label {
12561256
output.push(OutputItem::String("stderr:".to_string()));
@@ -1265,7 +1265,7 @@ fn run_code_single(id: &str, code: &str) -> (Vec<OutputItem>, Option<UiuaError>)
12651265
}
12661266
if let Some(error) = &error {
12671267
if !output.is_empty() {
1268-
output.push(OutputItem::String("".into()));
1268+
output.push(OutputItem::String(String::new()));
12691269
}
12701270
const MAX_OUTPUT_BEFORE_ERROR: usize = 60;
12711271
if output.len() >= MAX_OUTPUT_BEFORE_ERROR {
@@ -1283,7 +1283,7 @@ fn run_code_single(id: &str, code: &str) -> (Vec<OutputItem>, Option<UiuaError>)
12831283
}
12841284
if !diagnostics.is_empty() {
12851285
if !output.is_empty() {
1286-
output.push(OutputItem::String("".into()));
1286+
output.push(OutputItem::String(String::new()));
12871287
}
12881288
for diag in diagnostics {
12891289
output.push(OutputItem::Report(diag.report()));
@@ -1408,7 +1408,7 @@ pub fn progressive_strings(input: &str) -> Vec<String> {
14081408
curr_total.push('\n');
14091409
}
14101410
if strings.is_empty() {
1411-
strings.push("".into());
1411+
strings.push(String::new());
14121412
}
14131413
strings.rotate_right(1);
14141414
strings[0] = input.into();

parser/src/parse.rs

Lines changed: 46 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -306,25 +306,22 @@ impl Parser<'_> {
306306
}
307307
let mut trailing_newline = false;
308308
loop {
309-
match self.item(kind) {
310-
Some(item) => {
311-
trailing_newline = false;
312-
items.push(item)
309+
if let Some(item) = self.item(kind) {
310+
trailing_newline = false;
311+
items.push(item)
312+
} else {
313+
if self.exact(Newline).is_none() {
314+
break;
313315
}
314-
None => {
315-
if self.exact(Newline).is_none() {
316-
break;
317-
}
318-
trailing_newline = true;
316+
trailing_newline = true;
317+
self.spaces();
318+
let mut extra_newlines = false;
319+
while self.exact(Newline).is_some() {
320+
extra_newlines = true;
319321
self.spaces();
320-
let mut extra_newlines = false;
321-
while self.exact(Newline).is_some() {
322-
extra_newlines = true;
323-
self.spaces();
324-
}
325-
if extra_newlines {
326-
items.push(Item::Words(Vec::new()));
327-
}
322+
}
323+
if extra_newlines {
324+
items.push(Item::Words(Vec::new()));
328325
}
329326
}
330327
}
@@ -940,31 +937,28 @@ impl Parser<'_> {
940937
let range = self.real()?.span.byte_range();
941938
let s = &self.input[range];
942939
Some(if let Some((a, o)) = s.split_once('.') {
943-
let a = match a.parse() {
944-
Ok(a) => a,
945-
Err(_) => {
946-
self.errors
947-
.push(self.prev_span().sp(ParseError::InvalidArgCount(a.into())));
948-
1
949-
}
940+
let a = if let Ok(a) = a.parse() {
941+
a
942+
} else {
943+
self.errors
944+
.push(self.prev_span().sp(ParseError::InvalidArgCount(a.into())));
945+
1
950946
};
951-
let o = match o.parse() {
952-
Ok(o) => o,
953-
Err(_) => {
954-
self.errors
955-
.push(self.prev_span().sp(ParseError::InvalidOutCount(o.into())));
956-
1
957-
}
947+
let o = if let Ok(o) = o.parse() {
948+
o
949+
} else {
950+
self.errors
951+
.push(self.prev_span().sp(ParseError::InvalidOutCount(o.into())));
952+
1
958953
};
959954
(a, o)
960955
} else {
961-
let a = match s.parse() {
962-
Ok(a) => a,
963-
Err(_) => {
964-
self.errors
965-
.push(self.prev_span().sp(ParseError::InvalidArgCount(s.into())));
966-
1
967-
}
956+
let a = if let Ok(a) = s.parse() {
957+
a
958+
} else {
959+
self.errors
960+
.push(self.prev_span().sp(ParseError::InvalidArgCount(s.into())));
961+
1
968962
};
969963
(a, 1)
970964
})
@@ -1029,27 +1023,23 @@ impl Parser<'_> {
10291023
// Collect items
10301024
let mut items = Vec::new();
10311025
while self.exact(Underscore.into()).is_some() {
1032-
let item = match self.modified() {
1033-
Some(mut item) => {
1034-
if let Word::Spaces = item.value {
1035-
if items.is_empty() {
1036-
break;
1037-
}
1038-
self.errors.push(self.expected([Expectation::Term]));
1039-
item = match self.modified() {
1040-
Some(item) => item,
1041-
None => {
1042-
self.errors.push(self.expected([Expectation::Term]));
1043-
break;
1044-
}
1045-
};
1026+
let item = if let Some(mut item) = self.modified() {
1027+
if let Word::Spaces = item.value {
1028+
if items.is_empty() {
1029+
break;
10461030
}
1047-
item
1048-
}
1049-
None => {
10501031
self.errors.push(self.expected([Expectation::Term]));
1051-
break;
1032+
item = if let Some(item) = self.modified() {
1033+
item
1034+
} else {
1035+
self.errors.push(self.expected([Expectation::Term]));
1036+
break;
1037+
};
10521038
}
1039+
item
1040+
} else {
1041+
self.errors.push(self.expected([Expectation::Term]));
1042+
break;
10531043
};
10541044
items.push(item);
10551045
}

site/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ fn prim_html(prim: Primitive, glyph_only: bool, hide_docs: bool) -> String {
410410
let name = if !glyph_only && symbol != prim.name() {
411411
format!(" {}", prim.name())
412412
} else {
413-
"".to_string()
413+
String::new()
414414
};
415415
let href = format!("/docs/{}", prim.name());
416416
let mut title = String::new();

site/src/markdown.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ fn node_html<'a>(node: &'a AstNode<'a>) -> String {
292292
let symbol_class = format!("prim-glyph {}", prim_class(prim));
293293
let symbol = prim.to_string();
294294
let name = if symbol == prim.name() {
295-
"".to_string()
295+
String::new()
296296
} else {
297297
format!(" {}", prim.name())
298298
};

site/src/other_tutorial.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ pub enum OtherTutorialPage {
2222
}
2323

2424
impl OtherTutorialPage {
25-
pub fn path(&self) -> String {
25+
pub fn path(self) -> String {
2626
format!("{self:?}").to_lowercase()
2727
}
28-
pub fn view(&self) -> View {
28+
pub fn view(self) -> View {
2929
match self {
3030
Self::Strings => title_markdown(
3131
"Strings",
@@ -52,7 +52,7 @@ impl OtherTutorialPage {
5252
Self::EvenMoreStack => EvenMoreStack().into_view(),
5353
}
5454
}
55-
pub fn title(&self) -> &'static str {
55+
pub fn title(self) -> &'static str {
5656
match self {
5757
OtherTutorialPage::Strings => "Strings",
5858
OtherTutorialPage::FilesAndStreams => "Files and Streams",
@@ -64,7 +64,7 @@ impl OtherTutorialPage {
6464
OtherTutorialPage::Ranges => "Ranges",
6565
}
6666
}
67-
pub fn description(&self) -> Cow<'static, str> {
67+
pub fn description(self) -> Cow<'static, str> {
6868
Cow::Borrowed(match self {
6969
OtherTutorialPage::Strings => "how to manipulate strings",
7070
OtherTutorialPage::FilesAndStreams => "how to read and write files and streams",

site/src/tutorial.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ pub enum TutorialPage {
3535
}
3636

3737
impl TutorialPage {
38-
pub fn path(&self) -> String {
38+
pub fn path(self) -> String {
3939
format!("{self:?}").to_lowercase()
4040
}
41-
pub fn title(&self) -> &'static str {
41+
pub fn title(self) -> &'static str {
4242
match self {
4343
Self::Introduction => "Introduction",
4444
Self::Basic => "Basic Stack Operations and Formatting",

0 commit comments

Comments
 (0)