-
-
Notifications
You must be signed in to change notification settings - Fork 431
Closed
Labels
acknowledgedan issue is accepted as shortcoming to be fixedan issue is accepted as shortcoming to be fixedhelp wantedExtra attention is neededExtra attention is needed
Description
Current behavior 😯
Trying to filter tags in a separate function fails currently as the lifetime is too short:
fn latest_tag(repo: &gix::Repository) -> gix::Reference {
let refs = repo.references().unwrap();
refs.tags() // .tags() borrows from `refs` and thus this fails to compile
.unwrap()
.filter_map(|tag| tag.ok())
.map(|tag| (tag, semver::Version::parse(tag.name().shorten().to_str().unwrap())))
.max_by_key(|(_tag, version)| version.clone())
.map(|(tag, _version)| tag)
}Expected behavior 🤔
.tags() should instead borrow from repo and successfully compile.
I believe the issue is here:
gitoxide/gix/src/reference/iter.rs
Lines 58 to 60 in 202bc6d
| pub fn tags(&self) -> Result<Iter<'_>, init::Error> { | |
| Ok(Iter::new(self.repo, self.platform.prefixed(b"refs/tags/".try_into()?)?)) | |
| } |
tags should return Result<Iter<'repo>, init::Error> instead as otherwise it borrows from &self.
If this is desirable, I would be willing to contribute the fix (for tags and also the surrounding functions that look to have the same issue).
Git behavior
Not applicable
Steps to reproduce 🕹
Try to compile the following code:
# Cargo.toml
[package]
name = "gix-describe"
version = "0.1.0"
edition = "2024"
[dependencies]
gix = { version = "0.73.0", default-features = false, features = ["max-performance", "basic", "status"] }
semver = "1.0.26"// src/main.rs
fn latest_tag(repo: &gix::Repository) -> gix::Reference {
let refs = repo.references().unwrap();
refs.tags() // .tags() borrows from `refs` and thus this fails to compile
.unwrap()
.filter_map(|tag| tag.ok())
.map(|tag| (tag, semver::Version::parse(tag.name().shorten().to_str().unwrap())))
.max_by_key(|(_tag, version)| version.clone())
.map(|(tag, _version)| tag)
}
fn main() {}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
acknowledgedan issue is accepted as shortcoming to be fixedan issue is accepted as shortcoming to be fixedhelp wantedExtra attention is neededExtra attention is needed