Fix clippy warnings

This commit is contained in:
Lucien Greathouse
2019-10-17 18:22:53 -07:00
parent ec614e1912
commit 44c94da2d8
17 changed files with 42 additions and 33 deletions

View File

@@ -13,7 +13,7 @@ pub fn get_auth_cookie() -> Option<String> {
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() {

View File

@@ -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<F: VfsFetcher>(
// 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);

View File

@@ -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");

View File

@@ -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 ")?;

View File

@@ -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();

View File

@@ -31,7 +31,7 @@ impl<K: Hash + Eq, V: Eq> MultiMap<K, V> {
let bucket = self.inner.entry(k).or_default();
for value in &*bucket {
if &*value == &v {
if *value == v {
return;
}
}
@@ -49,7 +49,7 @@ impl<K: Hash + Eq, V: Eq> MultiMap<K, V> {
removed_value = Some(bucket.swap_remove(index));
}
if bucket.len() == 0 {
if bucket.is_empty() {
self.inner.remove(k.borrow());
}

View File

@@ -91,7 +91,7 @@ where
#[derive(Serialize)]
struct WithAbsolute<'a>(#[serde(serialize_with = "serialize_absolute")] &'a Path);
pub fn serialize_vec_absolute<S, T>(paths: &Vec<T>, serializer: S) -> Result<S::Ok, S::Error>
pub fn serialize_vec_absolute<S, T>(paths: &[T], serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
T: AsRef<Path>,

View File

@@ -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

View File

@@ -78,14 +78,14 @@ impl<F: VfsFetcher + Send + Sync + 'static> ServeSession<F> {
/// 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<P: AsRef<Path>>(mut vfs: Vfs<F>, start_path: P) -> Self {
pub fn new<P: AsRef<Path>>(vfs: Vfs<F>, 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();

View File

@@ -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};

View File

@@ -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()

View File

@@ -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))

View File

@@ -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::*;

View File

@@ -220,6 +220,6 @@ impl VfsFetcher for RealFetcher {
fn watched_paths(&self) -> Vec<PathBuf> {
let watched_paths = self.watched_paths.lock().unwrap();
watched_paths.iter().map(|v| v.clone()).collect()
watched_paths.iter().cloned().collect()
}
}

View File

@@ -39,12 +39,10 @@ impl<F: VfsFetcher> Service for ApiService<F> {
(&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,
),
}
}
}

View File

@@ -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(),

View File

@@ -336,7 +336,7 @@ impl<F: VfsFetcher> UiService<F> {
// 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()