let error = str::from_utf8(&output.stderr).unwrap();
let output = str::from_utf8(&output.stdout).unwrap();
- Ok(parse_crate_type(
- crate_type,
- &process,
- output,
- error,
- &mut output.lines(),
- )?)
+ parse_crate_type(crate_type, &process, output, error, &mut output.lines())
}
/// Returns all the file types generated by rustc for the given mode/target_kind.
//! dependencies on other Invocations.
use std::collections::BTreeMap;
-use std::path::PathBuf;
+use std::path::{Path, PathBuf};
use serde::Serialize;
}
}
- pub fn add_output(&mut self, path: &PathBuf, link: &Option<PathBuf>) {
- self.outputs.push(path.clone());
+ pub fn add_output(&mut self, path: &Path, link: &Option<PathBuf>) {
+ self.outputs.push(path.to_path_buf());
if let Some(ref link) = *link {
- self.links.insert(link.clone(), path.clone());
+ self.links.insert(link.clone(), path.to_path_buf());
}
}
) -> (
Box<
dyn FnOnce(
- &BuildDeps,
- Option<&dyn Fn() -> CargoResult<String>>,
- ) -> CargoResult<Option<Vec<LocalFingerprint>>>
+ &BuildDeps,
+ Option<&dyn Fn() -> CargoResult<String>>,
+ ) -> CargoResult<Option<Vec<LocalFingerprint>>>
+ Send,
>,
bool,
// thread to run the job.
doit(JobState {
id,
- messages: messages.clone(),
+ messages,
output: Some(cx.bcx.config),
rmeta_required: Cell::new(rmeta_required),
_marker: marker::PhantomData,
current_id: PackageId,
metadata: Option<Metadata>,
) {
- let metadata = match metadata {
- Some(metadata) => metadata,
- None => {
- return;
- }
- };
- if let Some(output) = build_script_outputs.get(current_id, metadata) {
- for &(ref name, ref value) in output.env.iter() {
- rustc.env(name, value);
+ if let Some(metadata) = metadata {
+ if let Some(output) = build_script_outputs.get(current_id, metadata) {
+ for &(ref name, ref value) in output.env.iter() {
+ rustc.env(name, value);
+ }
}
}
}
rustc: &mut ProcessBuilder,
build_script_outputs: &BuildScriptOutputs,
build_scripts: &BuildScripts,
- root_output: &PathBuf,
+ root_output: &Path,
) -> CargoResult<()> {
let var = util::dylib_path_envvar();
let search_path = rustc.get_env(var).unwrap_or_default();
// Strip off prefixes like "native=" or "framework=" and filter out directories
// **not** inside our output directory since they are likely spurious and can cause
// clashes with system shared libraries (issue #3366).
-fn filter_dynamic_search_path<'a, I>(paths: I, root_output: &PathBuf) -> Vec<PathBuf>
+fn filter_dynamic_search_path<'a, I>(paths: I, root_output: &Path) -> Vec<PathBuf>
where
I: Iterator<Item = &'a PathBuf>,
{
/// eventually be returned from `wait_for_download`. Returns `Some(pkg)` if
/// the package is ready and doesn't need to be downloaded.
pub fn start(&mut self, id: PackageId) -> CargoResult<Option<&'a Package>> {
- Ok(self
- .start_inner(id)
- .chain_err(|| format!("failed to download `{}`", id))?)
+ self.start_inner(id)
+ .chain_err(|| format!("failed to download `{}`", id))
}
fn start_inner(&mut self, id: PackageId) -> CargoResult<Option<&'a Package>> {
fn add_root_profiles(
profile_makers: &mut Profiles,
profiles: &BTreeMap<InternedString, TomlProfile>,
- ) {
+ ) {
profile_makers.by_name.insert(
InternedString::new("dev"),
ProfileMaker::new(Profile::default_dev(), profiles.get("dev").cloned()),
let bcx = create_bcx(ws, options, &interner)?;
if options.build_config.unit_graph {
unit_graph::emit_serialized_unit_graph(&bcx.roots, &bcx.unit_graph)?;
- return Ok(Compilation::new(&bcx)?);
+ return Compilation::new(&bcx);
}
let _p = profile::start("compiling");
metadata_opts.all_features,
!metadata_opts.no_default_features,
);
- let resolve_opts = ResolveOpts::new(/*dev_deps*/ true, requested_features.clone());
+ let resolve_opts = ResolveOpts::new(/*dev_deps*/ true, requested_features);
let force_all = if metadata_opts.filter_platforms.is_empty() {
crate::core::resolver::features::ForceAllTargets::Yes
} else {
// `registry.default` is handled in command-line parsing.
let (index, token, process) = match registry {
Some(registry) => {
- validate_package_name(®istry, "registry name", "")?;
- let index = Some(config.get_registry_index(®istry)?.to_string());
+ validate_package_name(registry, "registry name", "")?;
+ let index = Some(config.get_registry_index(registry)?.to_string());
let token_key = format!("registries.{}.token", registry);
let token = config.get_string(&token_key)?.map(|p| p.val);
let process = if config.cli_unstable().credential_process {
};
let token = if validate_token {
if index.is_some() {
- if !token.is_some() {
+ if token.is_none() {
bail!("command-line argument --index requires --token to be specified");
}
token
opts.all_features,
!opts.no_default_features,
);
- let resolve_opts = ResolveOpts::new(/*dev_deps*/ true, requested_features.clone());
+ let resolve_opts = ResolveOpts::new(/*dev_deps*/ true, requested_features);
let has_dev = if opts
.edge_kinds
.contains(&EdgeKind::Dep(DepKind::Development))
paths::create_dir_all(dst.parent().unwrap())?;
- let cksum = copy_and_checksum(&p, &dst, tmp_buf)?;
+ let cksum = copy_and_checksum(p, &dst, tmp_buf)?;
cksums.insert(relative.to_str().unwrap().replace("\\", "/"), cksum);
}
Ok(())
let mut name = match self.id2name.get(&id) {
Some(name) => name,
- None => return Ok(id.load(self.config, yanked_whitelist)?),
+ None => return id.load(self.config, yanked_whitelist),
};
let mut cfg_loc = "";
let orig_name = name;
name = s;
cfg_loc = c;
}
- None if id == cfg.id => return Ok(id.load(self.config, yanked_whitelist)?),
+ None if id == cfg.id => return id.load(self.config, yanked_whitelist),
None => {
new_id = cfg.id.with_precise(id.precise().map(|s| s.to_string()));
break;
.and_then(|s| s.rev().next())
.unwrap_or("");
- let ident = if ident == "" { "_empty" } else { ident };
+ let ident = if ident.is_empty() { "_empty" } else { ident };
format!("{}-{}", ident, short_hash(id.canonical_url()))
}
// call our callback, `f`, in a loop here.
if ssh_username_requested {
debug_assert!(res.is_err());
- let mut attempts = Vec::new();
- attempts.push("git".to_string());
+ let mut attempts = vec![String::from("git")];
if let Ok(s) = env::var("USER").or_else(|_| env::var("USERNAME")) {
attempts.push(s);
}
pub fn http_config(&self) -> CargoResult<&CargoHttpConfig> {
self.http_config
- .try_borrow_with(|| Ok(self.get::<CargoHttpConfig>("http")?))
+ .try_borrow_with(|| self.get::<CargoHttpConfig>("http"))
}
pub fn net_config(&self) -> CargoResult<&CargoNetConfig> {
self.net_config
- .try_borrow_with(|| Ok(self.get::<CargoNetConfig>("net")?))
+ .try_borrow_with(|| self.get::<CargoNetConfig>("net"))
}
pub fn build_config(&self) -> CargoResult<&CargoBuildConfig> {
self.build_config
- .try_borrow_with(|| Ok(self.get::<CargoBuildConfig>("build")?))
+ .try_borrow_with(|| self.get::<CargoBuildConfig>("build"))
}
pub fn progress_config(&self) -> &ProgressConfig {
// Links do not support environment variables.
let target_key = ConfigKey::from_str(&format!("target.{}", triple));
let links_overrides = match config.get_table(&target_key)? {
- Some(links) => parse_links_overrides(&target_key, links.val, &config)?,
+ Some(links) => parse_links_overrides(&target_key, links.val, config)?,
None => BTreeMap::new(),
};
Ok(TargetConfig {
///
/// CLI is preferred over environment, which is preferred over files.
pub fn is_higher_priority(&self, other: &Definition) -> bool {
- match (self, other) {
- (Definition::Cli, Definition::Environment(_)) => true,
- (Definition::Cli, Definition::Path(_)) => true,
- (Definition::Environment(_), Definition::Path(_)) => true,
- _ => false,
- }
+ matches!(
+ (self, other),
+ (Definition::Cli, Definition::Environment(_))
+ | (Definition::Cli, Definition::Path(_))
+ | (Definition::Environment(_), Definition::Path(_))
+ )
}
}
let paths = env::var_os("PATH").ok_or_else(|| anyhow::format_err!("no PATH"))?;
let candidates = env::split_paths(&paths).flat_map(|path| {
let candidate = path.join(&exec);
- let with_exe = if env::consts::EXE_EXTENSION == "" {
+ let with_exe = if env::consts::EXE_EXTENSION.is_empty() {
None
} else {
Some(candidate.with_extension(env::consts::EXE_EXTENSION))