Skip to content

Commit 1795a03

Browse files
committed
Cleanup some trait impls for SourceId
1 parent 6459852 commit 1795a03

File tree

1 file changed

+11
-36
lines changed

1 file changed

+11
-36
lines changed

src/cargo/core/source/source_id.rs

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -395,46 +395,25 @@ fn url_display(url: &Url) -> String {
395395

396396
impl fmt::Display for SourceId {
397397
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
398-
match *self.inner {
399-
SourceIdInner {
400-
kind: Kind::Path,
401-
ref url,
402-
..
403-
} => write!(f, "{}", url_display(url)),
404-
SourceIdInner {
405-
kind: Kind::Git(ref reference),
406-
ref url,
407-
ref precise,
408-
..
409-
} => {
398+
match self.inner.kind {
399+
Kind::Git(ref reference) => {
410400
// Don't replace the URL display for git references,
411401
// because those are kind of expected to be URLs.
412-
write!(f, "{}", url)?;
402+
write!(f, "{}", self.inner.url)?;
413403
if let Some(pretty) = reference.pretty_ref() {
414404
write!(f, "?{}", pretty)?;
415405
}
416406

417-
if let Some(ref s) = *precise {
407+
if let Some(ref s) = self.inner.precise {
418408
let len = cmp::min(s.len(), 8);
419409
write!(f, "#{}", &s[..len])?;
420410
}
421411
Ok(())
422412
}
423-
SourceIdInner {
424-
kind: Kind::Registry,
425-
ref url,
426-
..
427-
}
428-
| SourceIdInner {
429-
kind: Kind::LocalRegistry,
430-
ref url,
431-
..
432-
} => write!(f, "registry `{}`", url_display(url)),
433-
SourceIdInner {
434-
kind: Kind::Directory,
435-
ref url,
436-
..
437-
} => write!(f, "dir {}", url_display(url)),
413+
Kind::Path => write!(f, "{}", url_display(&self.inner.url)),
414+
Kind::Registry => write!(f, "registry `{}`", url_display(&self.inner.url)),
415+
Kind::LocalRegistry => write!(f, "registry `{}`", url_display(&self.inner.url)),
416+
Kind::Directory => write!(f, "dir {}", url_display(&self.inner.url)),
438417
}
439418
}
440419
}
@@ -479,7 +458,7 @@ impl Ord for SourceIdInner {
479458
ord => return ord,
480459
}
481460
match (&self.kind, &other.kind) {
482-
(&Kind::Git(ref ref1), &Kind::Git(ref ref2)) => {
461+
(Kind::Git(ref1), Kind::Git(ref2)) => {
483462
(ref1, &self.canonical_url).cmp(&(ref2, &other.canonical_url))
484463
}
485464
_ => self.kind.cmp(&other.kind),
@@ -493,12 +472,8 @@ impl Ord for SourceIdInner {
493472
impl Hash for SourceId {
494473
fn hash<S: hash::Hasher>(&self, into: &mut S) {
495474
self.inner.kind.hash(into);
496-
match *self.inner {
497-
SourceIdInner {
498-
kind: Kind::Git(..),
499-
ref canonical_url,
500-
..
501-
} => canonical_url.as_str().hash(into),
475+
match self.inner.kind {
476+
Kind::Git(_) => self.inner.canonical_url.as_str().hash(into),
502477
_ => self.inner.url.as_str().hash(into),
503478
}
504479
}

0 commit comments

Comments
 (0)