Skip to content

Conversation

@omskscream
Copy link
Contributor

What does this PR try to resolve?

This is a follow-up for #16407.

This PR is supposed to make patch-related error messages closer to the desired style, remove unnecessary(?) context wrappings, and fix a few minor issues in code.

I tried to restructure some of the error messages to include the values from .context() where I thought it would make sense. Obvious duplications (e.g. repository url of the patch) were removed.

I tried to rephrase some of the error messages to sound closer to the desired style and to ease future migration to rustc's error reporter.

How to test and review this PR?

Test changes should demonstrate the intended behavior change.
Suggestions on how to make messages even better are obviously welcome.

Note

I was thinking about (and tried) moving this portion of error messages directly to the annotate snippets #15944, but with several functions returning Result it was not straightforward. Probably needs well-thought refactoring, which is out of scope of this PR.

r? @weihanglo

@rustbot rustbot added A-crate-dependencies Area: [dependencies] of any kind A-registries Area: registries S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 11, 2026
Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

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

Thanks for the pull request. Looks really nice!

I was thinking about (and tried) moving this portion of error messages directly to the annotate snippets #15944, but with several functions returning Result it was not straightforward. Probably needs well-thought refactoring, which is out of scope of this PR.

Yeah that one definitely need more legwork :)

View changes since this review

Caused by:
The patch location `[ROOT]/foo/bar` contains a `bar` package with version `0.1.0`, but the patch definition in `[ROOT]/foo/Cargo.toml` requires `^0.1.1`.
Check that the version in the patch location is what you expect, and update the patch definition to match.
[ERROR] patch `bar` version mismatch
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the clean-up!

Some minor nits:

  • First letter should be lowercase.
  • We could have note and help levels here maybe, such as
error: patch `bar` version mismatch
note: patch location contains version `0.1.0`, but patch definition requires `^0.1.1`
help: check patch location `[ROOT]/foo/bar`
help: check `bar` patch definition for `https://github.com/rust-lang/crates.io-index`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the comments (and sorry for the delay in addressing them -- life happens).
Strangely, putting keywords to the message manually for some reason did not occur to me, but now I know that there's a way 🙂

vers.sort();
let versions: Vec<_> = vers.into_iter().map(|v| v.to_string()).collect();
return Poll::Ready(Err(anyhow::anyhow!(
"patch for `{}` in `{}` resolved to more than one candidate\n\
Copy link
Member

Choose a reason for hiding this comment

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

No need to quite the second one (source)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, it's similar to displaying various context::Definition in messages that were discussed in #16407.
Here SourceId is used and for some kinds it uses backticks in its Display implementation, for others don't.
I've added a separate test using git repository (commit#418bb33) to showcase when backticks would be preferred. So I don't think it will make sense to remove them here.

Copy link
Member

Choose a reason for hiding this comment

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

Indeed. We can leave it for future improvements. Thanks for adding a test!

[ERROR] patch for `bar` in `registry `alternative`` resolved to more than one candidate
Found versions: 0.1.0, 0.1.1
Check `bar` patch definition for `https://github.com/rust-lang/crates.io-index` in `[ROOT]/foo/Cargo.toml`
For example, select only one package using `version = "=0.1.1"`
Copy link
Member

Choose a reason for hiding this comment

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

  • we don't need to quote "registry alternative" maybe?

What about this?

error: patch for `bar` in registry `alternative` resolved to more than one candidate
note: found versions: 0.1.0, 0.1.1
help: check `bar` patch definition for `https://github.com/rust-lang/crates.io-index` in `[ROOT]/foo/Cargo.toml`
help: select only one package, for example with `version = "=0.1.1"`

@omskscream omskscream force-pushed the patch/add-location-clean-up branch from e5c05f7 to 8bbb642 Compare January 17, 2026 16:14
Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

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

This is great. Appreciate the help!

View changes since this review

vers.sort();
let versions: Vec<_> = vers.into_iter().map(|v| v.to_string()).collect();
return Poll::Ready(Err(anyhow::anyhow!(
"patch for `{}` in `{}` resolved to more than one candidate\n\
Copy link
Member

Choose a reason for hiding this comment

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

Indeed. We can leave it for future improvements. Thanks for adding a test!

@weihanglo weihanglo added this pull request to the merge queue Jan 17, 2026
Merged via the queue into rust-lang:master with commit a793cd1 Jan 17, 2026
29 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 17, 2026
rust-bors bot pushed a commit to rust-lang/rust that referenced this pull request Jan 23, 2026
Update cargo submodule

14 commits in 85eff7c80277b57f78b11e28d14154ab12fcf643..efcd9f58636c1990393d495159045d9c35e43b8f
2026-01-15 16:18:08 +0000 to 2026-01-23 13:50:59 +0000
- chore(deps): update cargo-semver-checks to v0.46.0 (rust-lang/cargo#16548)
- Increase cache_lock test timeout (rust-lang/cargo#16545)
- iTerm now supports OSC 9;4 (terminal window progress bar) (rust-lang/cargo#16506)
- chore: Updated compiler errors for Rust 1.93 (rust-lang/cargo#16543)
- test(build-std): adjust snapshot (rust-lang/cargo#16539)
- chore: bump to 0.96.0 (rust-lang/cargo#16538)
- fix: update `resolve_all_features()` to filter pkg deps (rust-lang/cargo#16221)
- fix: show implicit_minimum_version_req emitted source once per package (rust-lang/cargo#16535)
- fix: `--remap-path-scope` stabilized in 1.95-nightly (rust-lang/cargo#16536)
- feat(lints): Add non_kebab_case_bin lint  (rust-lang/cargo#16524)
- fix(rm): Suggest table flags when none are specified (rust-lang/cargo#16533)
- fix(patch): clean up patch-related error messages (rust-lang/cargo#16498)
- Store artifact deps in build unit dir (rust-lang/cargo#16519)
- refactor(timings): reuse timing metric collection logic between `--timings` and `-Zbuild-analysis` (rust-lang/cargo#16497)
rust-bors bot pushed a commit to rust-lang/rust that referenced this pull request Jan 23, 2026
Update cargo submodule

14 commits in 85eff7c80277b57f78b11e28d14154ab12fcf643..efcd9f58636c1990393d495159045d9c35e43b8f
2026-01-15 16:18:08 +0000 to 2026-01-23 13:50:59 +0000
- chore(deps): update cargo-semver-checks to v0.46.0 (rust-lang/cargo#16548)
- Increase cache_lock test timeout (rust-lang/cargo#16545)
- iTerm now supports OSC 9;4 (terminal window progress bar) (rust-lang/cargo#16506)
- chore: Updated compiler errors for Rust 1.93 (rust-lang/cargo#16543)
- test(build-std): adjust snapshot (rust-lang/cargo#16539)
- chore: bump to 0.96.0 (rust-lang/cargo#16538)
- fix: update `resolve_all_features()` to filter pkg deps (rust-lang/cargo#16221)
- fix: show implicit_minimum_version_req emitted source once per package (rust-lang/cargo#16535)
- fix: `--remap-path-scope` stabilized in 1.95-nightly (rust-lang/cargo#16536)
- feat(lints): Add non_kebab_case_bin lint  (rust-lang/cargo#16524)
- fix(rm): Suggest table flags when none are specified (rust-lang/cargo#16533)
- fix(patch): clean up patch-related error messages (rust-lang/cargo#16498)
- Store artifact deps in build unit dir (rust-lang/cargo#16519)
- refactor(timings): reuse timing metric collection logic between `--timings` and `-Zbuild-analysis` (rust-lang/cargo#16497)
rust-bors bot pushed a commit to rust-lang/rust that referenced this pull request Jan 24, 2026
Update cargo submodule

14 commits in 85eff7c80277b57f78b11e28d14154ab12fcf643..efcd9f58636c1990393d495159045d9c35e43b8f
2026-01-15 16:18:08 +0000 to 2026-01-23 13:50:59 +0000
- chore(deps): update cargo-semver-checks to v0.46.0 (rust-lang/cargo#16548)
- Increase cache_lock test timeout (rust-lang/cargo#16545)
- iTerm now supports OSC 9;4 (terminal window progress bar) (rust-lang/cargo#16506)
- chore: Updated compiler errors for Rust 1.93 (rust-lang/cargo#16543)
- test(build-std): adjust snapshot (rust-lang/cargo#16539)
- chore: bump to 0.96.0 (rust-lang/cargo#16538)
- fix: update `resolve_all_features()` to filter pkg deps (rust-lang/cargo#16221)
- fix: show implicit_minimum_version_req emitted source once per package (rust-lang/cargo#16535)
- fix: `--remap-path-scope` stabilized in 1.95-nightly (rust-lang/cargo#16536)
- feat(lints): Add non_kebab_case_bin lint  (rust-lang/cargo#16524)
- fix(rm): Suggest table flags when none are specified (rust-lang/cargo#16533)
- fix(patch): clean up patch-related error messages (rust-lang/cargo#16498)
- Store artifact deps in build unit dir (rust-lang/cargo#16519)
- refactor(timings): reuse timing metric collection logic between `--timings` and `-Zbuild-analysis` (rust-lang/cargo#16497)
@rustbot rustbot added this to the 1.95.0 milestone Jan 24, 2026
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Jan 25, 2026
Update cargo submodule

14 commits in 85eff7c80277b57f78b11e28d14154ab12fcf643..efcd9f58636c1990393d495159045d9c35e43b8f
2026-01-15 16:18:08 +0000 to 2026-01-23 13:50:59 +0000
- chore(deps): update cargo-semver-checks to v0.46.0 (rust-lang/cargo#16548)
- Increase cache_lock test timeout (rust-lang/cargo#16545)
- iTerm now supports OSC 9;4 (terminal window progress bar) (rust-lang/cargo#16506)
- chore: Updated compiler errors for Rust 1.93 (rust-lang/cargo#16543)
- test(build-std): adjust snapshot (rust-lang/cargo#16539)
- chore: bump to 0.96.0 (rust-lang/cargo#16538)
- fix: update `resolve_all_features()` to filter pkg deps (rust-lang/cargo#16221)
- fix: show implicit_minimum_version_req emitted source once per package (rust-lang/cargo#16535)
- fix: `--remap-path-scope` stabilized in 1.95-nightly (rust-lang/cargo#16536)
- feat(lints): Add non_kebab_case_bin lint  (rust-lang/cargo#16524)
- fix(rm): Suggest table flags when none are specified (rust-lang/cargo#16533)
- fix(patch): clean up patch-related error messages (rust-lang/cargo#16498)
- Store artifact deps in build unit dir (rust-lang/cargo#16519)
- refactor(timings): reuse timing metric collection logic between `--timings` and `-Zbuild-analysis` (rust-lang/cargo#16497)
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Jan 26, 2026
Update cargo submodule

14 commits in 85eff7c80277b57f78b11e28d14154ab12fcf643..efcd9f58636c1990393d495159045d9c35e43b8f
2026-01-15 16:18:08 +0000 to 2026-01-23 13:50:59 +0000
- chore(deps): update cargo-semver-checks to v0.46.0 (rust-lang/cargo#16548)
- Increase cache_lock test timeout (rust-lang/cargo#16545)
- iTerm now supports OSC 9;4 (terminal window progress bar) (rust-lang/cargo#16506)
- chore: Updated compiler errors for Rust 1.93 (rust-lang/cargo#16543)
- test(build-std): adjust snapshot (rust-lang/cargo#16539)
- chore: bump to 0.96.0 (rust-lang/cargo#16538)
- fix: update `resolve_all_features()` to filter pkg deps (rust-lang/cargo#16221)
- fix: show implicit_minimum_version_req emitted source once per package (rust-lang/cargo#16535)
- fix: `--remap-path-scope` stabilized in 1.95-nightly (rust-lang/cargo#16536)
- feat(lints): Add non_kebab_case_bin lint  (rust-lang/cargo#16524)
- fix(rm): Suggest table flags when none are specified (rust-lang/cargo#16533)
- fix(patch): clean up patch-related error messages (rust-lang/cargo#16498)
- Store artifact deps in build unit dir (rust-lang/cargo#16519)
- refactor(timings): reuse timing metric collection logic between `--timings` and `-Zbuild-analysis` (rust-lang/cargo#16497)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-crate-dependencies Area: [dependencies] of any kind A-registries Area: registries

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants