From f3c423d77d61ae2baa5b9de0806a1e937de90517 Mon Sep 17 00:00:00 2001 From: Micah Date: Fri, 10 Oct 2025 13:00:56 -0700 Subject: [PATCH] Fix the various lints (#1124) --- crates/memofs/src/in_memory_fs.rs | 22 ++++++---------- crates/memofs/src/noop_backend.rs | 40 ++++++------------------------ crates/memofs/src/std_backend.rs | 6 ++--- src/cli/upload.rs | 29 +--------------------- src/snapshot/metadata.rs | 2 +- src/snapshot/tree.rs | 4 +-- src/snapshot_middleware/project.rs | 2 +- tests/rojo_test/serve_util.rs | 2 +- 8 files changed, 24 insertions(+), 83 deletions(-) diff --git a/crates/memofs/src/in_memory_fs.rs b/crates/memofs/src/in_memory_fs.rs index fc8cf2ef..7bc654af 100644 --- a/crates/memofs/src/in_memory_fs.rs +++ b/crates/memofs/src/in_memory_fs.rs @@ -228,23 +228,17 @@ impl VfsBackend for InMemoryFs { } fn must_be_file(path: &Path) -> io::Result { - Err(io::Error::new( - io::ErrorKind::Other, - format!( - "path {} was a directory, but must be a file", - path.display() - ), - )) + Err(io::Error::other(format!( + "path {} was a directory, but must be a file", + path.display() + ))) } fn must_be_dir(path: &Path) -> io::Result { - Err(io::Error::new( - io::ErrorKind::Other, - format!( - "path {} was a file, but must be a directory", - path.display() - ), - )) + Err(io::Error::other(format!( + "path {} was a file, but must be a directory", + path.display() + ))) } fn not_found(path: &Path) -> io::Result { diff --git a/crates/memofs/src/noop_backend.rs b/crates/memofs/src/noop_backend.rs index efc8fd4a..31a2cca9 100644 --- a/crates/memofs/src/noop_backend.rs +++ b/crates/memofs/src/noop_backend.rs @@ -15,45 +15,27 @@ impl NoopBackend { impl VfsBackend for NoopBackend { fn read(&mut self, _path: &Path) -> io::Result> { - Err(io::Error::new( - io::ErrorKind::Other, - "NoopBackend doesn't do anything", - )) + Err(io::Error::other("NoopBackend doesn't do anything")) } fn write(&mut self, _path: &Path, _data: &[u8]) -> io::Result<()> { - Err(io::Error::new( - io::ErrorKind::Other, - "NoopBackend doesn't do anything", - )) + Err(io::Error::other("NoopBackend doesn't do anything")) } fn read_dir(&mut self, _path: &Path) -> io::Result { - Err(io::Error::new( - io::ErrorKind::Other, - "NoopBackend doesn't do anything", - )) + Err(io::Error::other("NoopBackend doesn't do anything")) } fn remove_file(&mut self, _path: &Path) -> io::Result<()> { - Err(io::Error::new( - io::ErrorKind::Other, - "NoopBackend doesn't do anything", - )) + Err(io::Error::other("NoopBackend doesn't do anything")) } fn remove_dir_all(&mut self, _path: &Path) -> io::Result<()> { - Err(io::Error::new( - io::ErrorKind::Other, - "NoopBackend doesn't do anything", - )) + Err(io::Error::other("NoopBackend doesn't do anything")) } fn metadata(&mut self, _path: &Path) -> io::Result { - Err(io::Error::new( - io::ErrorKind::Other, - "NoopBackend doesn't do anything", - )) + Err(io::Error::other("NoopBackend doesn't do anything")) } fn event_receiver(&self) -> crossbeam_channel::Receiver { @@ -61,17 +43,11 @@ impl VfsBackend for NoopBackend { } fn watch(&mut self, _path: &Path) -> io::Result<()> { - Err(io::Error::new( - io::ErrorKind::Other, - "NoopBackend doesn't do anything", - )) + Err(io::Error::other("NoopBackend doesn't do anything")) } fn unwatch(&mut self, _path: &Path) -> io::Result<()> { - Err(io::Error::new( - io::ErrorKind::Other, - "NoopBackend doesn't do anything", - )) + Err(io::Error::other("NoopBackend doesn't do anything")) } } diff --git a/crates/memofs/src/std_backend.rs b/crates/memofs/src/std_backend.rs index 0a8fb3b7..54c142dc 100644 --- a/crates/memofs/src/std_backend.rs +++ b/crates/memofs/src/std_backend.rs @@ -109,15 +109,13 @@ impl VfsBackend for StdBackend { self.watches.insert(path.to_path_buf()); self.watcher .watch(path, RecursiveMode::Recursive) - .map_err(|inner| io::Error::new(io::ErrorKind::Other, inner)) + .map_err(io::Error::other) } } fn unwatch(&mut self, path: &Path) -> io::Result<()> { self.watches.remove(path); - self.watcher - .unwatch(path) - .map_err(|inner| io::Error::new(io::ErrorKind::Other, inner)) + self.watcher.unwatch(path).map_err(io::Error::other) } } diff --git a/src/cli/upload.rs b/src/cli/upload.rs index ce7a2b5d..3c3610fd 100644 --- a/src/cli/upload.rs +++ b/src/cli/upload.rs @@ -1,7 +1,6 @@ use std::path::PathBuf; -use std::str::FromStr; -use anyhow::{bail, format_err, Context}; +use anyhow::{bail, Context}; use clap::Parser; use memofs::Vfs; use reqwest::{ @@ -91,32 +90,6 @@ impl UploadCommand { } } -/// The kind of asset to upload to the website. Affects what endpoints Rojo uses -/// and changes how the asset is built. -#[derive(Debug, Clone, Copy)] -enum UploadKind { - /// Upload to a place. - Place, - - /// Upload to a model-like asset, like a Model, Plugin, or Package. - Model, -} - -impl FromStr for UploadKind { - type Err = anyhow::Error; - - fn from_str(source: &str) -> Result { - match source { - "place" => Ok(UploadKind::Place), - "model" => Ok(UploadKind::Model), - attempted => Err(format_err!( - "Invalid upload kind '{}'. Valid kinds are: place, model", - attempted - )), - } - } -} - fn do_upload(buffer: Vec, asset_id: u64, cookie: &str) -> anyhow::Result<()> { let url = format!( "https://data.roblox.com/Data/Upload.ashx?assetid={}", diff --git a/src/snapshot/metadata.rs b/src/snapshot/metadata.rs index abe66df2..20505f29 100644 --- a/src/snapshot/metadata.rs +++ b/src/snapshot/metadata.rs @@ -221,7 +221,7 @@ pub enum InstigatingSource { ProjectNode( #[serde(serialize_with = "path_serializer::serialize_absolute")] PathBuf, String, - ProjectNode, + Box, Option, ), } diff --git a/src/snapshot/tree.rs b/src/snapshot/tree.rs index c2cabac5..76bcdc07 100644 --- a/src/snapshot/tree.rs +++ b/src/snapshot/tree.rs @@ -73,7 +73,7 @@ impl RojoTree { self.inner.root_ref() } - pub fn get_instance(&self, id: Ref) -> Option { + pub fn get_instance(&self, id: Ref) -> Option> { if let Some(instance) = self.inner.get_by_ref(id) { let metadata = self.metadata_map.get(&id).unwrap(); @@ -83,7 +83,7 @@ impl RojoTree { } } - pub fn get_instance_mut(&mut self, id: Ref) -> Option { + pub fn get_instance_mut(&mut self, id: Ref) -> Option> { if let Some(instance) = self.inner.get_by_ref_mut(id) { let metadata = self.metadata_map.get_mut(&id).unwrap(); diff --git a/src/snapshot_middleware/project.rs b/src/snapshot_middleware/project.rs index a9816a73..819e57b3 100644 --- a/src/snapshot_middleware/project.rs +++ b/src/snapshot_middleware/project.rs @@ -289,7 +289,7 @@ pub fn snapshot_project_node( metadata.instigating_source = Some(InstigatingSource::ProjectNode( project_path.to_path_buf(), instance_name.to_string(), - node.clone(), + Box::new(node.clone()), parent_class.map(|name| name.to_owned()), )); diff --git a/tests/rojo_test/serve_util.rs b/tests/rojo_test/serve_util.rs index 71d07778..22cc630f 100644 --- a/tests/rojo_test/serve_util.rs +++ b/tests/rojo_test/serve_util.rs @@ -160,7 +160,7 @@ impl TestServeSession { Ok(serde_json::from_str(&body).expect("Server returned malformed response")) } - pub fn get_api_read(&self, id: Ref) -> Result { + pub fn get_api_read(&self, id: Ref) -> Result, reqwest::Error> { let url = format!("http://localhost:{}/api/read/{}", self.port, id); let body = reqwest::blocking::get(url)?.text()?;