Skip to content

Conversation

@jieyouxu
Copy link
Member

@jieyouxu jieyouxu commented Jan 18, 2026

A codegen mode test (such as codegen-llvm test suite) will now by default have an implied //@ needs-target-std directive, unless the test explicitly has an #![no_std]/#![no_core] attribute which disables this behavior.

  • When a test has both #![no_std]/#![no_core] and //@ needs-target-std, the explicit //@ needs-target-std directive will cause the test to be ignored for targets that do not support std still.

This is to make it easier to test out-of-tree targets / custom targets (and targets not tested in r-l/r CI) without requiring target maintainers to do a bunch of manual //@ needs-target-std busywork.

Context: #t-compiler/help > `compiletest` cannot find `core` library for target != host

Implementation remarks

This is an alternative version of #150672, with some differences:

  • This PR applies this implied-needs-target-std behavior to all codegen test mode tests.
  • This PR does the synthetic directive injection in the same place as implied-codegen-run directives. Both are of course hacks, but at least they're together next to each other.

@rustbot
Copy link
Collaborator

rustbot commented Jan 18, 2026

The rustc-dev-guide subtree was changed. If this PR only touches the dev guide consider submitting a PR directly to rust-lang/rustc-dev-guide otherwise thank you for updating the dev guide with your changes.

cc @BoxyUwU, @Kobzol, @tshepang

@rustbot rustbot added A-compiletest Area: The compiletest test runner A-rustc-dev-guide Area: rustc-dev-guide A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Jan 18, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 18, 2026

r? @Zalathar

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

Comment on lines 318 to 327
By default, codegen tests will infer `//@ needs-target-std` (that the target
needs to support std), *unless* the `#![no_std]` attribute was specified in the
test source. You can override this behavior and explicitly write `//@
needs-target-std` to only run the test when target supports std, even if the
test is `#![no_std]`.

Copy link
Member Author

Choose a reason for hiding this comment

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

Discussion: note that design wise, I still don't really like this kind of inferred implicit behavior, but OTOH I agree it is really annoying having to maintain explicit //@ needs-target-std for codegen tests.

@jieyouxu jieyouxu force-pushed the infer-needs-target-std branch 2 times, most recently from 101f610 to c2d972b Compare January 18, 2026 11:18
@jieyouxu jieyouxu changed the title compiletest: infer needs-target-std for codegen-{gcc,llvm,cranelift} tests compiletest: infer needs-target-std for codegen mode tests Jan 18, 2026
@jieyouxu jieyouxu changed the title compiletest: infer needs-target-std for codegen mode tests compiletest: infer needs-target-std for codegen mode tests without #![no_std] Jan 18, 2026
@jieyouxu
Copy link
Member Author

cc @xdoardo, lmw if you want an Co-authored-by attribution.

}

if let Some(directive_line) = line_directive(path, line_number, ln) {
lines.push(directive_line);
Copy link
Contributor

@xdoardo xdoardo Jan 18, 2026

Choose a reason for hiding this comment

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

I haven't looked too much into it, but I noticed that the testing infrastructure looks at the directives in reverse to find reasons to ignore the test for the current target.

This means, for example, that a test like this will be ignored with the "target needs std" message if it is run for a target that does not have std and is not a 64-bit platform.

It could make sense to add the synthetic directive at the beginning of the vector instead, so that the (potential) reasons to ignore the test for the current target that are already in the file are checked first.

Copy link
Member Author

Choose a reason for hiding this comment

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

That seems okay, but also I think that's an orthogonal change which can benefit from a more aggressive change: I wonder if we should report the set of criteria that contributes to a test being ignored, rather than just the "first" or "last" directive.

@xdoardo
Copy link
Contributor

xdoardo commented Jan 18, 2026

I had a couple patches to push to my PR, but I am happy to close mine and comment here the bits I had patches for.

cc @xdoardo, lmw if you want an Co-authored-by attribution.

That would be great! It's not that important, though. I'm fine without the attribution if it is a hassle.

@jieyouxu
Copy link
Member Author

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 19, 2026
@Zalathar
Copy link
Member

Terminology nitpick: This usage of “infer” feels subtly wrong to me, in a way that trips me up every time I read it.

E.g. if I were the one writing, I would be more likely to say that we assume the need for an implicit/implied //@ needs-target-std directive in all codegen tests, except for ones with an explicit #![no_std] attribute.

@jieyouxu jieyouxu changed the title compiletest: infer needs-target-std for codegen mode tests without #![no_std] compiletest: assume needs-target-std for codegen mode tests unless explicit directive or annotated with #![no_std] Jan 21, 2026
@jieyouxu jieyouxu changed the title compiletest: assume needs-target-std for codegen mode tests unless explicit directive or annotated with #![no_std] compiletest: assume needs-target-std for codegen mode tests unless annotated with #![no_std] Jan 21, 2026
@jieyouxu jieyouxu changed the title compiletest: assume needs-target-std for codegen mode tests unless annotated with #![no_std] compiletest: assume needs-target-std for codegen mode tests unless annotated with #![no_{std,core}] Jan 21, 2026
@jieyouxu jieyouxu force-pushed the infer-needs-target-std branch from c2d972b to 8923124 Compare January 21, 2026 01:48
@rustbot

This comment has been minimized.

@jieyouxu jieyouxu force-pushed the infer-needs-target-std branch from 8923124 to 9cfd996 Compare January 21, 2026 01:52
@jieyouxu
Copy link
Member Author

Changes since last review:

  • Added #![no_core] to also disable the implied //@ needs-target-std.
  • Updated comment as requested, esp. to change "inferred" -> "implied".
  • Updated PR/commit title/description re. above.

@rustbot review

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jan 21, 2026
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 21, 2026
@jieyouxu jieyouxu changed the title compiletest: assume needs-target-std for codegen mode tests unless annotated with #![no_{std,core}] compiletest: assume needs-target-std for codegen mode tests unless annotated with #![no_std]/#![no_core] Jan 21, 2026
@Zalathar
Copy link
Member

Looks good to me, thanks.

I notice there are still a few occurrences of “infer” left over; r=me after another cleanup pass to make those more consistent.

@Zalathar
Copy link
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 24, 2026
…tests by default

A `codegen-llvm` test (and other codegen test mode tests) will now by
default have an implied `//@ needs-target-std` directive, *unless* the
test explicitly has an `#![no_std]`/`#![no_core]` attribute which
disables this implied behavior.

- When a test has both `#![no_std]`/`#![no_core]` and `//@
  needs-target-std`, the explicit `//@ needs-target-std` directive will
  cause the test to be ignored for targets that do not support std
  still.

This is to make it easier to test out-of-tree targets / custom targets
(and targets not tested in r-l/r CI) without requiring target
maintainers to do a bunch of manual `//@ needs-target-std` busywork.

Co-authored-by: Edoardo Marangoni <ecmm@anche.no>
@jieyouxu jieyouxu force-pushed the infer-needs-target-std branch from 9cfd996 to 841d781 Compare January 26, 2026 01:43
@rustbot
Copy link
Collaborator

rustbot commented Jan 26, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@jieyouxu jieyouxu changed the title compiletest: assume needs-target-std for codegen mode tests unless annotated with #![no_std]/#![no_core] compiletest: add implied needs-target-std for codegen mode tests unless annotated with #![no_std]/#![no_core] Jan 26, 2026
@jieyouxu
Copy link
Member Author

Fixed the leftover "inferred" that I apparently missed, no functional changes since last review.
@bors r=Zalathar rollup

@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 26, 2026

📌 Commit 841d781 has been approved by Zalathar

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 26, 2026
rust-bors bot pushed a commit that referenced this pull request Jan 26, 2026
Rollup of 6 pull requests

Successful merges:

 - #151611 (Improve is_ascii performance on x86_64 with explicit SSE2 intrinsics)
 - #150705 (Add missing mut to pin.rs docs)
 - #151294 (compiletest: add implied `needs-target-std` for `codegen` mode tests unless annotated with `#![no_std]`/`#![no_core]`)
 - #151589 (Add a `documentation` remapping path scope for rustdoc usage)
 - #151639 (Fix broken WASIp1 reference link)
 - #151645 (Update `sysinfo` version to `0.38.0`)
@rust-bors rust-bors bot merged commit 504c7fe into rust-lang:main Jan 26, 2026
11 checks passed
@rustbot rustbot added this to the 1.95.0 milestone Jan 26, 2026
rust-timer added a commit that referenced this pull request Jan 26, 2026
Rollup merge of #151294 - jieyouxu:infer-needs-target-std, r=Zalathar

compiletest: add implied `needs-target-std` for `codegen` mode tests unless annotated with `#![no_std]`/`#![no_core]`

A `codegen` mode test (such as `codegen-llvm` test suite) will now by default have an implied `//@ needs-target-std` directive, *unless* the test explicitly has an `#![no_std]`/`#![no_core]` attribute which disables this behavior.

- When a test has both `#![no_std]`/`#![no_core]` and `//@ needs-target-std`, the explicit `//@ needs-target-std` directive will cause the test to be ignored for targets that do not support std still.

This is to make it easier to test out-of-tree targets / custom targets (and targets not tested in r-l/r CI) without requiring target maintainers to do a bunch of manual `//@ needs-target-std` busywork.

Context: [#t-compiler/help > &#96;compiletest&#96; cannot find &#96;core&#96; library for target != host](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/.60compiletest.60.20cannot.20find.20.60core.60.20library.20for.20target.20!.3D.20host/with/568652419)

## Implementation remarks

This is an alternative version of #150672, with some differences:

- *This* PR applies this implied-`needs-target-std` behavior to all `codegen` test mode tests.
- *This* PR does the synthetic directive injection in the same place as implied-`codegen-run` directives. Both are of course hacks, but at least they're together next to each other.
@jieyouxu jieyouxu deleted the infer-needs-target-std branch January 26, 2026 09:51
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Jan 26, 2026
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#151611 (Improve is_ascii performance on x86_64 with explicit SSE2 intrinsics)
 - rust-lang/rust#150705 (Add missing mut to pin.rs docs)
 - rust-lang/rust#151294 (compiletest: add implied `needs-target-std` for `codegen` mode tests unless annotated with `#![no_std]`/`#![no_core]`)
 - rust-lang/rust#151589 (Add a `documentation` remapping path scope for rustdoc usage)
 - rust-lang/rust#151639 (Fix broken WASIp1 reference link)
 - rust-lang/rust#151645 (Update `sysinfo` version to `0.38.0`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-compiletest Area: The compiletest test runner A-rustc-dev-guide Area: rustc-dev-guide A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants