Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clippy warnings in 1.54 #730

Merged
merged 4 commits into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 37 additions & 37 deletions crates/ilp-cli/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ use url::Url;
pub enum Error {
// Custom errors
#[error("Usage error")]
UsageErr(&'static str),
Usage(&'static str),
#[error("Invalid protocol in URL: {0}")]
ProtocolErr(String),
Protocol(String),
// Foreign errors
#[error("Error sending HTTP request: {0}")]
SendErr(#[from] reqwest::Error),
Send(#[from] reqwest::Error),
#[error("Error receving HTTP response from testnet: {0}")]
TestnetErr(reqwest::Error),
Testnet(reqwest::Error),
#[error("Error altering URL scheme")]
SchemeErr(()), // TODO: should be part of UrlError, see https://github.com/servo/rust-url/issues/299
Scheme(()), // TODO: should be part of Urlor, see https://github.com/servo/rust-url/issues/299
#[error("Error parsing URL: {0}")]
UrlErr(#[from] url::ParseError),
Url(#[from] url::ParseError),
#[error("WebSocket error: {0}")]
WebsocketErr(#[from] tungstenite::error::Error),
Websocket(#[from] tungstenite::error::Error),
#[error("HTTP error: {0}")]
HttpErr(#[from] http::Error),
Http(#[from] http::Error),
}

pub fn run(matches: &ArgMatches) -> Result<Response, Error> {
Expand All @@ -49,35 +49,35 @@ pub fn run(matches: &ArgMatches) -> Result<Response, Error> {
("list", Some(submatches)) => client.get_accounts(submatches),
("update", Some(submatches)) => client.put_account(submatches),
("update-settings", Some(submatches)) => client.put_account_settings(submatches),
_ => Err(Error::UsageErr("ilp-cli help accounts")),
_ => Err(Error::Usage("ilp-cli help accounts")),
},
("pay", Some(pay_matches)) => client.post_account_payments(pay_matches),
("rates", Some(rates_matches)) => match rates_matches.subcommand() {
("list", Some(submatches)) => client.get_rates(submatches),
("set-all", Some(submatches)) => client.put_rates(submatches),
_ => Err(Error::UsageErr("ilp-cli help rates")),
_ => Err(Error::Usage("ilp-cli help rates")),
},
("routes", Some(routes_matches)) => match routes_matches.subcommand() {
("list", Some(submatches)) => client.get_routes(submatches),
("set", Some(submatches)) => client.put_route_static(submatches),
("set-all", Some(submatches)) => client.put_routes_static(submatches),
_ => Err(Error::UsageErr("ilp-cli help routes")),
_ => Err(Error::Usage("ilp-cli help routes")),
},
("settlement-engines", Some(settlement_matches)) => match settlement_matches.subcommand() {
("set-all", Some(submatches)) => client.put_settlement_engines(submatches),
_ => Err(Error::UsageErr("ilp-cli help settlement-engines")),
_ => Err(Error::Usage("ilp-cli help settlement-engines")),
},
("status", Some(status_matches)) => client.get_root(status_matches),
("logs", Some(log_level)) => client.put_tracing_level(log_level),
("testnet", Some(testnet_matches)) => match testnet_matches.subcommand() {
("setup", Some(submatches)) => client.xpring_account(submatches),
_ => Err(Error::UsageErr("ilp-cli help testnet")),
_ => Err(Error::Usage("ilp-cli help testnet")),
},
("payments", Some(payments_matches)) => match payments_matches.subcommand() {
("incoming", Some(submatches)) => client.ws_payments_incoming(submatches),
_ => Err(Error::UsageErr("ilp-cli help payments")),
_ => Err(Error::Usage("ilp-cli help payments")),
},
_ => Err(Error::UsageErr("ilp-cli help")),
_ => Err(Error::Usage("ilp-cli help")),
}
}

Expand All @@ -95,7 +95,7 @@ impl NodeClient<'_> {
.get(&format!("{}/accounts/{}/balance", self.url, user))
.bearer_auth(auth)
.send()
.map_err(Error::SendErr)
.map_err(Error::Send)
}

// POST /accounts
Expand All @@ -106,7 +106,7 @@ impl NodeClient<'_> {
.bearer_auth(auth)
.json(&args)
.send()
.map_err(Error::SendErr)
.map_err(Error::Send)
}

// PUT /accounts/:username
Expand All @@ -117,7 +117,7 @@ impl NodeClient<'_> {
.bearer_auth(auth)
.json(&args)
.send()
.map_err(Error::SendErr)
.map_err(Error::Send)
}

// DELETE /accounts/:username
Expand All @@ -127,7 +127,7 @@ impl NodeClient<'_> {
.delete(&format!("{}/accounts/{}", self.url, args["username"]))
.bearer_auth(auth)
.send()
.map_err(Error::SendErr)
.map_err(Error::Send)
}

// WebSocket /accounts/:username/payments/incoming
Expand All @@ -141,13 +141,13 @@ impl NodeClient<'_> {
let scheme = match url.scheme() {
"http" => Ok("ws"),
"https" => Ok("wss"),
s => Err(Error::ProtocolErr(format!(
s => Err(Error::Protocol(format!(
"{} (only HTTP and HTTPS are supported)",
s
))),
}?;

url.set_scheme(scheme).map_err(Error::SchemeErr)?;
url.set_scheme(scheme).map_err(Error::Scheme)?;

let request: Request = Request::builder()
.uri(url.into_string())
Expand All @@ -169,13 +169,13 @@ impl NodeClient<'_> {
let scheme = match url.scheme() {
"http" => Ok("ws"),
"https" => Ok("wss"),
s => Err(Error::ProtocolErr(format!(
s => Err(Error::Protocol(format!(
"{} (only HTTP and HTTPS are supported)",
s
))),
}?;

url.set_scheme(scheme).map_err(Error::SchemeErr)?;
url.set_scheme(scheme).map_err(Error::Scheme)?;

let request: Request = Request::builder()
.uri(url.into_string())
Expand All @@ -196,7 +196,7 @@ impl NodeClient<'_> {
.get(&format!("{}/accounts/{}", self.url, args["username"]))
.bearer_auth(auth)
.send()
.map_err(Error::SendErr)
.map_err(Error::Send)
}

// GET /accounts
Expand All @@ -206,7 +206,7 @@ impl NodeClient<'_> {
.get(&format!("{}/accounts", self.url))
.bearer_auth(auth)
.send()
.map_err(Error::SendErr)
.map_err(Error::Send)
}

// PUT /accounts/:username/settings
Expand All @@ -218,7 +218,7 @@ impl NodeClient<'_> {
.bearer_auth(auth)
.json(&args)
.send()
.map_err(Error::SendErr)
.map_err(Error::Send)
}

// POST /accounts/:username/payments
Expand All @@ -230,15 +230,15 @@ impl NodeClient<'_> {
.bearer_auth(auth)
.json(&args)
.send()
.map_err(Error::SendErr)
.map_err(Error::Send)
}

// GET /rates
fn get_rates(&self, _matches: &ArgMatches) -> Result<Response, Error> {
self.client
.get(&format!("{}/rates", self.url))
.send()
.map_err(Error::SendErr)
.map_err(Error::Send)
}

// PUT /rates
Expand All @@ -249,15 +249,15 @@ impl NodeClient<'_> {
.bearer_auth(auth)
.json(&rate_pairs)
.send()
.map_err(Error::SendErr)
.map_err(Error::Send)
}

// GET /routes
fn get_routes(&self, _matches: &ArgMatches) -> Result<Response, Error> {
self.client
.get(&format!("{}/routes", self.url))
.send()
.map_err(Error::SendErr)
.map_err(Error::Send)
}

// PUT /routes/static/:prefix
Expand All @@ -268,7 +268,7 @@ impl NodeClient<'_> {
.bearer_auth(auth)
.body(args["destination"].to_string())
.send()
.map_err(Error::SendErr)
.map_err(Error::Send)
}

// PUT routes/static
Expand All @@ -279,7 +279,7 @@ impl NodeClient<'_> {
.bearer_auth(auth)
.json(&route_pairs)
.send()
.map_err(Error::SendErr)
.map_err(Error::Send)
}

// PUT /settlement/engines
Expand All @@ -290,7 +290,7 @@ impl NodeClient<'_> {
.bearer_auth(auth)
.json(&engine_pairs)
.send()
.map_err(Error::SendErr)
.map_err(Error::Send)
}

// PUT /tracing-level
Expand All @@ -301,15 +301,15 @@ impl NodeClient<'_> {
.bearer_auth(auth)
.body(args["level"].to_owned())
.send()
.map_err(Error::SendErr)
.map_err(Error::Send)
}

// GET /
fn get_root(&self, _matches: &ArgMatches) -> Result<Response, Error> {
self.client
.get(&format!("{}/", self.url))
.send()
.map_err(Error::SendErr)
.map_err(Error::Send)
}

/*
Expand All @@ -332,7 +332,7 @@ impl NodeClient<'_> {
.get(&format!("https://xpring.io/api/accounts/{}", asset))
.send()?
.json()
.map_err(Error::TestnetErr)?;
.map_err(Error::Testnet)?;
let mut args = HashMap::new();
let token = format!("{}:{}", foreign_args.username, foreign_args.passkey);
args.insert("ilp_over_http_url", foreign_args.http_endpoint);
Expand Down Expand Up @@ -360,7 +360,7 @@ impl NodeClient<'_> {
http::Response::builder().body(token).unwrap(), // infallible unwrap
))
} else {
result.map_err(Error::SendErr)
result.map_err(Error::Send)
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/ilp-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn main() {

// 4. Handle interpreter output
match result {
Err(interpreter::Error::UsageErr(s)) => {
Err(interpreter::Error::Usage(s)) => {
// Clap doesn't seem to have a built-in way of manually printing the
// help text for an arbitrary subcommand, but this works just the same.
app.get_matches_from(s.split(' '));
Expand Down Expand Up @@ -217,9 +217,9 @@ mod interface_tests {
Ok(matches) => match run(&matches) {
// Because these are interface tests, not integration tests, network errors are expected
Ok(_)
| Err(Error::SendErr(_))
| Err(Error::WebsocketErr(_))
| Err(Error::TestnetErr(_)) => (),
| Err(Error::Send(_))
| Err(Error::Websocket(_))
| Err(Error::Testnet(_)) => (),
Err(e) => panic!("Unexpected interpreter failure: {}", e),
},
}
Expand Down
2 changes: 1 addition & 1 deletion crates/ilp-node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ fn set_app_env(env_config: &Config, app: &mut App<'_, '_>, path: &[String], dept
if depth == 1 {
for item in &mut app.p.opts {
if let Ok(value) = env_config.get_str(&item.b.name.to_lowercase()) {
item.v.env = Some((&OsStr::new(item.b.name), Some(OsString::from(value))));
item.v.env = Some((OsStr::new(item.b.name), Some(OsString::from(value))));
}
}
return;
Expand Down
2 changes: 1 addition & 1 deletion crates/ilp-node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ impl InterledgerNode {
}
Err(RejectBuilder {
code: ErrorCode::F02_UNREACHABLE,
message: &format!(
message: format!(
// TODO we might not want to expose the internal account ID in the error
"No outgoing route for account: {} (ILP address of the Prepare packet: {})",
request.to.id(),
Expand Down
2 changes: 1 addition & 1 deletion crates/interledger-api/src/routes/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ where
let server_secret_clone = server_secret.clone();
async move {
if let Some(ref username) = default_spsp_account {
let id = store.get_account_id_from_username(&username).await?;
let id = store.get_account_id_from_username(username).await?;

// TODO this shouldn't take multiple store calls
let mut accounts = store.get_accounts(vec![id]).await?;
Expand Down
2 changes: 1 addition & 1 deletion crates/interledger-api/src/routes/node_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ where
// Convert the usernames to account IDs to set the routes in the store
let mut usernames: Vec<Username> = Vec::new();
for username in routes.values() {
let user = match Username::from_str(&username) {
let user = match Username::from_str(username) {
Ok(u) => u,
Err(_) => return Err(Rejection::from(ApiError::bad_request())),
};
Expand Down
6 changes: 3 additions & 3 deletions crates/interledger-btp/src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ mod tests {
#[test]
fn from_bytes() {
assert_eq!(
BtpMessage::from_bytes(&MESSAGE_1_SERIALIZED).unwrap(),
BtpMessage::from_bytes(MESSAGE_1_SERIALIZED).unwrap(),
*MESSAGE_1
);
}
Expand Down Expand Up @@ -597,7 +597,7 @@ mod tests {
#[test]
fn from_bytes() {
assert_eq!(
BtpResponse::from_bytes(&RESPONSE_1_SERIALIZED).unwrap(),
BtpResponse::from_bytes(RESPONSE_1_SERIALIZED).unwrap(),
*RESPONSE_1
);
}
Expand Down Expand Up @@ -625,7 +625,7 @@ mod tests {

#[test]
fn from_bytes() {
assert_eq!(BtpError::from_bytes(&ERROR_1_SERIALIZED).unwrap(), *ERROR_1);
assert_eq!(BtpError::from_bytes(ERROR_1_SERIALIZED).unwrap(), *ERROR_1);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion crates/interledger-btp/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ where
let (auth, mut connection) = get_auth(Box::pin(connection)).await?;
debug!("Got BTP connection for username: {}", username);
let account = store
.get_account_from_btp_auth(&username, &auth.token.expose_secret())
.get_account_from_btp_auth(&username, auth.token.expose_secret())
.map_err(move |_| warn!("BTP connection does not correspond to an account"))
.await?;

Expand Down
2 changes: 1 addition & 1 deletion crates/interledger-ccp/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ where
warn!("Error handling incoming Route Update request, sending a Route Control request to get updated routing table info from peer. Error was: {}", &message);
let reject = RejectBuilder {
code: ErrorCode::F00_BAD_REQUEST,
message: &message.as_bytes(),
message: message.as_bytes(),
data: &[],
triggered_by: Some(&self.ilp_address.read()),
}
Expand Down
2 changes: 1 addition & 1 deletion crates/interledger-http/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ where
}
Ok(store
.get_account_from_http_auth(
&path_username,
path_username,
&password.expose_secret()[BEARER_TOKEN_START..],
)
.await?)
Expand Down
2 changes: 1 addition & 1 deletion crates/interledger-ildcp/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ where
if is_ildcp_request(&request.prepare) {
let from = request.from.ilp_address();
let builder = IldcpResponseBuilder {
ilp_address: &from,
ilp_address: from,
asset_code: request.from.asset_code(),
asset_scale: request.from.asset_scale(),
};
Expand Down
2 changes: 1 addition & 1 deletion crates/interledger-packet/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl Address {
unsafe {
self.0
.split(|&b| b == b'.')
.map(|s| str::from_utf8_unchecked(&s))
.map(|s| str::from_utf8_unchecked(s))
}
}

Expand Down
Loading