Skip to content

Commit

Permalink
Update to rust 1.26, and explicitly use Itertools::flatten to avoid r…
Browse files Browse the repository at this point in the history
…ust-lang/rust#48919. Additionally, apply rustfmt changes.
  • Loading branch information
stuhood committed May 20, 2018
1 parent bbbd37a commit 5fc27e2
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 71 deletions.
2 changes: 1 addition & 1 deletion build-support/bin/native/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ esac
readonly CACHE_ROOT=${XDG_CACHE_HOME:-$HOME/.cache}/pants
readonly NATIVE_ENGINE_CACHE_DIR=${CACHE_ROOT}/bin/native-engine

readonly RUST_TOOLCHAIN="1.25.0"
readonly RUST_TOOLCHAIN="1.26.0"

function calculate_current_hash() {
# Cached and unstaged files, with ignored files excluded.
Expand Down
14 changes: 7 additions & 7 deletions src/rust/engine/boxfuture/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ where
///
#[macro_export]
macro_rules! try_future {
( $x:expr) => {
{
match $x {
Ok(value) => {value}
Err(error) => {return future::err(error).to_boxed();}
}
($x:expr) => {{
match $x {
Ok(value) => value,
Err(error) => {
return future::err(error).to_boxed();
}
}
};
}};
}
16 changes: 8 additions & 8 deletions src/rust/engine/fs/brfs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,13 +643,13 @@ mod test {
extern crate tempdir;
extern crate testutil;

use self::tempdir::TempDir;
use self::testutil::{file, data::{TestData, TestDirectory}};
use super::mount;
use fs;
use futures::future::Future;
use hashing;
use self::tempdir::TempDir;
use std::sync::Arc;
use super::mount;
use self::testutil::{file, data::{TestData, TestDirectory}};

#[test]
fn missing_digest() {
Expand Down Expand Up @@ -888,16 +888,16 @@ mod syscall_tests {
extern crate tempdir;
extern crate testutil;

use self::tempdir::TempDir;
use self::testutil::data::TestData;
use super::mount;
use super::test::digest_to_filepath;
use fs;
use futures::Future;
use libc;
use std::sync::Arc;
use super::mount;
use super::test::digest_to_filepath;
use self::tempdir::TempDir;
use self::testutil::data::TestData;
use std::ffi::CString;
use std::path::Path;
use std::sync::Arc;

#[test]
fn read_file_by_digest_exact_bytes() {
Expand Down
9 changes: 3 additions & 6 deletions src/rust/engine/fs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ extern crate tempdir;
#[cfg(test)]
extern crate testutil;

use std::cmp::min;
use std::collections::HashSet;
use std::io::{self, Read};
use std::os::unix::fs::PermissionsExt;
use std::path::{Component, Path, PathBuf};
use std::sync::Arc;
use std::{fmt, fs};
use std::io::{self, Read};
use std::cmp::min;

use bytes::Bytes;
use futures::future::{self, Future};
Expand Down Expand Up @@ -123,12 +123,9 @@ impl PathStat {

lazy_static! {
static ref PARENT_DIR: &'static str = "..";

static ref SINGLE_STAR_GLOB: Pattern = Pattern::new("*").unwrap();

static ref DOUBLE_STAR: &'static str = "**";
static ref DOUBLE_STAR_GLOB: Pattern = Pattern::new("**").unwrap();

static ref EMPTY_IGNORE: Arc<Gitignore> = Arc::new(Gitignore::empty());
}

Expand Down Expand Up @@ -852,9 +849,9 @@ mod posixfs_test {
extern crate tempdir;
extern crate testutil;

use self::testutil::make_file;
use super::{Dir, File, Link, PathStat, PathStatGetter, PosixFS, ResettablePool, Stat};
use futures::Future;
use self::testutil::make_file;
use std;
use std::path::{Path, PathBuf};
use std::sync::Arc;
Expand Down
2 changes: 1 addition & 1 deletion src/rust/engine/fs/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

use std::sync::RwLock;

use futures_cpupool::{self, CpuFuture, CpuPool};
use futures::future::IntoFuture;
use futures_cpupool::{self, CpuFuture, CpuPool};

///
/// A wrapper around a CpuPool, to add the ability to drop the pool before forking,
Expand Down
34 changes: 15 additions & 19 deletions src/rust/engine/fs/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ use futures::future::{self, join_all};
use hashing::{Digest, Fingerprint};
use indexmap::{self, IndexMap};
use itertools::Itertools;
use {File, PathStat, PosixFS, Store};
use protobuf;
use std::ffi::OsString;
use std::fmt;
use std::path::PathBuf;
use std::sync::Arc;
use {File, PathStat, PosixFS, Store};

pub const EMPTY_FINGERPRINT: Fingerprint = Fingerprint([
0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24,
Expand Down Expand Up @@ -152,11 +152,7 @@ impl Snapshot {
// `Directory` structure. Only `Dir+Dir` collisions are legal.
let path_stats = {
let mut uniq_paths: IndexMap<PathBuf, PathStat> = IndexMap::new();
for path_stat in snapshots
.iter()
.map(|s| s.path_stats.iter().cloned())
.flatten()
{
for path_stat in Itertools::flatten(snapshots.iter().map(|s| s.path_stats.iter().cloned())) {
match uniq_paths.entry(path_stat.path().to_owned()) {
indexmap::map::Entry::Occupied(e) => match (&path_stat, e.get()) {
(&PathStat::Dir { .. }, &PathStat::Dir { .. }) => (),
Expand Down Expand Up @@ -212,11 +208,11 @@ impl Snapshot {

// Merge FileNodes.
out_dir.set_files(protobuf::RepeatedField::from_vec(
directories
.iter_mut()
.map(|directory| directory.take_files().into_iter())
.flatten()
.collect(),
Itertools::flatten(
directories
.iter_mut()
.map(|directory| directory.take_files().into_iter()),
).collect(),
));
out_dir.mut_files().sort_by(|a, b| a.name.cmp(&b.name));
let unique_count = out_dir
Expand All @@ -242,11 +238,11 @@ impl Snapshot {

// Group and recurse for DirectoryNodes.
let sorted_child_directories = {
let mut merged_directories = directories
.iter_mut()
.map(|directory| directory.take_directories().into_iter())
.flatten()
.collect::<Vec<_>>();
let mut merged_directories = Itertools::flatten(
directories
.iter_mut()
.map(|directory| directory.take_directories().into_iter()),
).collect::<Vec<_>>();
merged_directories.sort_by(|a, b| a.name.cmp(&b.name));
merged_directories
};
Expand Down Expand Up @@ -356,15 +352,15 @@ mod tests {
extern crate tempdir;
extern crate testutil;

use self::testutil::data::TestDirectory;
use self::testutil::make_file;
use futures::future::Future;
use hashing::{Digest, Fingerprint};
use tempdir::TempDir;
use self::testutil::make_file;
use self::testutil::data::TestDirectory;

use super::OneOffStoreFileByDigest;
use super::super::{Dir, File, Path, PathGlobs, PathStat, PosixFS, ResettablePool, Snapshot,
Store, VFS};
use super::OneOffStoreFileByDigest;

use std;
use std::path::PathBuf;
Expand Down
14 changes: 7 additions & 7 deletions src/rust/engine/fs/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,9 @@ mod local {
use digest::{Digest as DigestTrait, FixedOutput};
use futures::future;
use hashing::{Digest, Fingerprint};
use lmdb::Error::{KeyExist, NotFound};
use lmdb::{self, Cursor, Database, DatabaseFlags, Environment, RwTransaction, Transaction,
WriteFlags, NO_OVERWRITE, NO_SYNC, NO_TLS};
use lmdb::Error::{KeyExist, NotFound};
use resettable::Resettable;
use sha2::Sha256;
use std::collections::{BinaryHeap, HashMap};
Expand All @@ -575,9 +575,9 @@ mod local {
use std::sync::Arc;
use std::time;

use pool::ResettablePool;
use super::MAX_LOCAL_STORE_SIZE_BYTES;
use super::super::EMPTY_FINGERPRINT;
use super::MAX_LOCAL_STORE_SIZE_BYTES;
use pool::ResettablePool;

#[derive(Clone)]
pub struct ByteStore {
Expand Down Expand Up @@ -994,11 +994,11 @@ mod local {

#[cfg(test)]
pub mod tests {
use super::super::super::safe_create_dir_all;
use super::{ByteStore, EntryType, ResettablePool};
use bytes::Bytes;
use futures::Future;
use hashing::{Digest, Fingerprint};
use super::{ByteStore, EntryType, ResettablePool};
use super::super::super::safe_create_dir_all;
use lmdb::{DatabaseFlags, Environment, Transaction, WriteFlags};
use std::path::Path;
use std::sync::Arc;
Expand Down Expand Up @@ -1522,8 +1522,8 @@ mod remote {
use bytes::{Bytes, BytesMut};
use digest::{Digest as DigestTrait, FixedOutput};
use futures::{self, future, Future, Sink, Stream};
use hashing::{Digest, Fingerprint};
use grpcio;
use hashing::{Digest, Fingerprint};
use resettable::Resettable;
use sha2::Sha256;
use std::cmp::min;
Expand Down Expand Up @@ -1739,8 +1739,8 @@ mod remote {

extern crate tempdir;

use super::ByteStore;
use super::super::EntryType;
use super::ByteStore;
use bytes::Bytes;
use futures::Future;
use hashing::Digest;
Expand Down
16 changes: 9 additions & 7 deletions src/rust/engine/process_execution/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ impl super::CommandRunner for CommandRunner {
///
fn run(&self, req: ExecuteProcessRequest) -> BoxFuture<ExecuteProcessResult, String> {
let workdir = try_future!(
tempdir::TempDir::new("process-execution").map_err(|err| format!(
"Error making tempdir for local process execution: {:?}",
err
))
tempdir::TempDir::new("process-execution").map_err(|err| {
format!(
"Error making tempdir for local process execution: {:?}",
err
)
})
);

let store = self.store.clone();
Expand Down Expand Up @@ -105,18 +107,18 @@ mod tests {
extern crate tempdir;
extern crate testutil;

use self::testutil::{as_bytes, owned_string_vec};
use super::super::CommandRunner as CommandRunnerTrait;
use super::{ExecuteProcessRequest, ExecuteProcessResult};
use fs;
use futures::Future;
use super::{ExecuteProcessRequest, ExecuteProcessResult};
use super::super::CommandRunner as CommandRunnerTrait;
use std;
use std::collections::{BTreeMap, BTreeSet};
use std::env;
use std::os::unix::fs::PermissionsExt;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use tempdir::TempDir;
use self::testutil::{as_bytes, owned_string_vec};
use testutil::data::{TestData, TestDirectory};

#[test]
Expand Down
16 changes: 9 additions & 7 deletions src/rust/engine/process_execution/src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use digest::{Digest as DigestTrait, FixedOutput};
use fs::{self, Store};
use futures::{future, Future};
use futures_timer::Delay;
use hashing::{Digest, Fingerprint};
use grpcio;
use hashing::{Digest, Fingerprint};
use protobuf::{self, Message, ProtobufEnum};
use resettable::Resettable;
use sha2::Sha256;
Expand Down Expand Up @@ -268,10 +268,12 @@ impl CommandRunner {
try_future!(
precondition_failure
.merge_from_bytes(details.get_value())
.map_err(|e| ExecutionError::Fatal(format!(
"Error deserializing FailedPrecondition proto: {:?}",
e
)))
.map_err(|e| {
ExecutionError::Fatal(format!(
"Error deserializing FailedPrecondition proto: {:?}",
e
))
})
);

let mut missing_digests =
Expand Down Expand Up @@ -464,14 +466,14 @@ mod tests {
use futures::Future;
use grpcio;
use hashing::Digest;
use protobuf::{self, Message, ProtobufEnum};
use mock;
use protobuf::{self, Message, ProtobufEnum};
use tempdir::TempDir;
use testutil::data::{TestData, TestDirectory};
use testutil::{as_bytes, owned_string_vec};

use super::{CommandRunner, ExecuteProcessRequest, ExecuteProcessResult, ExecutionError};
use super::super::CommandRunner as CommandRunnerTrait;
use super::{CommandRunner, ExecuteProcessRequest, ExecuteProcessResult, ExecutionError};
use std::collections::{BTreeMap, BTreeSet};
use std::iter::{self, FromIterator};
use std::sync::Arc;
Expand Down
2 changes: 1 addition & 1 deletion src/rust/engine/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
use fnv::FnvHasher;

use std::collections::HashMap;
use std::{fmt, hash};
use std::ops::Drop;
use std::{fmt, hash};

use externs;
use handles::{enqueue_drop_handle, Handle};
Expand Down
8 changes: 4 additions & 4 deletions src/rust/engine/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ use std::io::{self, BufWriter, Write};
use std::path::{Path, PathBuf};
use std::sync::Mutex;

use futures::future::{self, Future};
use petgraph::Direction;
use petgraph::stable_graph::{NodeIndex, StableDiGraph, StableGraph};
use futures::future::{self, Future};

use externs;
use boxfuture::Boxable;
use context::ContextFactory;
use core::{Failure, Noop, FNV};
use externs;
use hashing;
use nodes::{DigestFile, Node, NodeFuture, NodeKey, NodeResult, TryInto};

Expand Down Expand Up @@ -341,7 +341,7 @@ impl InnerGraph {
};

try!(f.write_all(b"digraph plans {\n"));
try!(f.write_fmt(format_args!(" node[colorscheme={}];\n", viz_color_scheme),));
try!(f.write_fmt(format_args!(" node[colorscheme={}];\n", viz_color_scheme)));
try!(f.write_all(b" concentrate=true;\n"));
try!(f.write_all(b" rankdir=TB;\n"));

Expand Down Expand Up @@ -371,7 +371,7 @@ impl InnerGraph {

// Write an entry per edge.
let dep_str = dep_entry.format::<NodeKey>();
try!(f.write_fmt(format_args!(" \"{}\" -> \"{}\"\n", node_str, dep_str),));
try!(f.write_fmt(format_args!(" \"{}\" -> \"{}\"\n", node_str, dep_str)));
}
}

Expand Down
Loading

0 comments on commit 5fc27e2

Please sign in to comment.