fix(toml): show required rust-version in unstable edition error#16653
fix(toml): show required rust-version in unstable edition error#16653epage merged 2 commits intorust-lang:masterfrom
Conversation
|
r? @ehuss rustbot has assigned @ehuss. Use Why was this reviewer chosen?The reviewer was selected based on:
|
There was a problem hiding this comment.
Also fixes a latent bug in edition_unstable_gated: it expected
feature 'edition{next}' but current code emits feature 'unstable-editions'.
The test was silently skipping because Edition::LATEST_UNSTABLE is None.
Not having time reviewing the diff, though with that "and" I would assume this PR has at least two commits but I only saw commit. We recommend atomic commits for Git history management.
6a5139b to
824fed0
Compare
@weihanglo Done, Split into two atomic commits:
Thank you for your feedback |
tests/testsuite/edition.rs
Outdated
|
|
||
| Caused by: | ||
| feature `edition{next}` is required | ||
| feature `unstable-editions` is required |
There was a problem hiding this comment.
How did you verify this output with the test still being skipped?
There was a problem hiding this comment.
FYI this question is still outstanding
There was a problem hiding this comment.
Truly sorry @epage,
Since LATEST_UNSTABLE is None right now, the test always returns early so runtime verification is not possible. I verified it by reading the source: unstable_editions is defined in features.rs and require() applies .replace("_", "-") to the name, which gives unstable-editions. The docs URL fragment is also hardcoded in the same feature definition. Both are constants so I'm fairly confident the expected output is right, but if you say I can revert this change and leave the test untouched if you would prefer to revisit it when LATEST_UNSTABLE gets set again.
There was a problem hiding this comment.
As an old coworker said "if it isn't tested, then it is broken". That is going to a bit of an extreme imo but I think it applies here. You found that the output is incorrect for your reading of the code but the same kind of inspection is the only way to check if the new version of the code is correct. I would lean towards not changing it. On top of that, this doesn't seem to be related to this PR.
|
FYI I believe this is addressing #15305. Please link out to relevant issues in the PR description. If you say |
824fed0 to
46a6dee
Compare
|
@rustbot ready |
46a6dee to
3fa13f7
Compare
|
@rustbot ready |
Add a test `future_edition_with_rust_version_hint` that exercises the case where a package uses an unstable edition (`future`) and also sets `rust-version`. This records the current behavior before the fix -- the error message does not yet include a hint about the required Rust toolchain version.
When a package specifies an unstable edition (e.g. `edition = "future"`) and also declares a `rust-version`, the feature-gate error now appends a `help:` line of the form: help: <name>@<version> requires rust <msrv> This mirrors the style used elsewhere in Cargo (e.g. dependency MSRV conflicts) and gives the user an actionable pointer to the toolchain they need. Implementation: add `Features::require_with_hint` that takes an optional help string and emits it after the documentation link; call it from the unstable-edition check in `toml/mod.rs`, passing a hint built from the package name, version, and `rust-version` field. Closes rust-lang#15305
3fa13f7 to
2866bb6
Compare
|
@rustbot ready |
## What does this PR try to resolve? Fixes the unhelpful error when a package declares an unstable edition on a stable Cargo toolchain. Previously the error told the user to "try a newer version of Cargo" but gave no indication of *which* version, forcing them to dig through docs. This PR adds a `help:` line that names the required toolchain version, derived from the package's `rust-version` field (or from `Edition::first_version()` once that is set at unstable time). Before: ``` Consider trying a newer version of Cargo (this may require the nightly release). See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#unstable-editions ``` After: ``` Consider trying a newer version of Cargo (this may require the nightly release). help: mypackage@0.1.0 requires rustc 1.90 See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#unstable-editions ``` Also fixes a latent bug in `edition_unstable_gated`: it expected `feature 'edition{next}'` but current code emits `feature 'unstable-editions'`. The test was silently skipping because `Edition::LATEST_UNSTABLE` is `None`. Fixes #15305
What does this PR try to resolve?
Fixes the unhelpful error when a package declares an unstable edition on a
stable Cargo toolchain. Previously the error told the user to "try a newer
version of Cargo" but gave no indication of which version, forcing them to
dig through docs.
This PR adds a
help:line that names the required toolchain version,derived from the package's
rust-versionfield (or fromEdition::first_version()once that is set at unstable time).Before:
After:
Also fixes a latent bug in
edition_unstable_gated: it expectedfeature 'edition{next}'but current code emitsfeature 'unstable-editions'.The test was silently skipping because
Edition::LATEST_UNSTABLEisNone.Fixes #15305