$cargo fmt --all

This commit is contained in:
k-nasa 2019-05-02 06:39:15 +09:00
parent a6737f5fcd
commit 63a9c7aa6d
20 changed files with 140 additions and 108 deletions

View file

@ -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};

View file

@ -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)
}
}

View file

@ -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;
@ -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;
@ -984,7 +984,6 @@ fn build_deps_args<'a, 'cfg>(
cmd.arg("-Z").arg("unstable-options");
}
return Ok(());
fn link_to<'a, 'cfg>(
@ -992,7 +991,7 @@ fn build_deps_args<'a, 'cfg>(
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() {
@ -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");
}

View file

@ -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;
@ -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>>();
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();
(p.clone(), public_deps)
})
.collect();
Resolve {
graph,
@ -68,7 +77,7 @@ impl Resolve {
unused_patches,
empty_features: HashSet::new(),
reverse_replacements,
public_dependencies
public_dependencies,
}
}
@ -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))
}

View file

@ -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;

View file

@ -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!(

View file

@ -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};
@ -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

View file

@ -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)?;
@ -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),
)
}
@ -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 {
@ -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 {

View file

@ -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;

View file

@ -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> {
@ -301,7 +301,7 @@ impl<'a> RegistryDependency<'a> {
kind,
registry,
package,
public
public,
} = self;
let id = if let Some(registry) = &registry {

View file

@ -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.
@ -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>> {
@ -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))?;
@ -1663,4 +1664,3 @@ pub fn save_credentials(cfg: &Config, token: String, registry: Option<String>) -
Ok(())
}
}

View file

@ -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)

View file

@ -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))
}
}
@ -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"
);
}
}

View file

@ -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)]

View file

@ -1170,11 +1170,15 @@ fn unknown_registry() {
fn registries_index_relative_url() {
let config = paths::root().join(".cargo/config");
fs::create_dir_all(config.parent().unwrap()).unwrap();
File::create(&config).unwrap()
.write_all(br#"
File::create(&config)
.unwrap()
.write_all(
br#"
[registries.relative]
index = "file:alternative-registry"
"#).unwrap();
"#,
)
.unwrap();
registry::init();
@ -1195,9 +1199,7 @@ fn registries_index_relative_url() {
.file("src/main.rs", "fn main() {}")
.build();
Package::new("bar", "0.0.1")
.alternative(true)
.publish();
Package::new("bar", "0.0.1").alternative(true).publish();
p.cargo("build")
.with_stderr(&format!(
@ -1218,11 +1220,15 @@ fn registries_index_relative_url() {
fn registry_index_relative_url() {
let config = paths::root().join(".cargo/config");
fs::create_dir_all(config.parent().unwrap()).unwrap();
File::create(&config).unwrap()
.write_all(br#"
File::create(&config)
.unwrap()
.write_all(
br#"
[registry]
index = "file:alternative-registry"
"#).unwrap();
"#,
)
.unwrap();
registry::init();
@ -1242,9 +1248,7 @@ fn registry_index_relative_url() {
.file("src/main.rs", "fn main() {}")
.build();
Package::new("bar", "0.0.1")
.alternative(true)
.publish();
Package::new("bar", "0.0.1").alternative(true).publish();
fs::remove_file(paths::home().join(".cargo/config")).unwrap();
@ -1268,11 +1272,15 @@ warning: custom registry support via the `registry.index` configuration is being
fn registries_index_relative_path_not_allowed() {
let config = paths::root().join(".cargo/config");
fs::create_dir_all(config.parent().unwrap()).unwrap();
File::create(&config).unwrap()
.write_all(br#"
File::create(&config)
.unwrap()
.write_all(
br#"
[registries.relative]
index = "alternative-registry"
"#).unwrap();
"#,
)
.unwrap();
registry::init();
@ -1293,9 +1301,7 @@ fn registries_index_relative_path_not_allowed() {
.file("src/main.rs", "fn main() {}")
.build();
Package::new("bar", "0.0.1")
.alternative(true)
.publish();
Package::new("bar", "0.0.1").alternative(true).publish();
p.cargo("build")
.with_stderr(&format!(
@ -1304,8 +1310,9 @@ error: failed to parse manifest at `{root}/foo/Cargo.toml`
Caused by:
invalid url `alternative-registry`: relative URL without a base
"
, root = paths::root().to_str().unwrap()))
",
root = paths::root().to_str().unwrap()
))
.with_status(101)
.run();
}

View file

@ -1983,10 +1983,7 @@ fn rename_with_path_deps() {
a = { path = 'a' }
"#,
)
.file(
"src/lib.rs",
"extern crate a; pub fn foo() { a::foo(); }",
)
.file("src/lib.rs", "extern crate a; pub fn foo() { a::foo(); }")
.file(
"a/Cargo.toml",
r#"
@ -1999,10 +1996,7 @@ fn rename_with_path_deps() {
b = { path = 'b' }
"#,
)
.file(
"a/src/lib.rs",
"extern crate b; pub fn foo() { b::foo() }",
)
.file("a/src/lib.rs", "extern crate b; pub fn foo() { b::foo() }")
.file(
"a/b/Cargo.toml",
r#"
@ -2012,10 +2006,7 @@ fn rename_with_path_deps() {
authors = []
"#,
)
.file(
"a/b/src/lib.rs",
"pub fn foo() { }",
);
.file("a/b/src/lib.rs", "pub fn foo() { }");
let p = p.build();
p.cargo("build").run();

View file

@ -521,7 +521,7 @@ fn offline_resolve_optional_fail() {
// Change dep to 2.0.
p.change_file(
"Cargo.toml",
r#"
r#"
[package]
name = "foo"
version = "0.1.0"

View file

@ -160,7 +160,6 @@ consider adding `cargo-features = [\"public-dependency\"]` to the manifest
.run()
}
#[test]
fn pub_dev_dependency() {
Package::new("pub_dep", "0.1.0")

View file

@ -112,11 +112,9 @@ fn not_update() {
regsrc.update().unwrap();
cargo_process("search postgres")
.with_stdout_contains(
"hoare = \"0.1.1\" # Design by contract style assertions for Rust",
)
.with_stderr("") // without "Updating ... index"
.run();
.with_stdout_contains("hoare = \"0.1.1\" # Design by contract style assertions for Rust")
.with_stderr("") // without "Updating ... index"
.run();
}
#[test]

View file

@ -146,7 +146,9 @@ impl CargoPathExt for Path {
}
fn is_symlink(&self) -> bool {
fs::symlink_metadata(self).map(|m| m.file_type().is_symlink()).unwrap_or(false)
fs::symlink_metadata(self)
.map(|m| m.file_type().is_symlink())
.unwrap_or(false)
}
}