Skip to content

fix(toml): show required rust-version in unstable edition error#16653

Merged
epage merged 2 commits intorust-lang:masterfrom
yash-kumarx:fix-edition-version-hint
Feb 25, 2026
Merged

fix(toml): show required rust-version in unstable edition error#16653
epage merged 2 commits intorust-lang:masterfrom
yash-kumarx:fix-edition-version-hint

Conversation

@yash-kumarx
Copy link
Contributor

@yash-kumarx yash-kumarx commented Feb 18, 2026

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

@rustbot rustbot added A-manifest Area: Cargo.toml issues A-unstable Area: nightly unstable support S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 18, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 18, 2026

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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ehuss, @epage, @weihanglo
  • @ehuss, @epage, @weihanglo expanded to ehuss, epage, weihanglo
  • Random selection from ehuss, epage, weihanglo

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.

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.

View changes since this review

@yash-kumarx yash-kumarx force-pushed the fix-edition-version-hint branch from 6a5139b to 824fed0 Compare February 18, 2026 19:28
@yash-kumarx
Copy link
Contributor Author

yash-kumarx commented Feb 18, 2026

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.

View changes since this review

@weihanglo Done, Split into two atomic commits:

  • fix(test): corrects the edition_unstable_gated test which was expecting the wrong feature name and silently skipping

  • fix(toml): the actual fix — adds the help: hint derived from rust-version

Thank you for your feedback


Caused by:
feature `edition{next}` is required
feature `unstable-editions` is required
Copy link
Contributor

Choose a reason for hiding this comment

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

How did you verify this output with the test still being skipped?

Copy link
Contributor

Choose a reason for hiding this comment

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

FYI this question is still outstanding

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

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.

@epage
Copy link
Contributor

epage commented Feb 23, 2026

FYI I believe this is addressing #15305. Please link out to relevant issues in the PR description. If you say Fixes #15305 on its own line, github will automatically close it on merge.

@yash-kumarx yash-kumarx force-pushed the fix-edition-version-hint branch from 824fed0 to 46a6dee Compare February 24, 2026 14:38
@yash-kumarx
Copy link
Contributor Author

@rustbot ready

@yash-kumarx yash-kumarx force-pushed the fix-edition-version-hint branch from 46a6dee to 3fa13f7 Compare February 24, 2026 17:28
@yash-kumarx
Copy link
Contributor Author

@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
@yash-kumarx yash-kumarx force-pushed the fix-edition-version-hint branch from 3fa13f7 to 2866bb6 Compare February 25, 2026 05:12
@yash-kumarx
Copy link
Contributor Author

@rustbot ready

Copy link
Contributor

@epage epage left a comment

Choose a reason for hiding this comment

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

@epage epage added this pull request to the merge queue Feb 25, 2026
github-merge-queue bot pushed a commit that referenced this pull request Feb 25, 2026
## 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
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Feb 25, 2026
@epage epage added this pull request to the merge queue Feb 25, 2026
Merged via the queue into rust-lang:master with commit 29363ab Feb 25, 2026
29 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-manifest Area: Cargo.toml issues A-unstable Area: nightly unstable support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

More helpful error message for unsupported editions: display the required rust-version

5 participants