Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dont call wrap in a no-op source_id::with* #14318

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions src/cargo/core/source_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,34 +468,33 @@ impl SourceId {

/// Creates a new `SourceId` from this source with the given `precise`.
pub fn with_git_precise(self, fragment: Option<String>) -> SourceId {
SourceId::wrap(SourceIdInner {
precise: fragment.map(|f| Precise::GitUrlFragment(f)),
..(*self.inner).clone()
})
self.with_precise(&fragment.map(|f| Precise::GitUrlFragment(f)))
}

/// Creates a new `SourceId` from this source without a `precise`.
pub fn without_precise(self) -> SourceId {
SourceId::wrap(SourceIdInner {
precise: None,
..(*self.inner).clone()
})
self.with_precise(&None)
}

/// Creates a new `SourceId` from this source without a `precise`.
pub fn with_locked_precise(self) -> SourceId {
SourceId::wrap(SourceIdInner {
precise: Some(Precise::Locked),
..(*self.inner).clone()
})
self.with_precise(&Some(Precise::Locked))
}

/// Creates a new `SourceId` from this source with the `precise` from some other `SourceId`.
pub fn with_precise_from(self, v: Self) -> SourceId {
SourceId::wrap(SourceIdInner {
precise: v.inner.precise.clone(),
..(*self.inner).clone()
})
self.with_precise(&v.inner.precise)
}

fn with_precise(self, precise: &Option<Precise>) -> SourceId {
if &self.inner.precise == precise {
self
} else {
SourceId::wrap(SourceIdInner {
precise: precise.clone(),
..(*self.inner).clone()
})
}
}

/// When updating a lock file on a version using `cargo update --precise`
Expand Down