Skip to content

Commit

Permalink
Bump to Rust 1.40 (pantsbuild#9017)
Browse files Browse the repository at this point in the history
* Bump to `1.40`, and fix all clippy lints.

* Fix rustfmt.
  • Loading branch information
stuhood authored Jan 27, 2020
1 parent cced8bb commit 2955fc5
Show file tree
Hide file tree
Showing 21 changed files with 76 additions and 90 deletions.
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.39.0
1.40.0
6 changes: 3 additions & 3 deletions src/rust/engine/engine_cffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ fn make_core(

let remote_execution_headers = remote_execution_headers_buf.to_map("remote-execution-headers")?;
Core::new(
root_type_ids.clone(),
root_type_ids,
tasks,
types,
PathBuf::from(build_root_buf.to_os_string()),
Expand Down Expand Up @@ -767,7 +767,7 @@ fn generate_panic_string(payload: &(dyn Any + Send)) -> String {
match payload
.downcast_ref::<String>()
.cloned()
.or_else(|| payload.downcast_ref::<&str>().map(|s| s.to_string()))
.or_else(|| payload.downcast_ref::<&str>().map(|&s| s.to_string()))
{
Some(ref s) => format!("panic at '{}'", s),
None => format!("Non-string panic payload at {:p}", payload),
Expand Down Expand Up @@ -970,7 +970,7 @@ pub extern "C" fn run_local_interactive_process(
let write_operation = scheduler.core.store().materialize_directory(
destination,
digest,
session.workunit_store().clone(),
session.workunit_store(),
);

scheduler.core.executor.spawn_on_io_pool(write_operation).wait()?;
Expand Down
28 changes: 9 additions & 19 deletions src/rust/engine/fs/src/glob_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,12 @@ trait GlobMatchingImplementation<E: Display + Send + Sync + 'static>: VFS<E> {
} else {
match stat {
Stat::Link(l) => context.canonicalize(stat_symbolic_path, l.clone()),
Stat::Dir(d) => future::ok(Some(PathStat::dir(
stat_symbolic_path.to_owned(),
d.clone(),
)))
.to_boxed(),
Stat::File(f) => future::ok(Some(PathStat::file(
stat_symbolic_path.to_owned(),
f.clone(),
)))
.to_boxed(),
Stat::Dir(d) => {
future::ok(Some(PathStat::dir(stat_symbolic_path, d.clone()))).to_boxed()
}
Stat::File(f) => {
future::ok(Some(PathStat::file(stat_symbolic_path, f.clone()))).to_boxed()
}
}
}
})
Expand Down Expand Up @@ -225,21 +221,15 @@ trait GlobMatchingImplementation<E: Display + Send + Sync + 'static>: VFS<E> {
canonical_dir,
symbolic_path,
wildcard,
} => self.expand_wildcard(
result.clone(),
exclude.clone(),
canonical_dir,
symbolic_path,
wildcard,
),
} => self.expand_wildcard(result, exclude, canonical_dir, symbolic_path, wildcard),
PathGlob::DirWildcard {
canonical_dir,
symbolic_path,
wildcard,
remainder,
} => self.expand_dir_wildcard(
result.clone(),
exclude.clone(),
result,
exclude,
canonical_dir,
symbolic_path,
wildcard,
Expand Down
2 changes: 1 addition & 1 deletion src/rust/engine/fs/store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ impl Store {
})
.map_err(|e| format!("Error writing file {:?}: {:?}", destination, e))
},
workunit_store.clone(),
workunit_store,
)
.and_then(move |write_result| match write_result {
Some((Ok(()), metadata)) => Ok(metadata),
Expand Down
5 changes: 2 additions & 3 deletions src/rust/engine/fs/store/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ impl ByteStore {
// travis fail because they can't allocate virtual memory, if there are multiple Stores
// in memory at the same time. We don't know why they're not efficiently garbage collected
// by python, but they're not, so...
file_dbs: ShardedLmdb::new(files_root.clone(), 100 * GIGABYTES, executor.clone())
.map(Arc::new),
directory_dbs: ShardedLmdb::new(directories_root.clone(), 5 * GIGABYTES, executor.clone())
file_dbs: ShardedLmdb::new(files_root, 100 * GIGABYTES, executor.clone()).map(Arc::new),
directory_dbs: ShardedLmdb::new(directories_root, 5 * GIGABYTES, executor.clone())
.map(Arc::new),
executor: executor,
}),
Expand Down
6 changes: 3 additions & 3 deletions src/rust/engine/fs/store/src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl ByteStore {
digest.1,
);
let workunit_name = format!("store_bytes({})", resource_name.clone());
let workunit_store = workunit_store.clone();
let workunit_store = workunit_store;
let store = self.clone();
self
.with_byte_stream_client(move |client| {
Expand Down Expand Up @@ -246,7 +246,7 @@ impl ByteStore {
digest.1
);
let workunit_name = format!("load_bytes_with({})", resource_name.clone());
let workunit_store = workunit_store.clone();
let workunit_store = workunit_store;
self
.with_byte_stream_client(move |client| {
match client
Expand Down Expand Up @@ -323,7 +323,7 @@ impl ByteStore {
"list_missing_digests({})",
store.instance_name.clone().unwrap_or_default()
);
let workunit_store = workunit_store.clone();
let workunit_store = workunit_store;
self
.with_cas_client(move |client| {
client
Expand Down
4 changes: 1 addition & 3 deletions src/rust/engine/fs/store/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,7 @@ impl Snapshot {
.map(|d| d.get_digest().into())
.collect::<Result<Vec<_>, String>>();
future::done(digests_result)
.and_then(move |digests| {
Self::merge_directories(store2.clone(), digests, workunit_store2.clone())
})
.and_then(move |digests| Self::merge_directories(store2, digests, workunit_store2))
.map(move |merged_digest| {
let mut child_dir = bazel_protos::remote_execution::DirectoryNode::new();
child_dir.set_name(child_name);
Expand Down
7 changes: 2 additions & 5 deletions src/rust/engine/graph/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,10 +446,7 @@ impl<N: Node> InnerGraph<N> {
// the Nodes (to avoid cloning them), adding equal edge weights, and then reversing it.
// Because we do not remove any Nodes or edges, all EntryIds remain stable.
let dependent_graph = {
let mut dg = self
.pg
.filter_map(|_, _| Some(()), |_, _| Some(1.0))
.clone();
let mut dg = self.pg.filter_map(|_, _| Some(()), |_, _| Some(1.0));
dg.reverse();
dg
};
Expand Down Expand Up @@ -660,7 +657,7 @@ impl<N: Node> Graph<N> {
let dst_id = {
// TODO: doing cycle detection under the lock... unfortunate, but probably unavoidable
// without a much more complicated algorithm.
let potential_dst_id = inner.ensure_entry(dst_node.clone());
let potential_dst_id = inner.ensure_entry(dst_node);
if let Some(cycle_path) = Self::report_cycle(src_id, potential_dst_id, &mut inner) {
// Cyclic dependency: render an error.
let path_strs = cycle_path
Expand Down
15 changes: 5 additions & 10 deletions src/rust/engine/process_execution/src/nailgun/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn construct_nailgun_server_request(
) -> ExecuteProcessRequest {
let mut full_args = args_for_the_jvm;
full_args.push(NAILGUN_MAIN_CLASS.to_string());
full_args.extend(ARGS_TO_START_NAILGUN.iter().map(|a| a.to_string()));
full_args.extend(ARGS_TO_START_NAILGUN.iter().map(|&a| a.to_string()));

ExecuteProcessRequest {
argv: full_args,
Expand Down Expand Up @@ -231,12 +231,8 @@ impl CapturedWorkdir for CommandRunner {
.jdk_home
.clone()
.ok_or("JDK home must be specified for all nailgunnable requests.")?;
let nailgun_req = construct_nailgun_server_request(
&nailgun_name,
nailgun_args,
jdk_home.clone(),
req.target_platform,
);
let nailgun_req =
construct_nailgun_server_request(&nailgun_name, nailgun_args, jdk_home, req.target_platform);
trace!("Extracted nailgun request:\n {:#?}", &nailgun_req);

let nailgun_req_digest = crate::digest(
Expand All @@ -247,10 +243,9 @@ impl CapturedWorkdir for CommandRunner {
let nailgun_pool = self.nailgun_pool.clone();
let req2 = req.clone();
let workdir_for_this_nailgun = self.get_nailgun_workdir(&nailgun_name)?;
let workdir_for_this_nailgun1 = workdir_for_this_nailgun.clone();
let build_id = context.build_id.clone();
let store = self.inner.store.clone();
let workunit_store = context.workunit_store.clone();
let workunit_store = context.workunit_store;

// Streams to read child output from
let (stdio_write, stdio_read) = child_channel::<ChildOutput>();
Expand All @@ -263,7 +258,7 @@ impl CapturedWorkdir for CommandRunner {
nailgun_pool.connect(
nailgun_name.clone(),
nailgun_req,
workdir_for_this_nailgun1,
workdir_for_this_nailgun,
nailgun_req_digest,
build_id,
store,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ impl NailgunPool {
.lock()
.try_wait()
.map_err(|e| format!("Error getting the process status! {}", e))
.clone()
};
match status {
Ok(None) => {
Expand Down
5 changes: 2 additions & 3 deletions src/rust/engine/process_execution/src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ pub fn make_execute_request(
> {
let mut command = bazel_protos::remote_execution::Command::new();
command.set_arguments(protobuf::RepeatedField::from_vec(req.argv.clone()));
for (ref name, ref value) in &req.env {
for (name, value) in &req.env {
if name.as_str() == CACHE_KEY_GEN_VERSION_ENV_VAR_NAME {
return Err(format!(
"Cannot set env var with name {} as that is reserved for internal use by pants",
Expand Down Expand Up @@ -949,7 +949,7 @@ pub fn populate_fallible_execution_result(
.join(extract_output_files(
store,
&execute_response,
workunit_store.clone(),
workunit_store,
))
.and_then(move |((stdout, stderr), output_directory)| {
Ok(FallibleExecuteProcessResult {
Expand Down Expand Up @@ -1127,7 +1127,6 @@ pub fn extract_output_files(
}
}

let store = store.clone();
Snapshot::digest_from_path_stats(
store.clone(),
&StoreOneOffRemoteDigest::new(path_map),
Expand Down
4 changes: 2 additions & 2 deletions src/rust/engine/process_execution/src/speculate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ impl CommandRunner for SpeculatingCommandRunner {
self.primary.extract_compatible_request(req),
self.secondary.extract_compatible_request(req),
) {
(Some(req), _) => Some(req.clone()),
(_, Some(req)) => Some(req.clone()),
(Some(req), _) => Some(req),
(_, Some(req)) => Some(req),
_ => None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/rust/engine/process_executor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ fn main() {
headers,
store.clone(),
Platform::Linux,
executor.clone(),
executor,
std::time::Duration::from_secs(160),
std::time::Duration::from_millis(500),
std::time::Duration::from_secs(5),
Expand Down
25 changes: 17 additions & 8 deletions src/rust/engine/rule_graph/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

mod rules;

use std::cmp::Ordering;
use std::collections::{hash_map, BTreeSet, HashMap, HashSet};
use std::io;

Expand Down Expand Up @@ -671,12 +672,16 @@ impl<'t, R: Rule> GraphMaker<'t, R> {
Entry::WithDeps(ref wd) => wd.params().len(),
Entry::Param(_) => 1,
};
if param_set_size < minimum_param_set_size {
rules.clear();
rules.push(satisfiable_entry);
minimum_param_set_size = param_set_size;
} else if param_set_size == minimum_param_set_size {
rules.push(satisfiable_entry);
match param_set_size.cmp(&minimum_param_set_size) {
Ordering::Less => {
rules.clear();
rules.push(satisfiable_entry);
minimum_param_set_size = param_set_size;
}
Ordering::Equal => {
rules.push(satisfiable_entry);
}
Ordering::Greater => {}
}
}

Expand Down Expand Up @@ -972,7 +977,7 @@ impl<R: Rule> RuleGraph<R> {
.into_iter()
.map(|mut d| {
if d.details.is_empty() {
d.reason.clone()
d.reason
} else {
d.details.sort();
format!("{}:\n {}", d.reason, d.details.join("\n "))
Expand All @@ -985,7 +990,11 @@ impl<R: Rule> RuleGraph<R> {
.collect();
msgs.sort();

Err(format!("Rules with errors: {}\n {}", msgs.len(), msgs.join("\n ")).to_string())
Err(format!(
"Rules with errors: {}\n {}",
msgs.len(),
msgs.join("\n ")
))
}

pub fn visualize(&self, f: &mut dyn io::Write) -> io::Result<()> {
Expand Down
10 changes: 5 additions & 5 deletions src/rust/engine/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ impl Core {
.map_err(|e| format!("Could not initialize Store: {:?}", e))?;

let process_execution_metadata = ExecuteProcessRequestMetadata {
instance_name: remote_instance_name.clone(),
cache_key_gen_version: remote_execution_process_cache_namespace.clone(),
platform_properties: remote_execution_extra_platform_properties.clone(),
instance_name: remote_instance_name,
cache_key_gen_version: remote_execution_process_cache_namespace,
platform_properties: remote_execution_extra_platform_properties,
};

let local_command_runner = process_execution::local::CommandRunner::new(
Expand Down Expand Up @@ -174,8 +174,8 @@ impl Core {
// requires the remote_execution_server be present when remote_execution is set.
&remote_execution_server.unwrap(),
process_execution_metadata.clone(),
root_ca_certs.clone(),
oauth_bearer_token.clone(),
root_ca_certs,
oauth_bearer_token,
remote_execution_headers,
store.clone(),
// TODO if we ever want to configure the remote platform to be something else we
Expand Down
9 changes: 6 additions & 3 deletions src/rust/engine/src/handles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ pub struct Handle(pub RawHandle);

impl Handle {
///
/// An escape hatch to allow for cloning a Handle without cloning the value it points to. You
/// should generally not do this unless you are certain the input Handle has been mem::forgotten
/// (otherwise it will be `Drop`ed twice).
/// An escape hatch to allow for cloning a Handle without cloning the value it points to.
///
/// # Safety
///
/// You should not call this method unless you are certain the input Handle has been
/// mem::forgotten (otherwise it will be `Drop`ed twice).
///
pub unsafe fn clone_shallow(&self) -> Handle {
Handle(self.0)
Expand Down
4 changes: 2 additions & 2 deletions src/rust/engine/src/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ fn directory_with_prefix_to_strip_to_digest(context: Context, request: Value) ->
}

fn directory_with_prefix_to_add_to_digest(context: Context, request: Value) -> NodeFuture<Value> {
let core = context.core.clone();
let core = context.core;
future::result(
lift_digest(&externs::project_ignoring_type(
&request,
Expand Down Expand Up @@ -134,7 +134,7 @@ fn digest_to_snapshot(context: Context, directory_digest_val: Value) -> NodeFutu

fn directories_to_merge_to_digest(context: Context, request: Value) -> NodeFuture<Value> {
let workunit_store = context.session.workunit_store();
let core = context.core.clone();
let core = context.core;
let digests: Result<Vec<hashing::Digest>, Failure> =
externs::project_multi(&request, "directories")
.into_iter()
Expand Down
Loading

0 comments on commit 2955fc5

Please sign in to comment.