From 44c94da2d8f7416f23fba716e6149a2bd5f40994 Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Thu, 17 Oct 2019 18:22:53 -0700 Subject: [PATCH] Fix clippy warnings --- src/auth_cookie.rs | 2 +- src/change_processor.rs | 21 ++++++++++++--------- src/commands/build.rs | 4 ++-- src/commands/serve.rs | 2 +- src/commands/upload.rs | 4 ++-- src/multimap.rs | 4 ++-- src/path_serializer.rs | 2 +- src/project.rs | 6 +++--- src/serve_session.rs | 4 ++-- src/session_id.rs | 3 +++ src/snapshot_middleware/json_model.rs | 2 +- src/snapshot_middleware/lua.rs | 2 ++ src/vfs/mod.rs | 3 +++ src/vfs/real_fetcher.rs | 2 +- src/web/api.rs | 10 ++++------ src/web/interface.rs | 2 +- src/web/ui.rs | 2 +- 17 files changed, 42 insertions(+), 33 deletions(-) diff --git a/src/auth_cookie.rs b/src/auth_cookie.rs index 9d968dd8..83b2ca61 100644 --- a/src/auth_cookie.rs +++ b/src/auth_cookie.rs @@ -13,7 +13,7 @@ pub fn get_auth_cookie() -> Option { let entry: String = cookies.get_value(".ROBLOSECURITY").ok()?; let mut cookie = None; - for kv_pair in entry.split(",") { + for kv_pair in entry.split(',') { let mut pieces = kv_pair.split("::"); if let Some("COOK") = pieces.next() { diff --git a/src/change_processor.rs b/src/change_processor.rs index 3e89ae5d..f6b7fff6 100644 --- a/src/change_processor.rs +++ b/src/change_processor.rs @@ -52,9 +52,15 @@ impl ChangeProcessor { ) { let vfs_receiver = vfs.change_receiver(); - // Crossbeam's select macro generates code that Clippy doesn't like, and - // Clippy blames us for it. - #[allow(clippy::drop_copy)] + #[allow( + // Crossbeam's select macro generates code that Clippy doesn't like, + // and Clippy blames us for it. + clippy::drop_copy, + + // Crossbeam uses 0 as *const _ and Clippy doesn't like that either, + // but this isn't our fault. + clippy::zero_ptr, + )] loop { select! { recv(vfs_receiver) -> event => { @@ -142,12 +148,9 @@ fn update_affected_instances( // TODO: Use persisted snapshot // context struct instead of // recreating it every time. - let snapshot = - snapshot_from_vfs(&mut InstanceSnapshotContext::default(), &vfs, &entry) - .expect("snapshot failed") - .expect("snapshot did not return an instance"); - - snapshot + snapshot_from_vfs(&mut InstanceSnapshotContext::default(), &vfs, &entry) + .expect("snapshot failed") + .expect("snapshot did not return an instance") } InstigatingSource::ProjectNode(_, _) => { log::warn!("Instance {} had an instigating source that was a project node, which is not yet supported.", id); diff --git a/src/commands/build.rs b/src/commands/build.rs index 54054a96..8f9fed5c 100644 --- a/src/commands/build.rs +++ b/src/commands/build.rs @@ -81,9 +81,9 @@ pub fn build(options: &BuildOptions) -> Result<(), BuildError> { log::debug!("Hoping to generate file of type {:?}", output_kind); log::trace!("Constructing in-memory filesystem"); - let mut vfs = Vfs::new(RealFetcher::new(WatchMode::Disabled)); + let vfs = Vfs::new(RealFetcher::new(WatchMode::Disabled)); - let (_maybe_project, tree) = common_setup::start(&options.fuzzy_project_path, &mut vfs); + let (_maybe_project, tree) = common_setup::start(&options.fuzzy_project_path, &vfs); let root_id = tree.get_root_id(); log::trace!("Opening output file for write"); diff --git a/src/commands/serve.rs b/src/commands/serve.rs index bc021e91..26a35b39 100644 --- a/src/commands/serve.rs +++ b/src/commands/serve.rs @@ -65,7 +65,7 @@ fn show_start_message(port: u16) -> io::Result<()> { buffer.set_color(ColorSpec::new().set_fg(Some(Color::Green)).set_bold(true))?; writeln!(&mut buffer, "{}", port)?; - writeln!(&mut buffer, "")?; + writeln!(&mut buffer)?; buffer.set_color(&ColorSpec::new())?; write!(&mut buffer, "Visit ")?; diff --git a/src/commands/upload.rs b/src/commands/upload.rs index df6d6a0e..68054591 100644 --- a/src/commands/upload.rs +++ b/src/commands/upload.rs @@ -44,9 +44,9 @@ pub fn upload(options: UploadOptions) -> Result<(), UploadError> { .ok_or(UploadError::NeedAuthCookie)?; log::trace!("Constructing in-memory filesystem"); - let mut vfs = Vfs::new(RealFetcher::new(WatchMode::Disabled)); + let vfs = Vfs::new(RealFetcher::new(WatchMode::Disabled)); - let (_maybe_project, tree) = common_setup::start(&options.fuzzy_project_path, &mut vfs); + let (_maybe_project, tree) = common_setup::start(&options.fuzzy_project_path, &vfs); let root_id = tree.get_root_id(); let mut buffer = Vec::new(); diff --git a/src/multimap.rs b/src/multimap.rs index 19708552..02191e6a 100644 --- a/src/multimap.rs +++ b/src/multimap.rs @@ -31,7 +31,7 @@ impl MultiMap { let bucket = self.inner.entry(k).or_default(); for value in &*bucket { - if &*value == &v { + if *value == v { return; } } @@ -49,7 +49,7 @@ impl MultiMap { removed_value = Some(bucket.swap_remove(index)); } - if bucket.len() == 0 { + if bucket.is_empty() { self.inner.remove(k.borrow()); } diff --git a/src/path_serializer.rs b/src/path_serializer.rs index e3212077..a44e636e 100644 --- a/src/path_serializer.rs +++ b/src/path_serializer.rs @@ -91,7 +91,7 @@ where #[derive(Serialize)] struct WithAbsolute<'a>(#[serde(serialize_with = "serialize_absolute")] &'a Path); -pub fn serialize_vec_absolute(paths: &Vec, serializer: S) -> Result +pub fn serialize_vec_absolute(paths: &[T], serializer: S) -> Result where S: Serializer, T: AsRef, diff --git a/src/project.rs b/src/project.rs index fa2e7cc8..e8da842d 100644 --- a/src/project.rs +++ b/src/project.rs @@ -11,10 +11,10 @@ use log::warn; use rbx_dom_weak::{RbxValue, UnresolvedRbxValue}; use serde::{Deserialize, Serialize, Serializer}; -static DEFAULT_PLACE: &'static str = include_str!("../assets/place.project.json"); +static DEFAULT_PLACE: &str = include_str!("../assets/place.project.json"); -pub static PROJECT_FILENAME: &'static str = "default.project.json"; -pub static COMPAT_PROJECT_FILENAME: &'static str = "roblox-project.json"; +pub static PROJECT_FILENAME: &str = "default.project.json"; +pub static COMPAT_PROJECT_FILENAME: &str = "roblox-project.json"; /// SourceProject is the format that users author projects on-disk. Since we /// want to do things like transforming paths to be absolute before handing them diff --git a/src/serve_session.rs b/src/serve_session.rs index cd3865ce..0652a728 100644 --- a/src/serve_session.rs +++ b/src/serve_session.rs @@ -78,14 +78,14 @@ impl ServeSession { /// The project file is expected to be loaded out-of-band since it's /// currently loaded from the filesystem directly instead of through the /// in-memory filesystem layer. - pub fn new>(mut vfs: Vfs, start_path: P) -> Self { + pub fn new>(vfs: Vfs, start_path: P) -> Self { let start_path = start_path.as_ref(); log::trace!("Starting new ServeSession at path {}", start_path.display(),); let start_time = Instant::now(); - let (root_project, tree) = common_setup::start(start_path, &mut vfs); + let (root_project, tree) = common_setup::start(start_path, &vfs); let session_id = SessionId::new(); let message_queue = MessageQueue::new(); diff --git a/src/session_id.rs b/src/session_id.rs index d178a5b4..06ca1dd2 100644 --- a/src/session_id.rs +++ b/src/session_id.rs @@ -1,3 +1,6 @@ +// Default doesn't make sense for a type whose constructor is random. +#![allow(clippy::new_without_default)] + use std::fmt; use serde::{Deserialize, Serialize}; diff --git a/src/snapshot_middleware/json_model.rs b/src/snapshot_middleware/json_model.rs index 18aaa53d..8f1203f3 100644 --- a/src/snapshot_middleware/json_model.rs +++ b/src/snapshot_middleware/json_model.rs @@ -36,7 +36,7 @@ impl SnapshotMiddleware for SnapshotJsonModel { serde_json::from_slice(&entry.contents(vfs)?).expect("TODO: Handle serde_json errors"); if let Some(json_name) = &instance.name { - if json_name != &instance_name { + if json_name != instance_name { log::warn!( "Name from JSON model did not match its file name: {}", entry.path().display() diff --git a/src/snapshot_middleware/lua.rs b/src/snapshot_middleware/lua.rs index 2ebb7c2a..cba22156 100644 --- a/src/snapshot_middleware/lua.rs +++ b/src/snapshot_middleware/lua.rs @@ -36,6 +36,8 @@ impl SnapshotMiddleware for SnapshotLua { if entry.is_file() { snapshot_lua_file(vfs, entry) } else { + // At this point, our entry is definitely a directory! + if let Some(snapshot) = snapshot_init(context, vfs, entry, "init.lua")? { // An `init.lua` file turns its parent into a ModuleScript Ok(Some(snapshot)) diff --git a/src/vfs/mod.rs b/src/vfs/mod.rs index 32b48f0b..34a14a3d 100644 --- a/src/vfs/mod.rs +++ b/src/vfs/mod.rs @@ -4,6 +4,9 @@ mod fetcher; mod noop_fetcher; mod real_fetcher; mod snapshot; + +// I don't think module inception is a real problem? +#[allow(clippy::module_inception)] mod vfs; pub use error::*; diff --git a/src/vfs/real_fetcher.rs b/src/vfs/real_fetcher.rs index 5dce585c..7add1022 100644 --- a/src/vfs/real_fetcher.rs +++ b/src/vfs/real_fetcher.rs @@ -220,6 +220,6 @@ impl VfsFetcher for RealFetcher { fn watched_paths(&self) -> Vec { let watched_paths = self.watched_paths.lock().unwrap(); - watched_paths.iter().map(|v| v.clone()).collect() + watched_paths.iter().cloned().collect() } } diff --git a/src/web/api.rs b/src/web/api.rs index 676ddfdb..fe7ad62c 100644 --- a/src/web/api.rs +++ b/src/web/api.rs @@ -39,12 +39,10 @@ impl Service for ApiService { (&Method::GET, path) if path.starts_with("/api/subscribe/") => { self.handle_api_subscribe(request) } - (_method, path) => { - return json( - ErrorResponse::not_found(format!("Route not found: {}", path)), - StatusCode::NOT_FOUND, - ) - } + (_method, path) => json( + ErrorResponse::not_found(format!("Route not found: {}", path)), + StatusCode::NOT_FOUND, + ), } } } diff --git a/src/web/interface.rs b/src/web/interface.rs index ceab02fd..f748758c 100644 --- a/src/web/interface.rs +++ b/src/web/interface.rs @@ -67,7 +67,7 @@ pub struct Instance<'a> { } impl<'a> Instance<'a> { - pub(crate) fn from_rojo_instance<'b>(source: InstanceWithMeta<'b>) -> Instance<'b> { + pub(crate) fn from_rojo_instance(source: InstanceWithMeta<'_>) -> Instance<'_> { Instance { id: source.id(), parent: source.parent(), diff --git a/src/web/ui.rs b/src/web/ui.rs index 8f7276be..7a6b0b5b 100644 --- a/src/web/ui.rs +++ b/src/web/ui.rs @@ -336,7 +336,7 @@ impl UiService { // Round off all of our sub-second precision to make timestamps // nicer. - let just_nanos = Duration::from_nanos(elapsed.subsec_nanos() as u64); + let just_nanos = Duration::from_nanos(u64::from(elapsed.subsec_nanos())); let elapsed = elapsed - just_nanos; humantime::format_duration(elapsed).to_string()