clippy: unwrap_or/ok_or(function call) unwrap_or_else/ok_or_else

This commit is contained in:
Graham Christensen 2019-01-02 18:55:49 -05:00
parent 0ab2ce45cf
commit fc8494b45f
No known key found for this signature in database
GPG key ID: ACA1C1D120C83D5C
9 changed files with 17 additions and 19 deletions

View file

@ -196,13 +196,11 @@ impl SpawnedAsyncCmd {
pub fn wait(self) -> Result<ExitStatus, io::Error> {
self.waiter.join()
.map_err(|_err| io::Error::new(io::ErrorKind::Other, "Couldn't join thread."))
.and_then(|opt| opt.ok_or(io::Error::new(io::ErrorKind::Other, "Thread didn't return an exit status.")))
.and_then(|opt| opt.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "Thread didn't return an exit status.")))
.and_then(|res| res)
}
}
#[cfg(test)]
mod tests {
use super::AsyncCmd;

View file

@ -33,7 +33,7 @@ impl<'a> CommitStatus<'a> {
}
pub fn set_url(&mut self, url: Option<String>) {
self.url = url.unwrap_or(String::from(""))
self.url = url.unwrap_or_else(|| String::from(""))
}
pub fn set_with_description(&mut self, description: &str, state: hubcaps::statuses::State) {

View file

@ -158,7 +158,7 @@ impl RabbitMQConfig {
self.username,
self.password,
self.host,
self.virtualhost.clone().unwrap_or("/".to_owned()),
self.virtualhost.clone().unwrap_or_else(|| "/".to_owned()),
)
}
}

View file

@ -301,7 +301,7 @@ pub fn session_from_config(config: &RabbitMQConfig) -> Result<amqp::Session, amq
amqp::AMQPScheme::AMQPS => 5671,
amqp::AMQPScheme::AMQP => 5672,
},
vhost: config.virtualhost.clone().unwrap_or("/".to_owned()),
vhost: config.virtualhost.clone().unwrap_or_else(|| "/".to_owned()),
login: config.username.clone(),
password: config.password.clone(),
scheme,
@ -349,7 +349,7 @@ impl TypedWrappers for amqp::Channel {
config.no_ack,
config.exclusive,
config.no_wait,
config.arguments.unwrap_or(amqp::Table::new()),
config.arguments.unwrap_or_else(amqp::Table::new),
)
}
@ -365,7 +365,7 @@ impl TypedWrappers for amqp::Channel {
config.auto_delete,
config.internal,
config.no_wait,
config.arguments.unwrap_or(amqp::Table::new()),
config.arguments.unwrap_or_else(amqp::Table::new),
)
}
@ -381,7 +381,7 @@ impl TypedWrappers for amqp::Channel {
config.exclusive,
config.auto_delete,
config.no_wait,
config.arguments.unwrap_or(amqp::Table::new()),
config.arguments.unwrap_or_else(amqp::Table::new),
)
}
@ -392,9 +392,9 @@ impl TypedWrappers for amqp::Channel {
self.queue_bind(
config.queue,
config.exchange,
config.routing_key.unwrap_or("".to_owned()),
config.routing_key.unwrap_or_else(|| "".to_owned()),
config.no_wait,
config.arguments.unwrap_or(amqp::Table::new()),
config.arguments.unwrap_or_else(amqp::Table::new),
)
}
}

View file

@ -216,7 +216,7 @@ impl Nix {
let status = cmd.stdout(Stdio::from(stdout))
.stderr(Stdio::from(stderr))
.status()
.expect(format!("Running a program ...").as_ref());
.expect("Running a program ...");
reader.seek(SeekFrom::Start(0)).expect(
"Seeking to Start(0)",

View file

@ -72,8 +72,8 @@ impl<'a> NotificationReceiver for ChannelNotificationReceiver<'a> {
.unwrap();
}
Action::Publish(msg) => {
let exch = msg.exchange.clone().unwrap_or("".to_owned());
let key = msg.routing_key.clone().unwrap_or("".to_owned());
let exch = msg.exchange.clone().unwrap_or_else(|| "".to_owned());
let key = msg.routing_key.clone().unwrap_or_else(|| "".to_owned());
let props = msg.properties.unwrap_or(
BasicProperties { ..Default::default() },

View file

@ -80,7 +80,7 @@ fn result_to_check(result: &LegacyBuildResult, timestamp: DateTime<Utc>) -> Chec
result.skipped_attrs.clone()
]
.into_iter()
.map(|opt| opt.unwrap_or(vec![]))
.map(|opt| opt.unwrap_or_else(|| vec![]))
.flat_map(|list| list.into_iter().map(|attr| format!("-A {}", attr)))
.collect();
all_attrs.sort();

View file

@ -251,13 +251,13 @@ impl<E: stats::SysEvents + 'static> worker::SimpleWorker for MassRebuildWorker<E
}
let possibly_touched_packages =
parse_commit_messages(&co.commit_messages_from_head(&job.pr.head_sha).unwrap_or(
parse_commit_messages(&co.commit_messages_from_head(&job.pr.head_sha).unwrap_or_else(|_|
vec!["".to_owned()],
));
self.tag_from_paths(
&issue,
co.files_changed_from_head(&job.pr.head_sha).unwrap_or(vec![])
co.files_changed_from_head(&job.pr.head_sha).unwrap_or_else(|_| vec![])
);
overall_status.set_with_description("Merging PR", hubcaps::statuses::State::Pending);

View file

@ -105,8 +105,8 @@ impl<T: SimpleWorker + Send> Consumer for Worker<T> {
.unwrap();
}
Action::Publish(msg) => {
let exch = msg.exchange.clone().unwrap_or("".to_owned());
let key = msg.routing_key.clone().unwrap_or("".to_owned());
let exch = msg.exchange.clone().unwrap_or_else(|| "".to_owned());
let key = msg.routing_key.clone().unwrap_or_else(|| "".to_owned());
let props = msg.properties.unwrap_or(
BasicProperties { ..Default::default() },