Skip to content

Conversation

secona
Copy link
Contributor

@secona secona commented Sep 20, 2025

What does this PR try to resolve?

Sparse registries have their IDs prefixed with their kind (sparse+). This PR fixes the current implementation of TomlLockfileSourceId where it incorrectly splits the kind and URL for sparse registries.

This change itself shouldn't affect cargo. It does, however, affect users of cargo-util-schemas, i.e. cargo plumbing commands. See crate-ci/cargo-plumbing#111

How to test and review this PR?

Verify how source IDs are made, especially their URLs.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 20, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 20, 2025

r? @ehuss

rustbot has assigned @ehuss.
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

Copy link
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Would it be possible to add some tests around this?

@secona
Copy link
Contributor Author

secona commented Sep 22, 2025

I've added some unit tests for this. Let me know if there are other changes that you'd like me to make.

Copy link
Member

@0xPoe 0xPoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
I think this change makes sense for cargo-util-schemas. This bug didn’t affect Cargo itself because we handled it when constructing the source ID.

It would be great if we could introduce an end-to-end test to verify that Cargo itself correctly handles this prefix, but I think it’s fine to add that in a separate PR.

Maybe something like:

    let _registry = registry::RegistryBuilder::new()
        .http_index()
        .alternative()
        .build();

    Package::new("two-ver", "0.1.0").alternative(true).publish();
    Package::new("two-ver", "0.2.0").alternative(true).publish();
    let p = project()
        .file(
            "Cargo.toml",
            r#"
                [package]
                name = "foo"
                version = "0.1.0"
                edition = "2018"

                [dependencies]
                two-ver = { registry = 'alternative', version = "0.1.0" }
                two-ver2 = { registry = 'alternative', package = "two-ver", version = "0.2.0" }
            "#,
        )
        .file("src/lib.rs", "")
        .file("cratesio", "")
        .build();

    p.cargo("generate-lockfile").run();
    let lockfile = p.read_lockfile();
	// TODO: check source ID URL here.
    assert_eq!("", lockfile);

@secona
Copy link
Contributor Author

secona commented Sep 23, 2025

I thought cargo already had one.

#[cargo_test]
fn sparse_lockfile() {
let _registry = registry::RegistryBuilder::new()
.http_index()
.alternative()
.build();
Package::new("foo", "0.1.0").alternative(true).publish();
let p = project()
.file(
"Cargo.toml",
r#"
[project]
name = "a"
version = "0.5.0"
authors = []
edition = "2015"
[dependencies]
foo = { registry = 'alternative', version = '0.1.0'}
"#,
)
.file("src/lib.rs", "")
.build();
p.cargo("generate-lockfile").run();
assert_e2e().eq(
&p.read_lockfile(),
str![[r##"
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "a"
version = "0.5.0"
dependencies = [
"foo",
]
[[package]]
name = "foo"
version = "0.1.0"
source = "sparse+http://127.0.0.1:[..]/index/"
checksum = "458c1addb23fde7dfbca0410afdbcc0086f96197281ec304d9e0e10def3cb899"
"##]],
);
}

That being said, this change is also a fix for the url field of TomlLockfileSourceId, which Cargo doesn't really use other than for sources ordering. The bug also doesn't affect sources ordering because we order by source kind first and then URLs. Cargo only cares about the source_str field which is used to make the SourceIds and for writing the lock file. The url field is mostly for users of cargo-util-schemas.

I don't think adding an end-to-end test is going to cover this problem.

@0xPoe
Copy link
Member

0xPoe commented Sep 23, 2025

I thought cargo already had one.

Good catch! I didn't find it last night.

I don't think adding an end-to-end test is going to cover this problem.

I am not saying it's gonna cover this issue from cargo-util-schema. That's also why we should add a test for Cargo itself in a separate PR.(The one you post in your comment)

Thank you! I think this PR is ready to go.

@0xPoe 0xPoe added this pull request to the merge queue Sep 23, 2025
Merged via the queue into rust-lang:master with commit b4cdb55 Sep 23, 2025
25 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 23, 2025
@secona secona deleted the sparse-urls branch September 23, 2025 12:49
secona added a commit to secona/cargo-plumbing that referenced this pull request Sep 23, 2025
bors added a commit to rust-lang/rust that referenced this pull request Sep 25, 2025
Update cargo submodule

17 commits in 966f94733bbc94ca51ff9f1e4c49ad250ebbdc50..f2932725b045d361ff5f18ba02b1409dd1f44e71
2025-09-16 17:24:45 +0000 to 2025-09-24 11:31:26 +0000
- fix: use `host-tuple` for host target subsitution (rust-lang/cargo#16003)
- test(build-std): move away from panic_immediate_abort  (rust-lang/cargo#16006)
- fix: Sparse URLs in `TomlLockfileSourceId` (rust-lang/cargo#15990)
- refactor(gctx): extract toml dotted keys validation (rust-lang/cargo#15998)
- feat: Add lint for global use of `hint-mostly-unused` (rust-lang/cargo#15995)
- Make GlobalContext Sync (rust-lang/cargo#15967)
- chore(deps): update cargo-semver-checks to v0.44.0 (rust-lang/cargo#15993)
- fix(frontatter): Only allow horizontal whitespace after fences (rust-lang/cargo#15975)
- docs: Add Lockfile schemas docs (rust-lang/cargo#15989)
- Add parallel frontend to the build performance guide (rust-lang/cargo#15970)
- chore(deps): update msrv (3 versions) to v1.88 (rust-lang/cargo#15988)
- chore(deps): update msrv (1 version) to v1.90 (rust-lang/cargo#15984)
- feat(cargo-util-schemas): Move lockfile schemas (rust-lang/cargo#15980)
- Clarify multiple version requirement behavior (rust-lang/cargo#15979)
- Adds ghostty as supported terminal for term integration (OSC 9;4) (rust-lang/cargo#15977)
- docs(team): Fixed broken office hours link (rust-lang/cargo#15976)
- docs: Clarify git sources vs git registries in source replacement documentation (rust-lang/cargo#15974)

r? ghost
bors added a commit to rust-lang/rust that referenced this pull request Sep 25, 2025
Update cargo submodule

17 commits in 966f94733bbc94ca51ff9f1e4c49ad250ebbdc50..f2932725b045d361ff5f18ba02b1409dd1f44e71
2025-09-16 17:24:45 +0000 to 2025-09-24 11:31:26 +0000
- fix: use `host-tuple` for host target subsitution (rust-lang/cargo#16003)
- test(build-std): move away from panic_immediate_abort  (rust-lang/cargo#16006)
- fix: Sparse URLs in `TomlLockfileSourceId` (rust-lang/cargo#15990)
- refactor(gctx): extract toml dotted keys validation (rust-lang/cargo#15998)
- feat: Add lint for global use of `hint-mostly-unused` (rust-lang/cargo#15995)
- Make GlobalContext Sync (rust-lang/cargo#15967)
- chore(deps): update cargo-semver-checks to v0.44.0 (rust-lang/cargo#15993)
- fix(frontatter): Only allow horizontal whitespace after fences (rust-lang/cargo#15975)
- docs: Add Lockfile schemas docs (rust-lang/cargo#15989)
- Add parallel frontend to the build performance guide (rust-lang/cargo#15970)
- chore(deps): update msrv (3 versions) to v1.88 (rust-lang/cargo#15988)
- chore(deps): update msrv (1 version) to v1.90 (rust-lang/cargo#15984)
- feat(cargo-util-schemas): Move lockfile schemas (rust-lang/cargo#15980)
- Clarify multiple version requirement behavior (rust-lang/cargo#15979)
- Adds ghostty as supported terminal for term integration (OSC 9;4) (rust-lang/cargo#15977)
- docs(team): Fixed broken office hours link (rust-lang/cargo#15976)
- docs: Clarify git sources vs git registries in source replacement documentation (rust-lang/cargo#15974)

r? ghost
bors added a commit to rust-lang/rust that referenced this pull request Sep 25, 2025
Update cargo submodule

17 commits in 966f94733bbc94ca51ff9f1e4c49ad250ebbdc50..f2932725b045d361ff5f18ba02b1409dd1f44e71
2025-09-16 17:24:45 +0000 to 2025-09-24 11:31:26 +0000
- fix: use `host-tuple` for host target subsitution (rust-lang/cargo#16003)
- test(build-std): move away from panic_immediate_abort  (rust-lang/cargo#16006)
- fix: Sparse URLs in `TomlLockfileSourceId` (rust-lang/cargo#15990)
- refactor(gctx): extract toml dotted keys validation (rust-lang/cargo#15998)
- feat: Add lint for global use of `hint-mostly-unused` (rust-lang/cargo#15995)
- Make GlobalContext Sync (rust-lang/cargo#15967)
- chore(deps): update cargo-semver-checks to v0.44.0 (rust-lang/cargo#15993)
- fix(frontatter): Only allow horizontal whitespace after fences (rust-lang/cargo#15975)
- docs: Add Lockfile schemas docs (rust-lang/cargo#15989)
- Add parallel frontend to the build performance guide (rust-lang/cargo#15970)
- chore(deps): update msrv (3 versions) to v1.88 (rust-lang/cargo#15988)
- chore(deps): update msrv (1 version) to v1.90 (rust-lang/cargo#15984)
- feat(cargo-util-schemas): Move lockfile schemas (rust-lang/cargo#15980)
- Clarify multiple version requirement behavior (rust-lang/cargo#15979)
- Adds ghostty as supported terminal for term integration (OSC 9;4) (rust-lang/cargo#15977)
- docs(team): Fixed broken office hours link (rust-lang/cargo#15976)
- docs: Clarify git sources vs git registries in source replacement documentation (rust-lang/cargo#15974)

r? ghost
bors added a commit to rust-lang/rust that referenced this pull request Sep 25, 2025
Update cargo submodule

17 commits in 966f94733bbc94ca51ff9f1e4c49ad250ebbdc50..f2932725b045d361ff5f18ba02b1409dd1f44e71
2025-09-16 17:24:45 +0000 to 2025-09-24 11:31:26 +0000
- fix: use `host-tuple` for host target subsitution (rust-lang/cargo#16003)
- test(build-std): move away from panic_immediate_abort  (rust-lang/cargo#16006)
- fix: Sparse URLs in `TomlLockfileSourceId` (rust-lang/cargo#15990)
- refactor(gctx): extract toml dotted keys validation (rust-lang/cargo#15998)
- feat: Add lint for global use of `hint-mostly-unused` (rust-lang/cargo#15995)
- Make GlobalContext Sync (rust-lang/cargo#15967)
- chore(deps): update cargo-semver-checks to v0.44.0 (rust-lang/cargo#15993)
- fix(frontatter): Only allow horizontal whitespace after fences (rust-lang/cargo#15975)
- docs: Add Lockfile schemas docs (rust-lang/cargo#15989)
- Add parallel frontend to the build performance guide (rust-lang/cargo#15970)
- chore(deps): update msrv (3 versions) to v1.88 (rust-lang/cargo#15988)
- chore(deps): update msrv (1 version) to v1.90 (rust-lang/cargo#15984)
- feat(cargo-util-schemas): Move lockfile schemas (rust-lang/cargo#15980)
- Clarify multiple version requirement behavior (rust-lang/cargo#15979)
- Adds ghostty as supported terminal for term integration (OSC 9;4) (rust-lang/cargo#15977)
- docs(team): Fixed broken office hours link (rust-lang/cargo#15976)
- docs: Clarify git sources vs git registries in source replacement documentation (rust-lang/cargo#15974)

r? ghost
bors added a commit to rust-lang/rust that referenced this pull request Sep 25, 2025
Update cargo submodule

17 commits in 966f94733bbc94ca51ff9f1e4c49ad250ebbdc50..f2932725b045d361ff5f18ba02b1409dd1f44e71
2025-09-16 17:24:45 +0000 to 2025-09-24 11:31:26 +0000
- fix: use `host-tuple` for host target subsitution (rust-lang/cargo#16003)
- test(build-std): move away from panic_immediate_abort  (rust-lang/cargo#16006)
- fix: Sparse URLs in `TomlLockfileSourceId` (rust-lang/cargo#15990)
- refactor(gctx): extract toml dotted keys validation (rust-lang/cargo#15998)
- feat: Add lint for global use of `hint-mostly-unused` (rust-lang/cargo#15995)
- Make GlobalContext Sync (rust-lang/cargo#15967)
- chore(deps): update cargo-semver-checks to v0.44.0 (rust-lang/cargo#15993)
- fix(frontatter): Only allow horizontal whitespace after fences (rust-lang/cargo#15975)
- docs: Add Lockfile schemas docs (rust-lang/cargo#15989)
- Add parallel frontend to the build performance guide (rust-lang/cargo#15970)
- chore(deps): update msrv (3 versions) to v1.88 (rust-lang/cargo#15988)
- chore(deps): update msrv (1 version) to v1.90 (rust-lang/cargo#15984)
- feat(cargo-util-schemas): Move lockfile schemas (rust-lang/cargo#15980)
- Clarify multiple version requirement behavior (rust-lang/cargo#15979)
- Adds ghostty as supported terminal for term integration (OSC 9;4) (rust-lang/cargo#15977)
- docs(team): Fixed broken office hours link (rust-lang/cargo#15976)
- docs: Clarify git sources vs git registries in source replacement documentation (rust-lang/cargo#15974)

r? ghost
@rustbot rustbot added this to the 1.92.0 milestone Sep 25, 2025
github-actions bot pushed a commit to rust-lang/rust-analyzer that referenced this pull request Sep 29, 2025
Update cargo submodule

17 commits in 966f94733bbc94ca51ff9f1e4c49ad250ebbdc50..f2932725b045d361ff5f18ba02b1409dd1f44e71
2025-09-16 17:24:45 +0000 to 2025-09-24 11:31:26 +0000
- fix: use `host-tuple` for host target subsitution (rust-lang/cargo#16003)
- test(build-std): move away from panic_immediate_abort  (rust-lang/cargo#16006)
- fix: Sparse URLs in `TomlLockfileSourceId` (rust-lang/cargo#15990)
- refactor(gctx): extract toml dotted keys validation (rust-lang/cargo#15998)
- feat: Add lint for global use of `hint-mostly-unused` (rust-lang/cargo#15995)
- Make GlobalContext Sync (rust-lang/cargo#15967)
- chore(deps): update cargo-semver-checks to v0.44.0 (rust-lang/cargo#15993)
- fix(frontatter): Only allow horizontal whitespace after fences (rust-lang/cargo#15975)
- docs: Add Lockfile schemas docs (rust-lang/cargo#15989)
- Add parallel frontend to the build performance guide (rust-lang/cargo#15970)
- chore(deps): update msrv (3 versions) to v1.88 (rust-lang/cargo#15988)
- chore(deps): update msrv (1 version) to v1.90 (rust-lang/cargo#15984)
- feat(cargo-util-schemas): Move lockfile schemas (rust-lang/cargo#15980)
- Clarify multiple version requirement behavior (rust-lang/cargo#15979)
- Adds ghostty as supported terminal for term integration (OSC 9;4) (rust-lang/cargo#15977)
- docs(team): Fixed broken office hours link (rust-lang/cargo#15976)
- docs: Clarify git sources vs git registries in source replacement documentation (rust-lang/cargo#15974)

r? ghost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants