Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

Commit

Permalink
Fix more clippy issues
Browse files Browse the repository at this point in the history
Run `cargo +nightly clippy -Z unstable-options --fix` on crates which
are not in the main workspace.

Signed-off-by: Joe Grund <[email protected]>
  • Loading branch information
jgrund committed Dec 11, 2020
1 parent 671b0be commit 6adc27e
Show file tree
Hide file tree
Showing 25 changed files with 71 additions and 85 deletions.
22 changes: 15 additions & 7 deletions device-scanner/device-scanner-daemon/src/reducers/zed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@ pub fn into_zed_events(xs: Vec<libzfs_types::Pool>) -> state::ZedEvents {
}

pub fn remove_pool(zed_events: &mut state::ZedEvents, guid: u64) -> Result<libzfs_types::Pool> {
zed_events.remove(&guid).ok_or_else(|| {
Error::LibZfsError(libzfs_types::LibZfsError::PoolNotFound(None, Some(guid)))
})
zed_events
.remove(&guid)
.ok_or(Error::LibZfsError(libzfs_types::LibZfsError::PoolNotFound(
None,
Some(guid),
)))
}

pub fn get_pool(zed_events: &mut state::ZedEvents, guid: u64) -> Result<&mut libzfs_types::Pool> {
zed_events.get_mut(&guid).ok_or_else(|| {
Error::LibZfsError(libzfs_types::LibZfsError::PoolNotFound(None, Some(guid)))
})
zed_events
.get_mut(&guid)
.ok_or(Error::LibZfsError(libzfs_types::LibZfsError::PoolNotFound(
None,
Some(guid),
)))
}

fn update_prop(name: &str, value: &str, xs: &mut Vec<libzfs_types::ZProp>) {
Expand Down Expand Up @@ -96,7 +102,9 @@ pub fn update_zed_events(
pool.datasets
.iter_mut()
.find(|d| d.name == name)
.ok_or_else(|| Error::LibZfsError(libzfs_types::LibZfsError::ZfsNotFound(name)))
.ok_or(Error::LibZfsError(libzfs_types::LibZfsError::ZfsNotFound(
name,
)))
}

let mut pool = get_pool(&mut zed_events, guid)?;
Expand Down
2 changes: 1 addition & 1 deletion device-scanner/mount-emitter/src/bin/swap_emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async fn main() -> Result<(), mount_emitter::Error> {
for x in xs {
let x = x.trim();

if x == "" {
if x.is_empty() {
continue;
}

Expand Down
33 changes: 7 additions & 26 deletions device-scanner/mount-emitter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,10 @@ pub fn line_to_command(x: &[u8]) -> Result<MountCommand, Error> {
let mut x: IntermediateMap = line_to_hashmap(&x)?;

let (target, source, fstype, mount_opts, old_opts, old_target) = (
MountPoint(
x.remove("TARGET")
.ok_or_else(|| Error::Missing("TARGET"))?
.into(),
),
DevicePath(
x.remove("SOURCE")
.ok_or_else(|| Error::Missing("SOURCE"))?
.into(),
),
FsType(x.remove("FSTYPE").ok_or_else(|| Error::Missing("FSTYPE"))?),
MountOpts(
x.remove("OPTIONS")
.ok_or_else(|| Error::Missing("OPTIONS"))?,
),
MountPoint(x.remove("TARGET").ok_or(Error::Missing("TARGET"))?.into()),
DevicePath(x.remove("SOURCE").ok_or(Error::Missing("SOURCE"))?.into()),
FsType(x.remove("FSTYPE").ok_or(Error::Missing("FSTYPE"))?),
MountOpts(x.remove("OPTIONS").ok_or(Error::Missing("OPTIONS"))?),
x.get("OLD-OPTIONS"),
x.get("OLD-TARGET"),
);
Expand All @@ -64,22 +53,14 @@ pub fn line_to_command(x: &[u8]) -> Result<MountCommand, Error> {
source,
fstype,
mount_opts,
MountOpts(
old_opts
.ok_or_else(|| Error::Missing("OLD-OPTIONS"))?
.to_string(),
),
MountOpts(old_opts.ok_or(Error::Missing("OLD-OPTIONS"))?.to_string()),
),
Some("move") => MountCommand::MoveMount(
target,
source,
fstype,
mount_opts,
MountPoint(
old_target
.ok_or_else(|| Error::Missing("OLD-TARGET"))?
.into(),
),
MountPoint(old_target.ok_or(Error::Missing("OLD-TARGET"))?.into()),
),
Some(x) => return Err(Error::Unexpected(x.to_string())),
};
Expand Down Expand Up @@ -163,7 +144,7 @@ where

tracing::debug!("Read line: {}", String::from_utf8_lossy(&line));

if str::from_utf8(&line)? == "" {
if str::from_utf8(&line)?.is_empty() {
break;
}

Expand Down
6 changes: 3 additions & 3 deletions iml-gui/crate/src/components/breadcrumbs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ pub trait BreadCrumb {
}

impl<Crumb: PartialEq> BreadCrumbs<Crumb> {
pub fn iter(self: &Self) -> impl DoubleEndedIterator<Item = &Crumb> {
pub fn iter(&self) -> impl DoubleEndedIterator<Item = &Crumb> {
self.crumbs.iter()
}

pub fn clear(self: &mut Self) -> &mut Self {
pub fn clear(&mut self) -> &mut Self {
self.crumbs.clear();
self
}

pub fn push(self: &mut Self, n: Crumb) -> &mut Self {
pub fn push(&mut self, n: Crumb) -> &mut Self {
let mut new_crumbs = LinkedList::new();

while let Some(c) = self.crumbs.pop_front() {
Expand Down
26 changes: 13 additions & 13 deletions iml-gui/crate/src/components/command_modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ fn extract_children_from_cmd(cmd: &Arc<Command>) -> (i32, Vec<i32>) {
.iter()
.filter_map(|s| extract_uri_id::<Job0>(s))
.collect::<Vec<i32>>();
deps.sort();
deps.sort_unstable();
(cmd.id, deps)
}

Expand All @@ -693,7 +693,7 @@ fn extract_children_from_job(job: &Arc<Job0>) -> (i32, Vec<i32>) {
.iter()
.filter_map(|s| extract_uri_id::<Step>(s))
.collect::<Vec<i32>>();
deps.sort();
deps.sort_unstable();
(job.id, deps)
}

Expand Down Expand Up @@ -725,7 +725,7 @@ fn extract_wait_fors_from_job(job: &Job0, jobs: &HashMap<i32, Arc<RichJob>>) ->

fn extract_sorted_keys<T>(hm: &HashMap<i32, T>) -> Vec<i32> {
let mut ids = hm.keys().copied().collect::<Vec<_>>();
ids.sort();
ids.sort_unstable();
ids
}

Expand Down Expand Up @@ -924,14 +924,14 @@ mod tests {
#[test]
fn test_is_subset() {
let all = vec![1, 2, 3, 4, 5];
assert_eq!(is_subset(&vec![1, 2, 3], &all), true);
assert_eq!(is_subset(&vec![1, 3, 5], &all), true);
assert_eq!(is_subset(&vec![], &all), true);
assert_eq!(is_subset(&[1, 2, 3], &all), true);
assert_eq!(is_subset(&[1, 3, 5], &all), true);
assert_eq!(is_subset(&[], &all), true);
assert_eq!(is_subset(&all, &all), true);

assert_eq!(is_subset(&vec![1, 6], &all), false);
assert_eq!(is_subset(&[1, 6], &all), false);
// if not sorted, the correctness is not guaranteed
assert_eq!(is_subset(&vec![5, 1], &all), false);
assert_eq!(is_subset(&[5, 1], &all), false);
}

#[test]
Expand Down Expand Up @@ -1216,7 +1216,7 @@ mod tests {
}
}
let mut sam = hs.into_iter().collect::<Vec<_>>();
sam.sort();
sam.sort_unstable();
sam
}
(0..n)
Expand All @@ -1230,9 +1230,9 @@ mod tests {
let sel_step_ids = sample(rng, &step_ids, ns);
let result = sel_cmd_ids
.into_iter()
.map(|id| TypedId::Cmd(id))
.chain(sel_job_ids.into_iter().map(|id| TypedId::Job(id)))
.chain(sel_step_ids.into_iter().map(|id| TypedId::Step(id)))
.map(TypedId::Cmd)
.chain(sel_job_ids.into_iter().map(TypedId::Job))
.chain(sel_step_ids.into_iter().map(TypedId::Step))
.collect::<HashSet<_>>();
Select(result)
})
Expand Down Expand Up @@ -1274,7 +1274,7 @@ mod tests {
result
}

const WELL_ORDERED_TREE: &'static str = r#"253: Stop file system fs
const WELL_ORDERED_TREE: &str = r#"253: Stop file system fs
244: Make file system fs unavailable
243: Stop target fs-OST0000
242: Stop target fs-OST0003
Expand Down
2 changes: 1 addition & 1 deletion iml-gui/crate/src/components/duration_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub fn update(msg: Msg, model: &mut Model) {
let value = input_el.value_as_number();

model.value = if value.is_nan() { None } else { Some(value as u64) };
model.validation_message = input_el.validation_message().ok().filter(|x| x != "");
model.validation_message = input_el.validation_message().ok().filter(|x| !x.is_empty());
}
Msg::Dropdown(msg) => {
dropdown::update(msg, &mut model.dropdown);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg, GMsg>)

let req = fetch::Request::graphql_query(&query);

orders.perform_cmd(req.fetch_json_data(|x| Msg::Scanned(x)));
orders.perform_cmd(req.fetch_json_data(Msg::Scanned));
}
Msg::Scanned(x) => {
match x {
Expand Down
8 changes: 4 additions & 4 deletions iml-gui/crate/src/dependency_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ mod tests {
fn test_rich_wrapper() {
fn extract_from_y(y: &Y) -> (u32, Vec<u32>) {
let mut deps = y.deps.iter().map(|s| s.parse::<u32>().unwrap()).collect::<Vec<u32>>();
deps.sort();
deps.sort_unstable();
(y.id, deps)
}
// the DAG built over RichDeps<_, _> must be always the same, no matter how dependencies are sorted
Expand Down Expand Up @@ -417,15 +417,15 @@ mod tests {
}
}

const SMALL_TREE: &'static str = r#"48: Setup managed host oss2.local
const SMALL_TREE: &str = r#"48: Setup managed host oss2.local
39: Install packages on server oss2.local
40: Configure NTP on oss2.local
39: Install packages on server oss2.local...
46: Configure Pacemaker on oss2.local
46: Configure Pacemaker on oss2.local...
"#;

const TREE_DIRECT: &'static str = r#"48: Setup managed host oss2.local.
const TREE_DIRECT: &str = r#"48: Setup managed host oss2.local.
39: Install packages on server oss2.local.
40: Configure NTP on oss2.local.
41: Enable LNet on oss2.local.
Expand All @@ -437,7 +437,7 @@ mod tests {
47: Start Pacemaker on oss2.local.
"#;

const TREE_INVERSE: &'static str = r#"39: Install packages on server oss2.local.
const TREE_INVERSE: &str = r#"39: Install packages on server oss2.local.
40: Configure NTP on oss2.local.
48: Setup managed host oss2.local.
41: Enable LNet on oss2.local.
Expand Down
2 changes: 1 addition & 1 deletion iml-gui/crate/src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub(crate) trait RequestExt: Sized {
fn api_query(path: impl ToString, args: impl serde::Serialize) -> Result<Self, serde_urlencoded::ser::Error>;
fn api_item(path: impl ToString, item: impl ToString) -> Self;
fn graphql_query<T: serde::Serialize>(x: &T) -> Self;
fn with_auth(self: Self) -> Self;
fn with_auth(self) -> Self;
}

impl RequestExt for fetch::Request {
Expand Down
4 changes: 2 additions & 2 deletions iml-gui/crate/src/page/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub fn update(msg: Msg, cache: &ArcCache, model: &mut Model, orders: &mut impl O
let query = client_mount::list_mount_command::build(model.fs.name.to_string());
let req = seed::fetch::Request::graphql_query(&query);

orders.perform_cmd(req.fetch_json_data(|x| Msg::MountCommandFetched(x)));
orders.perform_cmd(req.fetch_json_data(Msg::MountCommandFetched));
}
Msg::MountCommandFetched(x) => {
match x {
Expand Down Expand Up @@ -538,7 +538,7 @@ pub(crate) fn standby_hosts_view<T>(cache: &ArcCache, target: &TargetRecord) ->

standby_hosts.sort_by(|a, b| natord::compare(&a.fqdn, &b.fqdn));

if standby_hosts.len() > 0 {
if !standby_hosts.is_empty() {
ul![standby_hosts
.iter()
.map(|x| li![resource_links::server_link(Some(&x.resource_uri), &x.fqdn)])]
Expand Down
2 changes: 1 addition & 1 deletion iml-gui/crate/src/page/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub fn view(model: &Model, branding: Branding, exa_version: &Option<String>) ->

let errs = Errors::default();

let errs = model.errors.as_ref().unwrap_or_else(|| &errs);
let errs = model.errors.as_ref().unwrap_or(&errs);
let (border_color, text_color, logo) = match branding {
Branding::Whamcloud => (
C.border_teal_500,
Expand Down
7 changes: 2 additions & 5 deletions iml-gui/crate/src/page/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg, GMsg>)
let query = builder.build();
let req = fetch::Request::graphql_query(&query);

orders.perform_cmd(req.fetch_json_data(|x| Msg::LogsFetched(x)));
orders.perform_cmd(req.fetch_json_data(Msg::LogsFetched));
}
Msg::LogsFetched(r) => {
match r {
Expand Down Expand Up @@ -192,10 +192,7 @@ fn log_item_view(log: &LogMessage, cache: &ArcCache) -> Node<Msg> {
label_view("Time: "),
&log.datetime.format("%H:%M:%S %Y/%m/%d").to_string()
],
div![
class![C.grid, C.justify_end],
log_severity(LogSeverity::from(log.severity))
],
div![class![C.grid, C.justify_end], log_severity(log.severity)],
div![class![C.col_span_4], log.message],
div![
class![C.col_span_2],
Expand Down
2 changes: 1 addition & 1 deletion iml-gui/crate/src/page/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub(crate) enum Page {
}

impl Page {
pub(crate) fn title(self: &Self) -> String {
pub(crate) fn title(&self) -> String {
match self {
Self::About => "About".into(),
Self::AppLoading => "Loading...".into(),
Expand Down
2 changes: 1 addition & 1 deletion iml-gui/crate/src/page/snapshot/add_interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg, GMsg>)

let req = fetch::Request::graphql_query(&query);

orders.perform_cmd(req.fetch_json_data(|x| Msg::SnapshotCreateIntervalResp(x)));
orders.perform_cmd(req.fetch_json_data(Msg::SnapshotCreateIntervalResp));
}
Msg::SnapshotCreateIntervalResp(x) => {
model.submitting = false;
Expand Down
2 changes: 1 addition & 1 deletion iml-gui/crate/src/page/snapshot/create_retention.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg, GMsg>)

let req = fetch::Request::graphql_query(&query);

orders.perform_cmd(req.fetch_json_data(|x| Msg::SnapshotCreateRetentionResp(x)));
orders.perform_cmd(req.fetch_json_data(Msg::SnapshotCreateRetentionResp));
}
Msg::SnapshotCreateRetentionResp(x) => {
model.submitting = false;
Expand Down
2 changes: 1 addition & 1 deletion iml-gui/crate/src/page/snapshot/list_interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg, GMsg>)

let req = fetch::Request::graphql_query(&query);

orders.perform_cmd(req.fetch_json_data(|x| Msg::SnapshotDeleteIntervalResp(x)));
orders.perform_cmd(req.fetch_json_data(Msg::SnapshotDeleteIntervalResp));
}
}
Msg::SnapshotDeleteIntervalResp(x) => match x {
Expand Down
2 changes: 1 addition & 1 deletion iml-gui/crate/src/page/snapshot/list_retention.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg, GMsg>)

let req = fetch::Request::graphql_query(&query);

orders.perform_cmd(req.fetch_json_data(|x| Msg::DeleteRetentionResp(x)));
orders.perform_cmd(req.fetch_json_data(Msg::DeleteRetentionResp));
}
}
Msg::DeleteRetentionResp(x) => match x {
Expand Down
4 changes: 2 additions & 2 deletions iml-gui/crate/src/page/snapshot/take.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg, GMsg>)

let req = fetch::Request::graphql_query(&query);

orders.perform_cmd(req.fetch_json_data(|x| Msg::SnapshotCreateResp(x)));
orders.perform_cmd(req.fetch_json_data(Msg::SnapshotCreateResp));
}
Msg::SnapshotCreateResp(x) => match x {
Ok(Response::Data(x)) => {
Expand Down Expand Up @@ -104,7 +104,7 @@ pub fn init(cache: &ArcCache, model: &mut Model) {
let fs_name = get_fs_names(cache).into_iter().next();

if let Some(fs_name) = fs_name {
model.fs_name = fs_name.to_string();
model.fs_name = fs_name;
}
}

Expand Down
2 changes: 1 addition & 1 deletion iml-gui/crate/src/test_utils/fixtures.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use iml_wire_types::warp_drive::Cache;

pub(crate) fn get_cache() -> Cache {
static DATA: &'static [u8] = include_bytes!("./fixture.json");
static DATA: &[u8] = include_bytes!("./fixture.json");

serde_json::from_slice(&DATA).unwrap()
}
4 changes: 2 additions & 2 deletions iml-system-docker-tests/tests/ldiskfs_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ async fn test_docker_ldiskfs_setup() -> Result<(), TestError> {
let config: Config = Config::default();
let config: Config = Config {
profile_map: vec![
("base_monitored".into(), config.storage_servers()),
("base_client".into(), config.client_servers()),
("base_monitored", config.storage_servers()),
("base_client", config.client_servers()),
],
test_type: TestType::Docker,
..config
Expand Down
Loading

0 comments on commit 6adc27e

Please sign in to comment.