Skip to content

Commit

Permalink
Auto merge of #6896 - k-nasa:fix_fmt, r=ehuss
Browse files Browse the repository at this point in the history
Run 'cargo fmt --all'
  • Loading branch information
bors committed May 1, 2019
2 parents a6737f5 + 63a9c7a commit ba5aac5
Show file tree
Hide file tree
Showing 20 changed files with 141 additions and 109 deletions.
4 changes: 2 additions & 2 deletions src/cargo/core/compiler/build_context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use std::str;

use log::debug;

use crate::core::compiler::unit::UnitInterner;
use crate::core::compiler::{BuildConfig, BuildOutput, Kind, Unit};
use crate::core::profiles::Profiles;
use crate::core::{Dependency, Workspace};
use crate::core::{PackageId, PackageSet, Resolve};
use crate::util::errors::CargoResult;
use crate::util::{profile, Cfg, Config, Rustc};
use crate::core::compiler::{Unit, Kind, BuildConfig, BuildOutput};
use crate::core::compiler::unit::UnitInterner;

mod target_info;
pub use self::target_info::{FileFlavor, TargetInfo};
Expand Down
8 changes: 7 additions & 1 deletion src/cargo/core/compiler/fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,13 @@ impl Serialize for DepFingerprint {
where
S: ser::Serializer,
{
(&self.pkg_id, &self.name, &self.public, &self.fingerprint.hash()).serialize(ser)
(
&self.pkg_id,
&self.name,
&self.public,
&self.fingerprint.hash(),
)
.serialize(ser)
}
}

Expand Down
20 changes: 12 additions & 8 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use log::debug;
use same_file::is_same_file;
use serde::Serialize;

use crate::core::Feature;
pub use self::build_config::{BuildConfig, CompileMode, MessageFormat};
pub use self::build_context::{BuildContext, FileFlavor, TargetConfig, TargetInfo};
use self::build_plan::BuildPlan;
Expand All @@ -38,6 +37,7 @@ use self::output_depinfo::output_depinfo;
pub use crate::core::compiler::unit::{Unit, UnitInterner};
use crate::core::manifest::TargetSourcePath;
use crate::core::profiles::{Lto, PanicStrategy, Profile};
use crate::core::Feature;
use crate::core::{PackageId, Target};
use crate::util::errors::{CargoResult, CargoResultExt, Internal, ProcessError};
use crate::util::paths;
Expand Down Expand Up @@ -984,15 +984,14 @@ fn build_deps_args<'a, 'cfg>(
cmd.arg("-Z").arg("unstable-options");
}


return Ok(());

fn link_to<'a, 'cfg>(
cmd: &mut ProcessBuilder,
cx: &mut Context<'a, 'cfg>,
current: &Unit<'a>,
dep: &Unit<'a>,
need_unstable_opts: &mut bool
need_unstable_opts: &mut bool,
) -> CargoResult<()> {
let bcx = cx.bcx;
for output in cx.outputs(dep)?.iter() {
Expand All @@ -1007,11 +1006,16 @@ fn build_deps_args<'a, 'cfg>(
v.push(&path::MAIN_SEPARATOR.to_string());
v.push(&output.path.file_name().unwrap());

if current.pkg.manifest().features().require(Feature::public_dependency()).is_ok() &&
!bcx.is_public_dependency(current, dep) {

cmd.arg("--extern-private");
*need_unstable_opts = true;
if current
.pkg
.manifest()
.features()
.require(Feature::public_dependency())
.is_ok()
&& !bcx.is_public_dependency(current, dep)
{
cmd.arg("--extern-private");
*need_unstable_opts = true;
} else {
cmd.arg("--extern");
}
Expand Down
44 changes: 27 additions & 17 deletions src/cargo/core/resolver/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use std::iter::FromIterator;

use url::Url;

use crate::core::{Dependency, PackageId, PackageIdSpec, Summary, Target};
use crate::core::dependency::Kind;
use crate::core::{Dependency, PackageId, PackageIdSpec, Summary, Target};
use crate::util::errors::CargoResult;
use crate::util::Graph;

Expand Down Expand Up @@ -44,20 +44,29 @@ impl Resolve {
unused_patches: Vec<PackageId>,
) -> Resolve {
let reverse_replacements = replacements.iter().map(|(&p, &r)| (r, p)).collect();
let public_dependencies = graph.iter().map(|p| {
let public_deps = graph.edges(p).flat_map(|(dep_package, deps)| {
let id_opt: Option<PackageId> = deps.iter().find(|d| d.kind() == Kind::Normal).and_then(|d| {
if d.is_public() {
Some(dep_package.clone())
} else {
None
}
});
id_opt
}).collect::<HashSet<PackageId>>();

(p.clone(), public_deps)
}).collect();
let public_dependencies = graph
.iter()
.map(|p| {
let public_deps = graph
.edges(p)
.flat_map(|(dep_package, deps)| {
let id_opt: Option<PackageId> = deps
.iter()
.find(|d| d.kind() == Kind::Normal)
.and_then(|d| {
if d.is_public() {
Some(dep_package.clone())
} else {
None
}
});
id_opt
})
.collect::<HashSet<PackageId>>();

(p.clone(), public_deps)
})
.collect();

Resolve {
graph,
Expand All @@ -68,7 +77,7 @@ impl Resolve {
unused_patches,
empty_features: HashSet::new(),
reverse_replacements,
public_dependencies
public_dependencies,
}
}

Expand Down Expand Up @@ -217,7 +226,8 @@ unable to verify that `{0}` is the same as when the lockfile was generated
}

pub fn is_public_dep(&self, pkg: PackageId, dep: PackageId) -> bool {
self.public_dependencies.get(&pkg)
self.public_dependencies
.get(&pkg)
.map(|public_deps| public_deps.contains(&dep))
.unwrap_or_else(|| panic!("Unknown dependency {:?} for package {:?}", dep, pkg))
}
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use url::Url;
use crate::core::features::Features;
use crate::core::profiles::Profiles;
use crate::core::registry::PackageRegistry;
use crate::core::{Dependency, PackageIdSpec, PackageId};
use crate::core::{Dependency, PackageId, PackageIdSpec};
use crate::core::{EitherManifest, Package, SourceId, VirtualManifest};
use crate::ops;
use crate::sources::PathSource;
Expand Down
4 changes: 3 additions & 1 deletion src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,9 @@ fn generate_targets<'a>(
} => {
if *lib != LibRule::False {
let mut libs = Vec::new();
for proposal in filter_targets(packages, Target::is_lib, false, bcx.build_config.mode) {
for proposal in
filter_targets(packages, Target::is_lib, false, bcx.build_config.mode)
{
let Proposal { target, pkg, .. } = proposal;
if bcx.build_config.mode == CompileMode::Doctest && !target.doctestable() {
ws.config().shell().warn(format!(
Expand Down
9 changes: 7 additions & 2 deletions src/cargo/ops/cargo_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ use termcolor::Color;

use crate::core::compiler::{BuildConfig, CompileMode, DefaultExecutor, Executor};
use crate::core::resolver::Method;
use crate::core::Feature;
use crate::core::{
Package, PackageId, PackageIdSpec, PackageSet, Resolve, Source, SourceId, Verbosity, Workspace,
};
use crate::core::Feature;
use crate::ops;
use crate::sources::PathSource;
use crate::util::errors::{CargoResult, CargoResultExt};
Expand Down Expand Up @@ -591,7 +591,12 @@ fn run_verify(ws: &Workspace<'_>, tar: &FileLock, opts: &PackageOpts<'_>) -> Car
let pkg_fingerprint = hash_all(&dst)?;
let ws = Workspace::ephemeral(new_pkg, config, None, true)?;

let rustc_args = if pkg.manifest().features().require(Feature::public_dependency()).is_ok() {
let rustc_args = if pkg
.manifest()
.features()
.require(Feature::public_dependency())
.is_ok()
{
// FIXME: Turn this on at some point in the future
//Some(vec!["-D exported_private_dependencies".to_string()])
None
Expand Down
10 changes: 6 additions & 4 deletions src/cargo/ops/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
opts.index.clone(),
opts.registry.clone(),
true,
!opts.dry_run
!opts.dry_run,
)?;
verify_dependencies(pkg, &registry, reg_id)?;

Expand Down Expand Up @@ -326,7 +326,9 @@ pub fn registry_configuration(
None => {
// Checking for default index and token
(
config.get_default_registry_index()?.map(|url| url.to_string()),
config
.get_default_registry_index()?
.map(|url| url.to_string()),
config.get_string("registry.token")?.map(|p| p.val),
)
}
Expand All @@ -341,7 +343,7 @@ fn registry(
index: Option<String>,
registry: Option<String>,
force_update: bool,
validate_token: bool
validate_token: bool,
) -> CargoResult<(Registry, SourceId)> {
// Parse all configuration options
let RegistryConfig {
Expand Down Expand Up @@ -609,7 +611,7 @@ pub fn modify_owners(config: &Config, opts: &OwnersOptions) -> CargoResult<()> {
opts.index.clone(),
opts.registry.clone(),
true,
true
true,
)?;

if let Some(ref v) = opts.to_add {
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use std::rc::Rc;

use log::{debug, trace};

use crate::core::Feature;
use crate::core::registry::PackageRegistry;
use crate::core::resolver::{self, Method, Resolve};
use crate::core::Feature;
use crate::core::{PackageId, PackageIdSpec, PackageSet, Source, SourceId, Workspace};
use crate::ops;
use crate::sources::PathSource;
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/sources/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ struct RegistryDependency<'a> {
kind: Option<Cow<'a, str>>,
registry: Option<Cow<'a, str>>,
package: Option<Cow<'a, str>>,
public: Option<bool>
public: Option<bool>,
}

impl<'a> RegistryDependency<'a> {
Expand All @@ -301,7 +301,7 @@ impl<'a> RegistryDependency<'a> {
kind,
registry,
package,
public
public,
} = self;

let id = if let Some(registry) = &registry {
Expand Down
24 changes: 12 additions & 12 deletions src/cargo/util/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ use crate::util::errors::{self, internal, CargoResult, CargoResultExt};
use crate::util::toml as cargo_toml;
use crate::util::Filesystem;
use crate::util::Rustc;
use crate::util::{ToUrl, ToUrlWithBase};
use crate::util::{paths, validate_package_name};
use crate::util::{ToUrl, ToUrlWithBase};

/// Configuration information for cargo. This is not specific to a build, it is information
/// relating to cargo itself.
Expand Down Expand Up @@ -275,9 +275,9 @@ impl Config {
}

pub fn updated_sources(&self) -> RefMut<'_, HashSet<SourceId>> {
self.updated_sources.borrow_with(|| {
RefCell::new(HashSet::new())
}).borrow_mut()
self.updated_sources
.borrow_with(|| RefCell::new(HashSet::new()))
.borrow_mut()
}

pub fn values(&self) -> CargoResult<&HashMap<String, ConfigValue>> {
Expand Down Expand Up @@ -675,16 +675,17 @@ impl Config {

/// Gets the index for the default registry.
pub fn get_default_registry_index(&self) -> CargoResult<Option<Url>> {
Ok(
match self.get_string("registry.index")? {
Some(index) => Some(self.resolve_registry_index(index)?),
None => None,
},
)
Ok(match self.get_string("registry.index")? {
Some(index) => Some(self.resolve_registry_index(index)?),
None => None,
})
}

fn resolve_registry_index(&self, index: Value<String>) -> CargoResult<Url> {
let base = index.definition.root(&self).join("truncated-by-url_with_base");
let base = index
.definition
.root(&self)
.join("truncated-by-url_with_base");
// Parse val to check it is a URL, not a relative path without a protocol.
let _parsed = index.val.to_url()?;
let url = index.val.to_url_with_base(Some(&*base))?;
Expand Down Expand Up @@ -1663,4 +1664,3 @@ pub fn save_credentials(cfg: &Config, token: String, registry: Option<String>) -
Ok(())
}
}

3 changes: 2 additions & 1 deletion src/cargo/util/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@ fn test_progress_status() {
);

// combining diacritics have width zero and thus can fit max_width.
let zalgo_msg = "z̸̧̢̗͉̝̦͍̱ͧͦͨ̑̅̌ͥ́͢a̢ͬͨ̽ͯ̅̑ͥ͋̏̑ͫ̄͢͏̫̝̪̤͎̱̣͍̭̞̙̱͙͍̘̭͚l̶̡̛̥̝̰̭̹̯̯̞̪͇̱̦͙͔̘̼͇͓̈ͨ͗ͧ̓͒ͦ̀̇ͣ̈ͭ͊͛̃̑͒̿̕͜g̸̷̢̩̻̻͚̠͓̞̥͐ͩ͌̑ͥ̊̽͋͐̐͌͛̐̇̑ͨ́ͅo͙̳̣͔̰̠̜͕͕̞̦̙̭̜̯̹̬̻̓͑ͦ͋̈̉͌̃ͯ̀̂͠ͅ ̸̡͎̦̲̖̤̺̜̮̱̰̥͔̯̅̏ͬ̂ͨ̋̃̽̈́̾̔̇ͣ̚͜͜h̡ͫ̐̅̿̍̀͜҉̛͇̭̹̰̠͙̞ẽ̶̙̹̳̖͉͎̦͂̋̓ͮ̔ͬ̐̀͂̌͑̒͆̚͜͠ ͓͓̟͍̮̬̝̝̰͓͎̼̻ͦ͐̾̔͒̃̓͟͟c̮̦͍̺͈͚̯͕̄̒͐̂͊̊͗͊ͤͣ̀͘̕͝͞o̶͍͚͍̣̮͌ͦ̽̑ͩ̅ͮ̐̽̏͗́͂̅ͪ͠m̷̧͖̻͔̥̪̭͉͉̤̻͖̩̤͖̘ͦ̂͌̆̂ͦ̒͊ͯͬ͊̉̌ͬ͝͡e̵̹̣͍̜̺̤̤̯̫̹̠̮͎͙̯͚̰̼͗͐̀̒͂̉̀̚͝͞s̵̲͍͙͖̪͓͓̺̱̭̩̣͖̣ͤͤ͂̎̈͗͆ͨͪ̆̈͗͝͠";
let zalgo_msg =
"z̸̧̢̗͉̝̦͍̱ͧͦͨ̑̅̌ͥ́͢a̢ͬͨ̽ͯ̅̑ͥ͋̏̑ͫ̄͢͏̫̝̪̤͎̱̣͍̭̞̙̱͙͍̘̭͚l̶̡̛̥̝̰̭̹̯̯̞̪͇̱̦͙͔̘̼͇͓̈ͨ͗ͧ̓͒ͦ̀̇ͣ̈ͭ͊͛̃̑͒̿̕͜g̸̷̢̩̻̻͚̠͓̞̥͐ͩ͌̑ͥ̊̽͋͐̐͌͛̐̇̑ͨ́ͅo͙̳̣͔̰̠̜͕͕̞̦̙̭̜̯̹̬̻̓͑ͦ͋̈̉͌̃ͯ̀̂͠ͅ ̸̡͎̦̲̖̤̺̜̮̱̰̥͔̯̅̏ͬ̂ͨ̋̃̽̈́̾̔̇ͣ̚͜͜h̡ͫ̐̅̿̍̀͜҉̛͇̭̹̰̠͙̞ẽ̶̙̹̳̖͉͎̦͂̋̓ͮ̔ͬ̐̀͂̌͑̒͆̚͜͠ ͓͓̟͍̮̬̝̝̰͓͎̼̻ͦ͐̾̔͒̃̓͟͟c̮̦͍̺͈͚̯͕̄̒͐̂͊̊͗͊ͤͣ̀͘̕͝͞o̶͍͚͍̣̮͌ͦ̽̑ͩ̅ͮ̐̽̏͗́͂̅ͪ͠m̷̧͖̻͔̥̪̭͉͉̤̻͖̩̤͖̘ͦ̂͌̆̂ͦ̒͊ͯͬ͊̉̌ͬ͝͡e̵̹̣͍̜̺̤̤̯̫̹̠̮͎͙̯͚̰̼͗͐̀̒͂̉̀̚͝͞s̵̲͍͙͖̪͓͓̺̱̭̩̣͖̣ͤͤ͂̎̈͗͆ͨͪ̆̈͗͝͠";
assert_eq!(
format.progress_status(3, 4, zalgo_msg),
Some("[=============> ] 3/4".to_string() + zalgo_msg)
Expand Down
37 changes: 21 additions & 16 deletions src/cargo/util/to_url_with_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@ pub trait ToUrlWithBase {
impl<'a> ToUrlWithBase for &'a str {
fn to_url_with_base<U: ToUrl>(self, base: Option<U>) -> CargoResult<Url> {
let base_url = match base {
Some(base) =>
Some(base.to_url().map_err(|s| {
failure::format_err!("invalid url `{}`: {}", self, s)
})?),
None => None
Some(base) => Some(
base.to_url()
.map_err(|s| failure::format_err!("invalid url `{}`: {}", self, s))?,
),
None => None,
};

Url::options()
.base_url(base_url.as_ref())
.parse(self).map_err(|s| {
failure::format_err!("invalid url `{}`: {}", self, s)
})
.parse(self)
.map_err(|s| failure::format_err!("invalid url `{}`: {}", self, s))
}
}

Expand All @@ -33,13 +32,19 @@ mod tests {

#[test]
fn to_url_with_base() {
assert_eq!("rel/path".to_url_with_base(Some("file:///abs/path/"))
.unwrap()
.to_string(),
"file:///abs/path/rel/path");
assert_eq!("rel/path".to_url_with_base(Some("file:///abs/path/popped-file"))
.unwrap()
.to_string(),
"file:///abs/path/rel/path");
assert_eq!(
"rel/path"
.to_url_with_base(Some("file:///abs/path/"))
.unwrap()
.to_string(),
"file:///abs/path/rel/path"
);
assert_eq!(
"rel/path"
.to_url_with_base(Some("file:///abs/path/popped-file"))
.unwrap()
.to_string(),
"file:///abs/path/rel/path"
);
}
}
2 changes: 1 addition & 1 deletion src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ pub struct DetailedTomlDependency {
#[serde(rename = "default_features")]
default_features2: Option<bool>,
package: Option<String>,
public: Option<bool>
public: Option<bool>,
}

#[derive(Debug, Deserialize, Serialize)]
Expand Down
Loading

0 comments on commit ba5aac5

Please sign in to comment.