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

fix: Limiting pre-release match semantics to use only on OptVersionReq::Req #14412

Merged
merged 2 commits into from
Aug 20, 2024

Conversation

linyihai
Copy link
Contributor

@linyihai linyihai commented Aug 16, 2024

What does this PR try to resolve?

The prerelease matches semantics should be only used on OptVersionReq::Req, but it dosn't. The other OptVersionReq types have specify matches logic already, for example a OptVersionReq::Precise will failed on matches_prerelease, see #14140 (comment)

How should we test and review this PR?

the first commit added the test, the second commit updated the test and fixed the issue.

Additional information

@rustbot
Copy link
Collaborator

rustbot commented Aug 16, 2024

r? @weihanglo

rustbot has assigned @weihanglo.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-semver Area: semver specifications, version matching, etc. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 16, 2024
src/cargo/util/semver_ext.rs Outdated Show resolved Hide resolved
src/cargo/util/semver_ext.rs Outdated Show resolved Hide resolved
@epage
Copy link
Contributor

epage commented Aug 16, 2024

matches_prerelease should be only used on OptVersionReq::Req, but it dosn't.

Can you explain why?

@linyihai
Copy link
Contributor Author

Thanks your swift review and forgive my typos.

matches_prerelease should be only used on OptVersionReq::Req, but it dosn't.

The currrent approach of matches_prerelease ignores the Prerelease tag, which will allows updating to any semver-compatible pre-rerelease version. (This approach is temporray).

But the OptVersionReq::Locked and OptVersionReq::Precise involve the Prerelease tag to match, they will fail in match if the VersiongReq is pre-release.

The current use of this function is OptVersionReq::Req,

let mut req = dep.version_req().clone();
// Handle `cargo update --precise` here.
if let Some((_, requested)) = self
.source_id
.precise_registry_version(dep.package_name().as_str())
.filter(|(c, to)| {
if to.is_prerelease() && self.gctx.cli_unstable().unstable_options {
req.matches_prerelease(c)
} else {
req.matches(c)
}
})
{
req.precise_to(&requested);
}

let mut precise_yanked_in_use = false;
ready!(self
.index
.query_inner(dep.package_name(), &req, &mut *self.ops, &mut |s| {
let matched = match kind {
QueryKind::Exact => {
if req.is_precise() && self.gctx.cli_unstable().unstable_options {
dep.matches_prerelease(s.as_summary())
} else {
dep.matches(s.as_summary())
}
}
QueryKind::Alternatives => true,
QueryKind::Normalized => true,
};

so it's safe to limit its usage

@epage
Copy link
Contributor

epage commented Aug 19, 2024

But the OptVersionReq::Locked and OptVersionReq::Precise involve the Prerelease tag to match, they will fail in match if the VersiongReq is pre-release.

I think #14305 makes this a bit more clear. We are trying to emulate a proposed matches_prelease, so we should be modifying the behavior of matches. With where this was placed, we accidentally expanded the scope out further and applied it to Precise and Locked which the current hack is incompatible with and the semantics of those operations are for version equality and not version requirement matching.

src/cargo/util/semver_ext.rs Outdated Show resolved Hide resolved
@linyihai linyihai changed the title fix: matches_prerelease should be only used on OptVersionReq::Req fix: Limiting pre-release match semantics to use only on OptVersionReq::Req Aug 20, 2024
@epage
Copy link
Contributor

epage commented Aug 20, 2024

@bors r+

@bors
Copy link
Contributor

bors commented Aug 20, 2024

📌 Commit 3a1bb8b has been approved by epage

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 20, 2024
@bors
Copy link
Contributor

bors commented Aug 20, 2024

⌛ Testing commit 3a1bb8b with merge 1f4ef10...

@bors
Copy link
Contributor

bors commented Aug 20, 2024

☀️ Test successful - checks-actions
Approved by: epage
Pushing 1f4ef10 to master...

@bors bors merged commit 1f4ef10 into rust-lang:master Aug 20, 2024
22 checks passed
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 22, 2024
Update cargo

12 commits in ba8b39413c74d08494f94a7542fe79aa636e1661..8f40fc59fb0c8df91c97405785197f3c630304ea
2024-08-16 22:48:57 +0000 to 2024-08-21 22:37:06 +0000
- Tests rely on absence of RUST_BACKTRACE (rust-lang/cargo#14441)
- fix: -Cmetadata includes whether extra rustflags is same as host (rust-lang/cargo#14432)
- [mdman] Normalize newlines when rendering options (rust-lang/cargo#14428)
- fix: doctest respects Cargo's color options (rust-lang/cargo#14425)
- Be more permissive while packaging unpublishable crates. (rust-lang/cargo#14408)
- fix: Limiting pre-release match semantics to use only on `OptVersionReq::Req` (rust-lang/cargo#14412)
- test: add a regression test for Issue 14409 (rust-lang/cargo#14430)
- chore: update label trigger for Command-info (rust-lang/cargo#14422)
- doc: add lockfile-path unstable doc section (rust-lang/cargo#14423)
- doc: update lockfile-path tracking issue (rust-lang/cargo#14424)
- fix: remove list owners feature of info subcommand (rust-lang/cargo#14418)
- Lockfile path tests (follow-up) (rust-lang/cargo#14417)
@rustbot rustbot added this to the 1.82.0 milestone Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-semver Area: semver specifications, version matching, etc. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants