Skip to content

Commit eebd1da

Browse files
committed
Auto merge of #7048 - jeremystucki:into_url, r=Eh2406
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)
2 parents 92427df + 2415a29 commit eebd1da

File tree

18 files changed

+77
-77
lines changed

18 files changed

+77
-77
lines changed

crates/resolver-tests/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use cargo::core::resolver::{self, Method};
99
use cargo::core::source::{GitReference, SourceId};
1010
use cargo::core::Resolve;
1111
use cargo::core::{Dependency, PackageId, Registry, Summary};
12-
use cargo::util::{CargoResult, Config, Graph, ToUrl};
12+
use cargo::util::{CargoResult, Config, Graph, IntoUrl};
1313

1414
use proptest::collection::{btree_map, vec};
1515
use proptest::prelude::*;
@@ -504,7 +504,7 @@ macro_rules! pkg {
504504
fn registry_loc() -> SourceId {
505505
lazy_static::lazy_static! {
506506
static ref EXAMPLE_DOT_COM: SourceId =
507-
SourceId::for_registry(&"https://example.com".to_url().unwrap()).unwrap();
507+
SourceId::for_registry(&"https://example.com".into_url().unwrap()).unwrap();
508508
}
509509
*EXAMPLE_DOT_COM
510510
}
@@ -535,7 +535,7 @@ pub fn pkg_id(name: &str) -> PackageId {
535535
}
536536

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

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

588588
pub fn dep_loc(name: &str, location: &str) -> Dependency {
589-
let url = location.to_url().unwrap();
589+
let url = location.into_url().unwrap();
590590
let master = GitReference::Branch("master".to_string());
591591
let source_id = SourceId::for_git(&url, master).unwrap();
592592
Dependency::parse_no_deprecated(name, Some("1.0.0"), source_id).unwrap()

src/bin/cargo/commands/git_checkout.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::command_prelude::*;
22

33
use cargo::core::{GitReference, Source, SourceId};
44
use cargo::sources::GitSource;
5-
use cargo::util::ToUrl;
5+
use cargo::util::IntoUrl;
66

77
pub fn cli() -> App {
88
subcommand("git-checkout")
@@ -23,7 +23,7 @@ pub fn cli() -> App {
2323
}
2424

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

2929
let reference = GitReference::Branch(reference.to_string());

src/bin/cargo/commands/install.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::command_prelude::*;
22

33
use cargo::core::{GitReference, SourceId};
44
use cargo::ops;
5-
use cargo::util::ToUrl;
5+
use cargo::util::IntoUrl;
66

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

129129
let source = if let Some(url) = args.value_of("git") {
130-
let url = url.to_url()?;
130+
let url = url.into_url()?;
131131
let gitref = if let Some(branch) = args.value_of("branch") {
132132
GitReference::Branch(branch.to_string())
133133
} else if let Some(tag) = args.value_of("tag") {

src/cargo/core/package_id.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl ser::Serialize for PackageId {
5959
"{} {} ({})",
6060
self.inner.name,
6161
self.inner.version,
62-
self.inner.source_id.to_url()
62+
self.inner.source_id.into_url()
6363
))
6464
}
6565
}
@@ -205,11 +205,11 @@ mod tests {
205205
use super::PackageId;
206206
use crate::core::source::SourceId;
207207
use crate::sources::CRATES_IO_INDEX;
208-
use crate::util::ToUrl;
208+
use crate::util::IntoUrl;
209209

210210
#[test]
211211
fn invalid_version_handled_nicely() {
212-
let loc = CRATES_IO_INDEX.to_url().unwrap();
212+
let loc = CRATES_IO_INDEX.into_url().unwrap();
213213
let repo = SourceId::for_registry(&loc).unwrap();
214214

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

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

@@ -254,7 +254,7 @@ PackageId {
254254

255255
#[test]
256256
fn display() {
257-
let loc = CRATES_IO_INDEX.to_url().unwrap();
257+
let loc = CRATES_IO_INDEX.into_url().unwrap();
258258
let pkg_id = PackageId::new("foo", "1.0.0", SourceId::for_registry(&loc).unwrap()).unwrap();
259259
assert_eq!("foo v1.0.0", pkg_id.to_string());
260260
}

src/cargo/core/package_id_spec.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use url::Url;
88
use crate::core::interning::InternedString;
99
use crate::core::PackageId;
1010
use crate::util::errors::{CargoResult, CargoResultExt};
11-
use crate::util::{validate_package_name, ToSemver, ToUrl};
11+
use crate::util::{validate_package_name, IntoUrl, ToSemver};
1212

1313
/// Some or all of the data required to identify a package:
1414
///
@@ -50,7 +50,7 @@ impl PackageIdSpec {
5050
/// }
5151
pub fn parse(spec: &str) -> CargoResult<PackageIdSpec> {
5252
if spec.contains('/') {
53-
if let Ok(url) = spec.to_url() {
53+
if let Ok(url) = spec.into_url() {
5454
return PackageIdSpec::from_url(url);
5555
}
5656
if !spec.contains("://") {

src/cargo/core/resolver/encode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ impl fmt::Display for EncodablePackageId {
269269
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
270270
write!(f, "{} {}", self.name, self.version)?;
271271
if let Some(ref s) = self.source {
272-
write!(f, " ({})", s.to_url())?;
272+
write!(f, " ({})", s.into_url())?;
273273
}
274274
Ok(())
275275
}

src/cargo/core/source/source_id.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::ops;
1818
use crate::sources::git;
1919
use crate::sources::DirectorySource;
2020
use crate::sources::{GitSource, PathSource, RegistrySource, CRATES_IO_INDEX};
21-
use crate::util::{CargoResult, Config, ToUrl};
21+
use crate::util::{CargoResult, Config, IntoUrl};
2222

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

118118
match kind {
119119
"git" => {
120-
let mut url = url.to_url()?;
120+
let mut url = url.into_url()?;
121121
let mut reference = GitReference::Branch("master".to_string());
122122
for (k, v) in url.query_pairs() {
123123
match &k[..] {
@@ -135,11 +135,11 @@ impl SourceId {
135135
Ok(SourceId::for_git(&url, reference)?.with_precise(precise))
136136
}
137137
"registry" => {
138-
let url = url.to_url()?;
138+
let url = url.into_url()?;
139139
Ok(SourceId::new(Kind::Registry, url)?.with_precise(Some("locked".to_string())))
140140
}
141141
"path" => {
142-
let url = url.to_url()?;
142+
let url = url.into_url()?;
143143
SourceId::new(Kind::Path, url)
144144
}
145145
kind => Err(failure::format_err!(
@@ -150,8 +150,8 @@ impl SourceId {
150150
}
151151

152152
/// A view of the `SourceId` that can be `Display`ed as a URL.
153-
pub fn to_url(&self) -> SourceIdToUrl<'_> {
154-
SourceIdToUrl {
153+
pub fn into_url(&self) -> SourceIdIntoUrl<'_> {
154+
SourceIdIntoUrl {
155155
inner: &*self.inner,
156156
}
157157
}
@@ -160,7 +160,7 @@ impl SourceId {
160160
///
161161
/// `path`: an absolute path.
162162
pub fn for_path(path: &Path) -> CargoResult<SourceId> {
163-
let url = path.to_url()?;
163+
let url = path.into_url()?;
164164
SourceId::new(Kind::Path, url)
165165
}
166166

@@ -176,13 +176,13 @@ impl SourceId {
176176

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

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

@@ -207,7 +207,7 @@ impl SourceId {
207207
} else {
208208
CRATES_IO_INDEX
209209
};
210-
let url = url.to_url()?;
210+
let url = url.into_url()?;
211211
SourceId::for_registry(&url)
212212
})
213213
}
@@ -390,7 +390,7 @@ impl ser::Serialize for SourceId {
390390
if self.is_path() {
391391
None::<String>.serialize(s)
392392
} else {
393-
s.collect_str(&self.to_url())
393+
s.collect_str(&self.into_url())
394394
}
395395
}
396396
}
@@ -504,11 +504,11 @@ impl Hash for SourceId {
504504
}
505505

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

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

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

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

593593
assert_eq!(s1, s2);

src/cargo/ops/registry.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::sources::{RegistrySource, SourceConfigMap, CRATES_IO_REGISTRY};
2121
use crate::util::config::{self, Config};
2222
use crate::util::errors::{CargoResult, CargoResultExt};
2323
use crate::util::important_paths::find_root_manifest_for_wd;
24-
use crate::util::ToUrl;
24+
use crate::util::IntoUrl;
2525
use crate::util::{paths, validate_package_name};
2626
use crate::version;
2727

@@ -696,7 +696,7 @@ fn get_source_id(
696696
) -> CargoResult<SourceId> {
697697
match (reg, index) {
698698
(Some(r), _) => SourceId::alt_registry(config, &r),
699-
(_, Some(i)) => SourceId::for_registry(&i.to_url()?),
699+
(_, Some(i)) => SourceId::for_registry(&i.into_url()?),
700700
_ => {
701701
let map = SourceConfigMap::new(config)?;
702702
let src = map.load(SourceId::crates_io(config)?, &HashSet::new())?;

src/cargo/sources/config.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::core::{GitReference, PackageId, Source, SourceId};
1414
use crate::sources::{ReplacedSource, CRATES_IO_REGISTRY};
1515
use crate::util::config::ConfigValue;
1616
use crate::util::errors::{CargoResult, CargoResultExt};
17-
use crate::util::{Config, ToUrl};
17+
use crate::util::{Config, IntoUrl};
1818

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

243243
fn url(cfg: &ConfigValue, key: &str) -> CargoResult<Url> {
244244
let (url, path) = cfg.string(key)?;
245-
let url = url.to_url().chain_err(|| {
245+
let url = url.into_url().chain_err(|| {
246246
format!(
247247
"configuration key `{}` specified an invalid \
248248
URL (in {})",

src/cargo/sources/git/source.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl<'cfg> Source for GitSource<'cfg> {
241241
#[cfg(test)]
242242
mod test {
243243
use super::ident;
244-
use crate::util::ToUrl;
244+
use crate::util::IntoUrl;
245245
use url::Url;
246246

247247
#[test]
@@ -291,6 +291,6 @@ mod test {
291291
}
292292

293293
fn url(s: &str) -> Url {
294-
s.to_url().unwrap()
294+
s.into_url().unwrap()
295295
}
296296
}

src/cargo/sources/git/utils.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::core::GitReference;
1616
use crate::util::errors::{CargoResult, CargoResultExt};
1717
use crate::util::paths;
1818
use crate::util::process_builder::process;
19-
use crate::util::{internal, network, Config, Progress, ToUrl};
19+
use crate::util::{internal, network, Config, IntoUrl, Progress};
2020

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

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

397397
// Fetch data from origin and reset to the head commit
398398
let refspec = "refs/heads/*:refs/heads/*";
399-
let url = url.to_url()?;
399+
let url = url.into_url()?;
400400
fetch(&mut repo, &url, refspec, cargo_config).chain_err(|| {
401401
internal(format!(
402402
"failed to fetch submodule `{}` from {}",

src/cargo/sources/registry/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ use crate::core::{InternedString, Package, PackageId, Source, SourceId, Summary}
177177
use crate::sources::PathSource;
178178
use crate::util::errors::CargoResultExt;
179179
use crate::util::hex;
180-
use crate::util::to_url::ToUrl;
180+
use crate::util::into_url::IntoUrl;
181181
use crate::util::{internal, CargoResult, Config, Filesystem};
182182

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

306306
let id = if let Some(registry) = &registry {
307-
SourceId::for_registry(&registry.to_url()?)?
307+
SourceId::for_registry(&registry.into_url()?)?
308308
} else {
309309
default
310310
};

src/cargo/util/config.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::util::toml as cargo_toml;
3030
use crate::util::Filesystem;
3131
use crate::util::Rustc;
3232
use crate::util::{paths, validate_package_name, FileLock};
33-
use crate::util::{ToUrl, ToUrlWithBase};
33+
use crate::util::{IntoUrl, IntoUrlWithBase};
3434

3535
/// Configuration information for cargo. This is not specific to a build, it is information
3636
/// relating to cargo itself.
@@ -714,8 +714,8 @@ impl Config {
714714
.root(self)
715715
.join("truncated-by-url_with_base");
716716
// Parse val to check it is a URL, not a relative path without a protocol.
717-
let _parsed = index.val.to_url()?;
718-
let url = index.val.to_url_with_base(Some(&*base))?;
717+
let _parsed = index.val.into_url()?;
718+
let url = index.val.into_url_with_base(Some(&*base))?;
719719
if url.password().is_some() {
720720
failure::bail!("Registry URLs may not contain passwords");
721721
}

0 commit comments

Comments
 (0)