Skip to content

Commit

Permalink
fix Rust clippy issues
Browse files Browse the repository at this point in the history
Summary:
It seems clippy issues became fatal with `#[deny(warnings)]` internally. Fix
them so pull requests that treat `#[deny(warnings)]` as rustc warnings, not
rustc+clippy warnings can have green signals.

If this continues to be an issue, we might want to disable `#[deny(warnings)]`.

Reviewed By: genevievehelsel

Differential Revision: D58690344

fbshipit-source-id: 14c2885f53e7d68161bb904a3febd047dcb37956
  • Loading branch information
quark-zju authored and facebook-github-bot committed Jun 17, 2024
1 parent f6ee029 commit 861531f
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 64 deletions.
2 changes: 1 addition & 1 deletion watchman/rust/serde_bser/src/bytestring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl TryInto<ByteString> for PathBuf {
type Error = &'static str;

fn try_into(self) -> Result<ByteString, Self::Error> {
Ok(self.into_os_string().try_into()?)
self.into_os_string().try_into()
}
}

Expand Down
2 changes: 1 addition & 1 deletion watchman/rust/serde_bser/src/de/bunser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ where
BSER_INT8 => self.next_i8()? as i64,
BSER_INT16 => self.next_i16()? as i64,
BSER_INT32 => self.next_i32()? as i64,
BSER_INT64 => self.next_i64()? as i64,
BSER_INT64 => self.next_i64()?,
ch => {
return Err(Error::DeInvalidStartByte {
kind: "integer".into(),
Expand Down
12 changes: 5 additions & 7 deletions watchman/rust/serde_bser/src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ where
match self
.bunser
.read_bytes(len)?
.map_result(|x| str::from_utf8(x))
.map_result(str::from_utf8)
.map_err(Error::de_reader_error)?
{
Reference::Borrowed(s) => visitor.visit_borrowed_str(s),
Expand Down Expand Up @@ -277,12 +277,10 @@ where
}
visitor.visit_enum(variant::VariantAccess::new(self, &guard))
}
ch => {
return Err(Error::DeInvalidStartByte {
kind: format!("enum '{}'", name),
byte: ch,
});
}
ch => Err(Error::DeInvalidStartByte {
kind: format!("enum '{}'", name),
byte: ch,
}),
}
}

Expand Down
36 changes: 18 additions & 18 deletions watchman/rust/watchman_client/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,32 +85,32 @@ pub enum Expr {
FileType(FileType),
}

impl Into<Value> for Expr {
fn into(self) -> Value {
match self {
Self::True => "true".into(),
Self::False => "false".into(),
Self::Not(expr) => Value::Array(vec!["not".into(), (*expr).into()]),
Self::All(expr) => {
impl From<Expr> for Value {
fn from(val: Expr) -> Self {
match val {
Expr::True => "true".into(),
Expr::False => "false".into(),
Expr::Not(expr) => Value::Array(vec!["not".into(), (*expr).into()]),
Expr::All(expr) => {
let mut expr: Vec<Value> = expr.into_iter().map(Into::into).collect();
expr.insert(0, "allof".into());
Value::Array(expr)
}
Self::Any(expr) => {
Expr::Any(expr) => {
let mut expr: Vec<Value> = expr.into_iter().map(Into::into).collect();
expr.insert(0, "anyof".into());
Value::Array(expr)
}
Self::DirName(term) => {
Expr::DirName(term) => {
let mut expr: Vec<Value> = vec!["dirname".into(), term.path.try_into().unwrap()];
if let Some(depth) = term.depth {
expr.push(depth.into_term("depth"));
}
expr.into()
}
Self::Empty => "empty".into(),
Self::Exists => "exists".into(),
Self::Match(term) => vec![
Expr::Empty => "empty".into(),
Expr::Exists => "exists".into(),
Expr::Match(term) => vec![
"match".into(),
term.glob.into(),
if term.wholename {
Expand All @@ -125,7 +125,7 @@ impl Into<Value> for Expr {
}),
]
.into(),
Self::Name(term) => vec![
Expr::Name(term) => vec![
"name".into(),
Value::Array(
term.paths
Expand All @@ -141,7 +141,7 @@ impl Into<Value> for Expr {
.into(),
]
.into(),
Self::Pcre(term) => vec![
Expr::Pcre(term) => vec![
"pcre".into(),
term.pattern.into(),
if term.wholename {
Expand All @@ -152,7 +152,7 @@ impl Into<Value> for Expr {
.into(),
]
.into(),
Self::Since(term) => match term {
Expr::Since(term) => match term {
SinceTerm::ObservedClock(c) => {
vec!["since".into(), c.into(), "oclock".into()].into()
}
Expand All @@ -166,13 +166,13 @@ impl Into<Value> for Expr {
vec!["since".into(), c.to_string().into(), "ctime".into()].into()
}
},
Self::Size(term) => term.into_term("size"),
Self::Suffix(term) => vec![
Expr::Size(term) => term.into_term("size"),
Expr::Suffix(term) => vec![
"suffix".into(),
Value::Array(term.into_iter().map(|p| p.try_into().unwrap()).collect()),
]
.into(),
Self::FileType(term) => vec!["type".into(), term.to_string().into()].into(),
Expr::FileType(term) => vec!["type".into(), term.to_string().into()].into(),
}
}
}
Expand Down
13 changes: 5 additions & 8 deletions watchman/rust/watchman_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,10 @@ impl Connector {
let watchman_path = self
.watchman_cli_path
.as_ref()
.map(|p| p.as_ref())
.unwrap_or_else(|| Path::new("watchman"));
.map_or_else(|| Path::new("watchman"), |p| p.as_ref());

let mut cmd = Command::new(watchman_path);
cmd.args(&["--output-encoding", "bser-v2", "get-sockname"]);
cmd.args(["--output-encoding", "bser-v2", "get-sockname"]);

#[cfg(windows)]
cmd.creation_flags(winapi::um::winbase::CREATE_NO_WINDOW);
Expand Down Expand Up @@ -630,7 +629,7 @@ fn bunser<T>(buf: &[u8]) -> Result<T, Error>
where
T: serde::de::DeserializeOwned,
{
let response: T = serde_bser::from_slice(&buf).map_err(|source| Error::Deserialize {
let response: T = serde_bser::from_slice(buf).map_err(|source| Error::Deserialize {
source: source.into(),
data: buf.to_vec(),
})?;
Expand Down Expand Up @@ -1191,7 +1190,7 @@ mod tests {

let reader = StreamReader::new(stream::iter(chunks));

let decoded = FramedRead::new(reader, BserSplitter)
FramedRead::new(reader, BserSplitter)
.map_err(TaskError::from)
.and_then(|bytes| async move {
// We unwrap this since a) this is a test and b) serde_bser's errors aren't
Expand All @@ -1201,9 +1200,7 @@ mod tests {
})
.try_collect()
.await
.unwrap();

decoded
.unwrap()
}

let msgs = vec![
Expand Down
59 changes: 30 additions & 29 deletions watchman/rust/watchman_client/src/pdu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//! This module defines the request and response PDU types used by the
//! watchman protocol.

use std::fmt;
use std::path::PathBuf;

use serde::Deserialize;
Expand Down Expand Up @@ -144,9 +145,9 @@ impl From<std::time::Duration> for SettleDurationMs {
}
}

impl Into<i64> for SettleDurationMs {
fn into(self) -> i64 {
self.0.as_millis() as i64
impl From<SettleDurationMs> for i64 {
fn from(val: SettleDurationMs) -> Self {
val.0.as_millis() as i64
}
}

Expand Down Expand Up @@ -203,9 +204,9 @@ impl From<std::time::Duration> for SyncTimeout {
}
}

impl Into<i64> for SyncTimeout {
fn into(self) -> i64 {
match self {
impl From<SyncTimeout> for i64 {
fn from(val: SyncTimeout) -> Self {
match val {
// This is only really here because the `ClockRequestParams` PDU
// treats a missing sync_timeout as `DisableCookie`, whereas
// the `QueryRequestCommon` PDU treats it as `Default`.
Expand All @@ -215,9 +216,9 @@ impl Into<i64> for SyncTimeout {
// default behavior, we use the current default sync timeout here.
// We're honestly not likely to change this, so this should be fine.
// The server uses 1 minute; the value here is expressed in milliseconds.
Self::Default => 60_000,
Self::DisableCookie => 0,
Self::Duration(d) => d.as_millis() as i64,
SyncTimeout::Default => 60_000,
SyncTimeout::DisableCookie => 0,
SyncTimeout::Duration(d) => d.as_millis() as i64,
}
}
}
Expand Down Expand Up @@ -657,11 +658,11 @@ impl ClockSpec {
}
}

impl Into<Value> for ClockSpec {
fn into(self) -> Value {
match self {
Self::StringClock(st) => Value::Utf8String(st),
Self::UnixTimestamp(ts) => Value::Integer(ts),
impl From<ClockSpec> for Value {
fn from(val: ClockSpec) -> Self {
match val {
ClockSpec::StringClock(st) => Value::Utf8String(st),
ClockSpec::UnixTimestamp(ts) => Value::Integer(ts),
}
}
}
Expand Down Expand Up @@ -755,9 +756,9 @@ pub enum FileType {
Unknown,
}

impl std::string::ToString for FileType {
fn to_string(&self) -> String {
(*self).into()
impl fmt::Display for FileType {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
f.write_str(&String::from(*self))
}
}

Expand All @@ -778,18 +779,18 @@ impl From<String> for FileType {
}
}

impl Into<String> for FileType {
fn into(self) -> String {
match self {
Self::BlockSpecial => "b",
Self::CharSpecial => "c",
Self::Directory => "d",
Self::Regular => "f",
Self::Fifo => "p",
Self::Symlink => "l",
Self::Socket => "s",
Self::SolarisDoor => "D",
Self::Unknown => "?",
impl From<FileType> for String {
fn from(val: FileType) -> Self {
match val {
FileType::BlockSpecial => "b",
FileType::CharSpecial => "c",
FileType::Directory => "d",
FileType::Regular => "f",
FileType::Fifo => "p",
FileType::Symlink => "l",
FileType::Socket => "s",
FileType::SolarisDoor => "D",
FileType::Unknown => "?",
}
.to_string()
}
Expand Down

0 comments on commit 861531f

Please sign in to comment.