Skip to content

Commit

Permalink
Auto merge of #7048 - jeremystucki:into_url, r=Eh2406
Browse files Browse the repository at this point in the history
Rename to_url → into_url

I think it should be `into_url` as it consumes itself.

[Relevant clippy lint](https://rust-lang.github.io/rust-clippy/master/index.html#wrong_self_convention)
  • Loading branch information
bors committed Jun 20, 2019
2 parents 92427df + 2415a29 commit eebd1da
Show file tree
Hide file tree
Showing 18 changed files with 77 additions and 77 deletions.
8 changes: 4 additions & 4 deletions crates/resolver-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use cargo::core::resolver::{self, Method};
use cargo::core::source::{GitReference, SourceId};
use cargo::core::Resolve;
use cargo::core::{Dependency, PackageId, Registry, Summary};
use cargo::util::{CargoResult, Config, Graph, ToUrl};
use cargo::util::{CargoResult, Config, Graph, IntoUrl};

use proptest::collection::{btree_map, vec};
use proptest::prelude::*;
Expand Down Expand Up @@ -504,7 +504,7 @@ macro_rules! pkg {
fn registry_loc() -> SourceId {
lazy_static::lazy_static! {
static ref EXAMPLE_DOT_COM: SourceId =
SourceId::for_registry(&"https://example.com".to_url().unwrap()).unwrap();
SourceId::for_registry(&"https://example.com".into_url().unwrap()).unwrap();
}
*EXAMPLE_DOT_COM
}
Expand Down Expand Up @@ -535,7 +535,7 @@ pub fn pkg_id(name: &str) -> PackageId {
}

fn pkg_id_loc(name: &str, loc: &str) -> PackageId {
let remote = loc.to_url();
let remote = loc.into_url();
let master = GitReference::Branch("master".to_string());
let source_id = SourceId::for_git(&remote.unwrap(), master).unwrap();

Expand Down Expand Up @@ -586,7 +586,7 @@ pub fn dep_req_kind(name: &str, req: &str, kind: Kind, public: bool) -> Dependen
}

pub fn dep_loc(name: &str, location: &str) -> Dependency {
let url = location.to_url().unwrap();
let url = location.into_url().unwrap();
let master = GitReference::Branch("master".to_string());
let source_id = SourceId::for_git(&url, master).unwrap();
Dependency::parse_no_deprecated(name, Some("1.0.0"), source_id).unwrap()
Expand Down
4 changes: 2 additions & 2 deletions src/bin/cargo/commands/git_checkout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::command_prelude::*;

use cargo::core::{GitReference, Source, SourceId};
use cargo::sources::GitSource;
use cargo::util::ToUrl;
use cargo::util::IntoUrl;

pub fn cli() -> App {
subcommand("git-checkout")
Expand All @@ -23,7 +23,7 @@ pub fn cli() -> App {
}

pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
let url = args.value_of("url").unwrap().to_url()?;
let url = args.value_of("url").unwrap().into_url()?;
let reference = args.value_of("reference").unwrap();

let reference = GitReference::Branch(reference.to_string());
Expand Down
4 changes: 2 additions & 2 deletions src/bin/cargo/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::command_prelude::*;

use cargo::core::{GitReference, SourceId};
use cargo::ops;
use cargo::util::ToUrl;
use cargo::util::IntoUrl;

pub fn cli() -> App {
subcommand("install")
Expand Down Expand Up @@ -127,7 +127,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
let mut from_cwd = false;

let source = if let Some(url) = args.value_of("git") {
let url = url.to_url()?;
let url = url.into_url()?;
let gitref = if let Some(branch) = args.value_of("branch") {
GitReference::Branch(branch.to_string())
} else if let Some(tag) = args.value_of("tag") {
Expand Down
10 changes: 5 additions & 5 deletions src/cargo/core/package_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl ser::Serialize for PackageId {
"{} {} ({})",
self.inner.name,
self.inner.version,
self.inner.source_id.to_url()
self.inner.source_id.into_url()
))
}
}
Expand Down Expand Up @@ -205,11 +205,11 @@ mod tests {
use super::PackageId;
use crate::core::source::SourceId;
use crate::sources::CRATES_IO_INDEX;
use crate::util::ToUrl;
use crate::util::IntoUrl;

#[test]
fn invalid_version_handled_nicely() {
let loc = CRATES_IO_INDEX.to_url().unwrap();
let loc = CRATES_IO_INDEX.into_url().unwrap();
let repo = SourceId::for_registry(&loc).unwrap();

assert!(PackageId::new("foo", "1.0", repo).is_err());
Expand All @@ -220,7 +220,7 @@ mod tests {

#[test]
fn debug() {
let loc = CRATES_IO_INDEX.to_url().unwrap();
let loc = CRATES_IO_INDEX.into_url().unwrap();
let pkg_id = PackageId::new("foo", "1.0.0", SourceId::for_registry(&loc).unwrap()).unwrap();
assert_eq!(r#"PackageId { name: "foo", version: "1.0.0", source: "registry `https://github.com/rust-lang/crates.io-index`" }"#, format!("{:?}", pkg_id));

Expand Down Expand Up @@ -254,7 +254,7 @@ PackageId {

#[test]
fn display() {
let loc = CRATES_IO_INDEX.to_url().unwrap();
let loc = CRATES_IO_INDEX.into_url().unwrap();
let pkg_id = PackageId::new("foo", "1.0.0", SourceId::for_registry(&loc).unwrap()).unwrap();
assert_eq!("foo v1.0.0", pkg_id.to_string());
}
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/package_id_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use url::Url;
use crate::core::interning::InternedString;
use crate::core::PackageId;
use crate::util::errors::{CargoResult, CargoResultExt};
use crate::util::{validate_package_name, ToSemver, ToUrl};
use crate::util::{validate_package_name, IntoUrl, ToSemver};

/// Some or all of the data required to identify a package:
///
Expand Down Expand Up @@ -50,7 +50,7 @@ impl PackageIdSpec {
/// }
pub fn parse(spec: &str) -> CargoResult<PackageIdSpec> {
if spec.contains('/') {
if let Ok(url) = spec.to_url() {
if let Ok(url) = spec.into_url() {
return PackageIdSpec::from_url(url);
}
if !spec.contains("://") {
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/resolver/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ impl fmt::Display for EncodablePackageId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{} {}", self.name, self.version)?;
if let Some(ref s) = self.source {
write!(f, " ({})", s.to_url())?;
write!(f, " ({})", s.into_url())?;
}
Ok(())
}
Expand Down
32 changes: 16 additions & 16 deletions src/cargo/core/source/source_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::ops;
use crate::sources::git;
use crate::sources::DirectorySource;
use crate::sources::{GitSource, PathSource, RegistrySource, CRATES_IO_INDEX};
use crate::util::{CargoResult, Config, ToUrl};
use crate::util::{CargoResult, Config, IntoUrl};

lazy_static::lazy_static! {
static ref SOURCE_ID_CACHE: Mutex<HashSet<&'static SourceIdInner>> = Mutex::new(HashSet::new());
Expand Down Expand Up @@ -117,7 +117,7 @@ impl SourceId {

match kind {
"git" => {
let mut url = url.to_url()?;
let mut url = url.into_url()?;
let mut reference = GitReference::Branch("master".to_string());
for (k, v) in url.query_pairs() {
match &k[..] {
Expand All @@ -135,11 +135,11 @@ impl SourceId {
Ok(SourceId::for_git(&url, reference)?.with_precise(precise))
}
"registry" => {
let url = url.to_url()?;
let url = url.into_url()?;
Ok(SourceId::new(Kind::Registry, url)?.with_precise(Some("locked".to_string())))
}
"path" => {
let url = url.to_url()?;
let url = url.into_url()?;
SourceId::new(Kind::Path, url)
}
kind => Err(failure::format_err!(
Expand All @@ -150,8 +150,8 @@ impl SourceId {
}

/// A view of the `SourceId` that can be `Display`ed as a URL.
pub fn to_url(&self) -> SourceIdToUrl<'_> {
SourceIdToUrl {
pub fn into_url(&self) -> SourceIdIntoUrl<'_> {
SourceIdIntoUrl {
inner: &*self.inner,
}
}
Expand All @@ -160,7 +160,7 @@ impl SourceId {
///
/// `path`: an absolute path.
pub fn for_path(path: &Path) -> CargoResult<SourceId> {
let url = path.to_url()?;
let url = path.into_url()?;
SourceId::new(Kind::Path, url)
}

Expand All @@ -176,13 +176,13 @@ impl SourceId {

/// Creates a SourceId from a local registry path.
pub fn for_local_registry(path: &Path) -> CargoResult<SourceId> {
let url = path.to_url()?;
let url = path.into_url()?;
SourceId::new(Kind::LocalRegistry, url)
}

/// Creates a `SourceId` from a directory path.
pub fn for_directory(path: &Path) -> CargoResult<SourceId> {
let url = path.to_url()?;
let url = path.into_url()?;
SourceId::new(Kind::Directory, url)
}

Expand All @@ -207,7 +207,7 @@ impl SourceId {
} else {
CRATES_IO_INDEX
};
let url = url.to_url()?;
let url = url.into_url()?;
SourceId::for_registry(&url)
})
}
Expand Down Expand Up @@ -390,7 +390,7 @@ impl ser::Serialize for SourceId {
if self.is_path() {
None::<String>.serialize(s)
} else {
s.collect_str(&self.to_url())
s.collect_str(&self.into_url())
}
}
}
Expand Down Expand Up @@ -504,11 +504,11 @@ impl Hash for SourceId {
}

/// A `Display`able view into a `SourceId` that will write it as a url
pub struct SourceIdToUrl<'a> {
pub struct SourceIdIntoUrl<'a> {
inner: &'a SourceIdInner,
}

impl<'a> fmt::Display for SourceIdToUrl<'a> {
impl<'a> fmt::Display for SourceIdIntoUrl<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self.inner {
SourceIdInner {
Expand Down Expand Up @@ -579,15 +579,15 @@ impl<'a> fmt::Display for PrettyRef<'a> {
#[cfg(test)]
mod tests {
use super::{GitReference, Kind, SourceId};
use crate::util::ToUrl;
use crate::util::IntoUrl;

#[test]
fn github_sources_equal() {
let loc = "https://github.com/foo/bar".to_url().unwrap();
let loc = "https://github.com/foo/bar".into_url().unwrap();
let master = Kind::Git(GitReference::Branch("master".to_string()));
let s1 = SourceId::new(master.clone(), loc).unwrap();

let loc = "git://github.com/foo/bar".to_url().unwrap();
let loc = "git://github.com/foo/bar".into_url().unwrap();
let s2 = SourceId::new(master, loc.clone()).unwrap();

assert_eq!(s1, s2);
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/ops/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::sources::{RegistrySource, SourceConfigMap, CRATES_IO_REGISTRY};
use crate::util::config::{self, Config};
use crate::util::errors::{CargoResult, CargoResultExt};
use crate::util::important_paths::find_root_manifest_for_wd;
use crate::util::ToUrl;
use crate::util::IntoUrl;
use crate::util::{paths, validate_package_name};
use crate::version;

Expand Down Expand Up @@ -696,7 +696,7 @@ fn get_source_id(
) -> CargoResult<SourceId> {
match (reg, index) {
(Some(r), _) => SourceId::alt_registry(config, &r),
(_, Some(i)) => SourceId::for_registry(&i.to_url()?),
(_, Some(i)) => SourceId::for_registry(&i.into_url()?),
_ => {
let map = SourceConfigMap::new(config)?;
let src = map.load(SourceId::crates_io(config)?, &HashSet::new())?;
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/sources/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::core::{GitReference, PackageId, Source, SourceId};
use crate::sources::{ReplacedSource, CRATES_IO_REGISTRY};
use crate::util::config::ConfigValue;
use crate::util::errors::{CargoResult, CargoResultExt};
use crate::util::{Config, ToUrl};
use crate::util::{Config, IntoUrl};

#[derive(Clone)]
pub struct SourceConfigMap<'cfg> {
Expand Down Expand Up @@ -242,7 +242,7 @@ restore the source replacement configuration to continue the build

fn url(cfg: &ConfigValue, key: &str) -> CargoResult<Url> {
let (url, path) = cfg.string(key)?;
let url = url.to_url().chain_err(|| {
let url = url.into_url().chain_err(|| {
format!(
"configuration key `{}` specified an invalid \
URL (in {})",
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/sources/git/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl<'cfg> Source for GitSource<'cfg> {
#[cfg(test)]
mod test {
use super::ident;
use crate::util::ToUrl;
use crate::util::IntoUrl;
use url::Url;

#[test]
Expand Down Expand Up @@ -291,6 +291,6 @@ mod test {
}

fn url(s: &str) -> Url {
s.to_url().unwrap()
s.into_url().unwrap()
}
}
8 changes: 4 additions & 4 deletions src/cargo/sources/git/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::core::GitReference;
use crate::util::errors::{CargoResult, CargoResultExt};
use crate::util::paths;
use crate::util::process_builder::process;
use crate::util::{internal, network, Config, Progress, ToUrl};
use crate::util::{internal, network, Config, IntoUrl, Progress};

#[derive(PartialEq, Clone, Debug)]
pub struct GitRevision(git2::Oid);
Expand Down Expand Up @@ -274,7 +274,7 @@ impl<'a> GitCheckout<'a> {
//
// Note that we still use the same fetch options because while we don't
// need authentication information we may want progress bars and such.
let url = database.path.to_url()?;
let url = database.path.into_url()?;
let mut repo = None;
with_fetch_options(&git_config, &url, config, &mut |fopts| {
let mut checkout = git2::build::CheckoutBuilder::new();
Expand Down Expand Up @@ -310,7 +310,7 @@ impl<'a> GitCheckout<'a> {

fn fetch(&mut self, cargo_config: &Config) -> CargoResult<()> {
info!("fetch {}", self.repo.path().display());
let url = self.database.path.to_url()?;
let url = self.database.path.into_url()?;
let refspec = "refs/heads/*:refs/heads/*";
fetch(&mut self.repo, &url, refspec, cargo_config)?;
Ok(())
Expand Down Expand Up @@ -396,7 +396,7 @@ impl<'a> GitCheckout<'a> {

// Fetch data from origin and reset to the head commit
let refspec = "refs/heads/*:refs/heads/*";
let url = url.to_url()?;
let url = url.into_url()?;
fetch(&mut repo, &url, refspec, cargo_config).chain_err(|| {
internal(format!(
"failed to fetch submodule `{}` from {}",
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 @@ -177,7 +177,7 @@ use crate::core::{InternedString, Package, PackageId, Source, SourceId, Summary}
use crate::sources::PathSource;
use crate::util::errors::CargoResultExt;
use crate::util::hex;
use crate::util::to_url::ToUrl;
use crate::util::into_url::IntoUrl;
use crate::util::{internal, CargoResult, Config, Filesystem};

const PACKAGE_SOURCE_LOCK: &str = ".cargo-ok";
Expand Down Expand Up @@ -304,7 +304,7 @@ impl<'a> RegistryDependency<'a> {
} = self;

let id = if let Some(registry) = &registry {
SourceId::for_registry(&registry.to_url()?)?
SourceId::for_registry(&registry.into_url()?)?
} else {
default
};
Expand Down
6 changes: 3 additions & 3 deletions src/cargo/util/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::util::toml as cargo_toml;
use crate::util::Filesystem;
use crate::util::Rustc;
use crate::util::{paths, validate_package_name, FileLock};
use crate::util::{ToUrl, ToUrlWithBase};
use crate::util::{IntoUrl, IntoUrlWithBase};

/// Configuration information for cargo. This is not specific to a build, it is information
/// relating to cargo itself.
Expand Down Expand Up @@ -714,8 +714,8 @@ impl Config {
.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))?;
let _parsed = index.val.into_url()?;
let url = index.val.into_url_with_base(Some(&*base))?;
if url.password().is_some() {
failure::bail!("Registry URLs may not contain passwords");
}
Expand Down
Loading

0 comments on commit eebd1da

Please sign in to comment.