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

rustdoc: when merging target features, keep the highest stability #137632

Merged
merged 4 commits into from
Mar 3, 2025

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Feb 25, 2025

This addresses #137366. (Not closing since we might consider a backport.)

rustdoc wants to pretend that it runs for all targets at once and has all target features, so tcx.rust_target_features() will actually be all the target features. For target features that exist on multiple targets, the stability info for one of the targets will be picked (first or last in the list, I guess). All the code consuming that query has to be aware that the data is basically nonsense when running in rustdoc, but the logic checking for unstable or forbidden #[target_feature] attributes was not aware of that.

This PR makes the tcx.rust_target_features() info in rustdoc slightly less nonsensical (and decidedly less random) by having the "most stable" target feature take precedent. That deals with #137366 (a conflict between a stable and a "forbidden" target feature of the same name for different targets), and also deals with the situation (that we did not seem to have yet) of a conflict between a stable and an unstable target feature of the same name. Note that if there are two unstable target features of the same name, rustdoc might still require the "wrong" nightly feature to be enabled -- but this can only possibly affect unstable code so I guess we can wait until that actually happens, and then someone will have to rewrite this entire thing to be less hacky.

@rustbot
Copy link
Collaborator

rustbot commented Feb 25, 2025

r? @workingjubilee

rustbot has assigned @workingjubilee.
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 S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 25, 2025
@RalfJung
Copy link
Member Author

Cc @rust-lang/rustdoc

@RalfJung
Copy link
Member Author

I haven't added a test as I am not sure how to build one... is it even possible to have a no_core rustdoc tests where we could set --target to an ARM target to check this?

@workingjubilee
Copy link
Member

😵‍💫 does rustdoc even respond to things like #![no_core]?

@workingjubilee
Copy link
Member

I suppose it must or core wouldn't work but I'm not feeling entirely sure right now...

@RalfJung
Copy link
Member Author

Given this is fixing a stable-to-stable regression I feel it's okay to land this without a test... though if a rustdoc person has an idea for how to test this that would of course be great. :)

@GuillaumeGomez
Copy link
Member

I'm not even sure to understand what needs to be checked in rustdoc. From reading the issue, what I see is that it failed compilation. What do you want to check in rustdoc?

@RalfJung
Copy link
Member Author

RalfJung commented Feb 28, 2025

It fails compilation only in rustdoc and only on ARM-32 targets. So we'd need a test that checks that some code builds fine in rustdoc on ARM-32. Ideally this test can be run on all hosts, which we usually do with #![no_core] tests that don't need a sysroot and thus can easily be cross-compiled, so we can just set --target <whatever>.

@GuillaumeGomez
Copy link
Member

Do we have an equivalent test for rustc? If so you can write the same one for rustdoc.

@RalfJung
Copy link
Member Author

RalfJung commented Feb 28, 2025

The rustc test would be something like

//@ compile-flags: --target armv7-unknown-linux-gnueabihf

#![crate_type = "lib"]
#![feature(no_core, lang_items)]
#![no_core]

#[lang = "sized"]
pub trait Sized {}

#[target_feature(enable = "neon,v7,aes")]
pub fn fun() {}

So do I just dump such a file into tests/rustdoc?

@GuillaumeGomez
Copy link
Member

In tests/rustdoc-ui with //@ check-pass but otherwise yes. :)

@fmease

This comment has been minimized.

@RalfJung
Copy link
Member Author

Hm that does not seem to do the right thing, the test passes even without my PR.

@RalfJung
Copy link
Member Author

Okay strange, of the two examples given in #137366, only one reproduces this way. 🤷 I guess one confirmed test is enough. ;)

@RalfJung RalfJung force-pushed the rustdoc-target-features branch from b072867 to eff59b8 Compare February 28, 2025 16:02
@rust-log-analyzer

This comment has been minimized.

@RalfJung RalfJung force-pushed the rustdoc-target-features branch from eff59b8 to 6b63c57 Compare February 28, 2025 16:15
@RalfJung
Copy link
Member Author

Ah, right, the neon target feature is no longer "forbidden", we handle that via the ABI instead and that... I have no idea what that does under rustdoc, probably something nonsensical, but at least it does not error. ;)

The last commit disables this check in rustdoc. It also adds a test.

@rust-log-analyzer

This comment has been minimized.

@RalfJung RalfJung force-pushed the rustdoc-target-features branch from 6b63c57 to 63088e3 Compare February 28, 2025 16:31
Comment on lines +93 to +94
if !tcx.sess.opts.actually_rustdoc {
if abi_feature_constraints.incompatible.contains(&name.as_str()) {
Copy link
Member

Choose a reason for hiding this comment

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

isn't this just &&?

Copy link
Member Author

@RalfJung RalfJung Mar 1, 2025

Choose a reason for hiding this comment

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

name is a Symbol. So &&name does not work, no.

Copy link
Member

Choose a reason for hiding this comment

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

I was commenting on both lines because I meant that this is && the control flow operator:

if x {
    if y {
    };
};

if x && y {
};

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, that's what you meant.^^

Yeah you are right.

Copy link
Member Author

Choose a reason for hiding this comment

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

Now it's already rolled up so I'll rather not push to this PR.

Copy link
Member

Choose a reason for hiding this comment

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

them not being merged turned out oddly fortuitous, as they wound up easier to pick apart while backporting, I suppose.

@@ -0,0 +1,28 @@
//! This is a regression test for <https://github.com/rust-lang/rust/issues/137366>, ensuring
//! that we can use the `neon` target feature on ARM-32 targets in rustdoc despite there
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
//! that we can use the `neon` target feature on ARM-32 targets in rustdoc despite there
//! that we can use the `neon` target feature on ARM32 targets in rustdoc despite there

Copy link
Member

@workingjubilee workingjubilee left a comment

Choose a reason for hiding this comment

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

r=me with nits addressed

@apiraino
Copy link
Contributor

apiraino commented Mar 6, 2025

hey @rust-lang/rustdoc Are you interested (or neutral or against) in having this patch backported to beta channel. It fixes a regression on stable.

@RalfJung RalfJung deleted the rustdoc-target-features branch March 6, 2025 17:36
@jieyouxu jieyouxu added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. beta-nominated Nominated for backporting to the compiler in the beta channel. and removed beta-nominated Nominated for backporting to the compiler in the beta channel. labels Mar 9, 2025
@jieyouxu
Copy link
Member

jieyouxu commented Mar 9, 2025

(t-rustdoc backport nomination thread is #t-rustdoc > beta-nominated: #137632)

freebsd-git pushed a commit to freebsd/freebsd-ports that referenced this pull request Mar 13, 2025
A bug [1] prevents documentation from being compiled on this
platform, disable it until it's fixed in a release branch.

[1] rust-lang/rust#137632

Reported by:	mmel
@apiraino
Copy link
Contributor

Beta backport accepted as per compiler team on Zulip. A backport PR will be authored by the release team at the end of the current development cycle. Backport labels handled by them.

(Most importantly, T-rustdoc approved this backport)

@rustbot label +beta-accepted

@rustbot rustbot added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Mar 13, 2025
@cuviper
Copy link
Member

cuviper commented Mar 14, 2025

This was suggested for stable as well, so I'll at least make that a formal nomination:

@rustbot label +stable-nominated

@rustbot rustbot added the stable-nominated Nominated for backporting to the compiler in the stable channel. label Mar 14, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 14, 2025
[stable] Release 1.85.1

- [Fix the doctest-merging feature of the 2024 Edition.](rust-lang#137899)
- [Relax some `target_feature` checks when generating docs.](rust-lang#137632)
  - DRAFT NOTE: this is not formally `stable-accepted` yet. It also required some fixup to deal with differences in the `Stability` system, but I think it should have the same effect, limited to `rustdoc` execution.
- [Fix errors in `fs::rename` on Windows 1607.](rust-lang#137528)
- [Downgrade bootstrap `cc` to fix custom targets.](rust-lang#137460)
- [Skip submodule updates when building Rust from a source tarball.](rust-lang#137338)

cc `@rust-lang/release`
r? cuviper

try-job: dist-x86_64-linux
try-job: dist-i686-msvc
try-job: x86_64-rust-for-linux
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 15, 2025
[stable] Release 1.85.1

- [Fix the doctest-merging feature of the 2024 Edition.](rust-lang#137899)
- [Relax some `target_feature` checks when generating docs.](rust-lang#137632)
  - DRAFT NOTE: this is not formally `stable-accepted` yet. It also required some fixup to deal with differences in the `Stability` system, but I think it should have the same effect, limited to `rustdoc` execution.
- [Fix errors in `fs::rename` on Windows 1607.](rust-lang#137528)
- [Downgrade bootstrap `cc` to fix custom targets.](rust-lang#137460)
- [Skip submodule updates when building Rust from a source tarball.](rust-lang#137338)

cc `@rust-lang/release`
r? cuviper

try-job: dist-x86_64-linux
try-job: dist-i686-msvc
try-job: x86_64-rust-for-linux
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 15, 2025
[stable] Release 1.85.1

- [Fix the doctest-merging feature of the 2024 Edition.](rust-lang#137899)
- [Relax some `target_feature` checks when generating docs.](rust-lang#137632)
  - DRAFT NOTE: this is not formally `stable-accepted` yet. It also required some fixup to deal with differences in the `Stability` system, but I think it should have the same effect, limited to `rustdoc` execution.
- [Fix errors in `fs::rename` on Windows 1607.](rust-lang#137528)
- [Downgrade bootstrap `cc` to fix custom targets.](rust-lang#137460)
- [Skip submodule updates when building Rust from a source tarball.](rust-lang#137338)

cc `@rust-lang/release`
r? cuviper

try-job: dist-x86_64-linux
try-job: dist-i686-msvc
try-job: i686-msvc
try-job: x86_64-rust-for-linux
@cuviper cuviper mentioned this pull request Mar 15, 2025
@cuviper cuviper modified the milestones: 1.87.0, 1.86.0 Mar 15, 2025
@cuviper cuviper removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Mar 15, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 15, 2025
[stable] Release 1.85.1

- [Fix the doctest-merging feature of the 2024 Edition.](rust-lang#137899)
- [Relax some `target_feature` checks when generating docs.](rust-lang#137632)
  - DRAFT NOTE: this is not formally `stable-accepted` yet. It also required some fixup to deal with differences in the `Stability` system, but I think it should have the same effect, limited to `rustdoc` execution.
- [Fix errors in `fs::rename` on Windows 1607.](rust-lang#137528)
- [Downgrade bootstrap `cc` to fix custom targets.](rust-lang#137460)
- [Skip submodule updates when building Rust from a source tarball.](rust-lang#137338)

cc `@rust-lang/release`
r? cuviper

try-job: dist-x86_64-linux
try-job: dist-i686-msvc
try-job: i686-msvc
try-job: x86_64-rust-for-linux
@apiraino
Copy link
Contributor

I'll accept the stable backport as well, based on the T-rustdoc Zulip thread, partly also here. Hoping it can make it to the 1.85.1 train. A backport PR will be authored by the release team at the end of the current development cycle. Backport labels handled by them.

@rustbot label +stable-accepted

@rustbot rustbot added the stable-accepted Accepted for backporting to the compiler in the stable channel. label Mar 15, 2025
@cuviper cuviper removed the stable-nominated Nominated for backporting to the compiler in the stable channel. label Mar 15, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 15, 2025
[stable] Release 1.85.1

- [Fix the doctest-merging feature of the 2024 Edition.](rust-lang#137899)
- [Relax some `target_feature` checks when generating docs.](rust-lang#137632)
- [Fix errors in `std::fs::rename` on Windows 1607.](rust-lang#137528)
- [Downgrade bootstrap `cc` to fix custom targets.](rust-lang#137460)
- [Skip submodule updates when building Rust from a source tarball.](rust-lang#137338)

Added backports to fix CI:

- Remove latest Windows SDK from 32-bit CI rust-lang#137753
- Do not install rustup on Rust for Linux job rust-lang#137947

cc `@rust-lang/release`
r? cuviper
@cuviper cuviper modified the milestones: 1.86.0, 1.85.1 Mar 15, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 16, 2025
[beta] backports

- Windows: Fix error in `fs::rename` on Windows 1607 rust-lang#137528
- rustdoc: when merging target features, keep the highest stability rust-lang#137632
- doctests: fix merging on stable rust-lang#137899
- Revert wf sized check on beta rust-lang#138122

r? cuviper
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 16, 2025
[beta] backports

- Windows: Fix error in `fs::rename` on Windows 1607 rust-lang#137528
- rustdoc: when merging target features, keep the highest stability rust-lang#137632
- doctests: fix merging on stable rust-lang#137899
- Revert wf sized check on beta rust-lang#138122

r? cuviper
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Mar 25, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [rust](https://github.com/rust-lang/rust) | patch | `1.85.0` -> `1.85.1` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>rust-lang/rust (rust)</summary>

### [`v1.85.1`](https://github.com/rust-lang/rust/blob/HEAD/RELEASES.md#Version-1851-2025-03-18)

[Compare Source](rust-lang/rust@1.85.0...1.85.1)

\==========================

<a id="1.85.1"></a>

-   [Fix the doctest-merging feature of the 2024 Edition.](rust-lang/rust#137899)
-   [Relax some `target_feature` checks when generating docs.](rust-lang/rust#137632)
-   [Fix errors in `std::fs::rename` on Windows 10, version 1607.](rust-lang/rust#137528)
-   [Downgrade bootstrap `cc` to fix custom targets.](rust-lang/rust#137460)
-   [Skip submodule updates when building Rust from a source tarball.](rust-lang/rust#137338)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever MR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4yMTIuMiIsInVwZGF0ZWRJblZlciI6IjM5LjIxMi4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-accepted Accepted for backporting to the compiler in the beta channel. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. stable-accepted Accepted for backporting to the compiler in the stable channel. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants