Skip to content

std: Clean up and improve errors for is_*_feature_detected macros - #165011

Open
tgross35 wants to merge 5 commits into
rust-lang:mainfrom
tgross35:std_detect-updates
Open

tgross35 wants to merge 5 commits into
rust-lang:mainfrom
tgross35:std_detect-updates

Conversation

@tgross35

@tgross35 tgross35 commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

View all comments

This includes a handful of small changes around the internals of our feature detection macros:

This is done in a handful of separate commits, the messages have some more details.

r? libs

@rustbot

rustbot commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in std_detect

cc @Amanieu, @folkertdev, @sayantn

@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 Oct 27, 2026
@tgross35

Copy link
Copy Markdown
Member Author

@bors try jobs=test-i686-gnu-1,test-i686-gnu-2

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Oct 27, 2026
std: Clean up and improve errors for `is_*_feature_detected` macros


try-job: test-i686-gnu-1
try-job: test-i686-gnu-2
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-bors rust-bors Bot 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 Oct 27, 2026
@rust-bors

This comment was marked as outdated.

@tgross35

This comment was marked as outdated.

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Oct 27, 2026
std: Clean up and improve errors for `is_*_feature_detected` macros


try-job: test-i686-gnu-1
@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment was marked as outdated.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@tgross35

This comment was marked as outdated.

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Oct 27, 2026
std: Clean up and improve errors for `is_*_feature_detected` macros


try-job: test-i686-gnu-1
@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment was marked as outdated.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

It can be a bit tricky to follow these macros, but we still want to
provide good diagnostics. Add tests making sure these don't change.
Because of rewrapping, this prints as:

    error: This macro cannot be used on the current target.
                                       You can prevent it from being used in other architectures by
                                       guarding it behind a cfg(any(target_arch = "aarch64", target_arch = "arm64ec")).

Bridge newlines so it instead prints as this: 

    error: This macro cannot be used on the current target. You can prevent
           it from being used in other architectures by guarding it behind
           a `cfg(any(target_arch = "aarch64", target_arch = "arm64ec"))`.
We have a handful of `#[unstable]` gates that aren't even being used,
because all that matters is the re-export in `std`. For example, the
RISC-V macro appears unstable, but has actually been stable since 1.78
<https://doc.rust-lang.org/1.78.0/std/arch/macro.is_riscv_feature_detected.html>.
@tgross35

Copy link
Copy Markdown
Member Author

@bors try jobs=test-i686-gnu-1

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Oct 27, 2026
std: Clean up and improve errors for `is_*_feature_detected` macros


try-job: test-i686-gnu-1
@rust-bors

rust-bors Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: a0dd189 (a0dd189f4a59792f71fc63cf586e0700c11752ff)
Base parent: 16d1ffa (16d1ffac17ad8b739e32483ac2e65fe7e1804977)

@tgross35

Copy link
Copy Markdown
Member Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 27, 2026
Rather than transmuting discriminants, use the macros to generate a list
of all features that we can iterate instead. This also allows us to
remove the sentinel `_last` entry.
@LawnGnome

Copy link
Copy Markdown
Contributor

I appreciate the added commentary. My brain still hurts following this, but less than I think it would have otherwise.

Playing around with this, I don't see any obvious user-visible changes here other than better error messages, so 👍.

@bors r+ rollup=iffy

@rust-bors

rust-bors Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 5f7505c has been approved by LawnGnome

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-review Status: Awaiting review from the assignee but also interested parties. labels Nov 3, 2026
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 4, 2026
…nGnome

std: Clean up and improve errors for `is_*_feature_detected` macros

This includes a handful of small changes around the internals of our feature detection macros:

* Add UI tests, since this macro is pretty UI-forward but not yet covered anywhere
* Remove misleading feature gates that aren't even being checked, e.g. what showed up in rust-lang#111192 (comment).
* Clean up some errors and improve the comments around all of this

This is done in a handful of separate commits, the messages have some more details.
rust-bors Bot pushed a commit that referenced this pull request Nov 4, 2026
Rollup of 9 pull requests

Successful merges:

 - #165011 (std: Clean up and improve errors for `is_*_feature_detected` macros)
 - #164482 (Remove the label starting with 0 in the test binary_asm_labels_allowed.rs)
 - #165268 (Fix constant-pattern  equality suggestion spans in macros)
 - #165318 (Fix explicit destructor-call suggestion spans in macros)
 - #164440 ([Outreachy] alloc: Add test coverage for try_clone_from_ref_in (Box, Arc, Rc))
 - #165001 (Document allocator swap in BinaryHeap::append)
 - #165330 (Impl read_le/read_be for f16 and f128)
 - #165414 (Remove unusued query key impl)
 - #165440 (docker: bump node to v24.22.2 in shared script)
rust-bors Bot pushed a commit that referenced this pull request Nov 4, 2026
Rollup of 9 pull requests

Successful merges:

 - #165011 (std: Clean up and improve errors for `is_*_feature_detected` macros)
 - #164482 (Remove the label starting with 0 in the test binary_asm_labels_allowed.rs)
 - #165268 (Fix constant-pattern  equality suggestion spans in macros)
 - #165318 (Fix explicit destructor-call suggestion spans in macros)
 - #164440 ([Outreachy] alloc: Add test coverage for try_clone_from_ref_in (Box, Arc, Rc))
 - #165001 (Document allocator swap in BinaryHeap::append)
 - #165330 (Impl read_le/read_be for f16 and f128)
 - #165414 (Remove unusued query key impl)
 - #165440 (docker: bump node to v24.22.2 in shared script)
rust-bors Bot pushed a commit that referenced this pull request Nov 4, 2026
Rollup of 9 pull requests

Successful merges:

 - #165011 (std: Clean up and improve errors for `is_*_feature_detected` macros)
 - #164482 (Remove the label starting with 0 in the test binary_asm_labels_allowed.rs)
 - #165268 (Fix constant-pattern  equality suggestion spans in macros)
 - #165318 (Fix explicit destructor-call suggestion spans in macros)
 - #164440 ([Outreachy] alloc: Add test coverage for try_clone_from_ref_in (Box, Arc, Rc))
 - #165001 (Document allocator swap in BinaryHeap::append)
 - #165330 (Impl read_le/read_be for f16 and f128)
 - #165414 (Remove unusued query key impl)
 - #165440 (docker: bump node to v24.22.2 in shared script)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 4, 2026
…nGnome

std: Clean up and improve errors for `is_*_feature_detected` macros

This includes a handful of small changes around the internals of our feature detection macros:

* Add UI tests, since this macro is pretty UI-forward but not yet covered anywhere
* Remove misleading feature gates that aren't even being checked, e.g. what showed up in rust-lang#111192 (comment).
* Clean up some errors and improve the comments around all of this

This is done in a handful of separate commits, the messages have some more details.
rust-bors Bot pushed a commit that referenced this pull request Nov 4, 2026
…uwer

Rollup of 17 pull requests

Successful merges:

 - #164752 (Apply the Cortex-A53 843419 CC mitigation to aarch64 targets )
 - #165011 (std: Clean up and improve errors for `is_*_feature_detected` macros)
 - #165376 (Add `Forget` trait feature gate)
 - #164482 (Remove the label starting with 0 in the test binary_asm_labels_allowed.rs)
 - #165201 (Move a bunch of methods out of `AttributeExt`)
 - #165268 (Fix constant-pattern  equality suggestion spans in macros)
 - #165318 (Fix explicit destructor-call suggestion spans in macros)
 - #164440 ([Outreachy] alloc: Add test coverage for try_clone_from_ref_in (Box, Arc, Rc))
 - #165001 (Document allocator swap in BinaryHeap::append)
 - #165257 (Revert FCW on lint attributes on macro calls)
 - #165330 (Impl read_le/read_be for f16 and f128)
 - #165364 (Update books)
 - #165414 (Remove unusued query key impl)
 - #165424 (Update amdgpu datalayout for LLVM 24)
 - #165440 (docker: bump node to v24.22.2 in shared script)
 - #165443 (Add `Discriminant::ord`)
 - #165445 (Add an unstable option to increase the chain depth of the next solver overflow FCW)
rust-bors Bot pushed a commit that referenced this pull request Nov 4, 2026
…uwer

Rollup of 17 pull requests

Successful merges:

 - #164752 (Apply the Cortex-A53 843419 CC mitigation to aarch64 targets )
 - #165011 (std: Clean up and improve errors for `is_*_feature_detected` macros)
 - #165376 (Add `Forget` trait feature gate)
 - #164482 (Remove the label starting with 0 in the test binary_asm_labels_allowed.rs)
 - #165201 (Move a bunch of methods out of `AttributeExt`)
 - #165268 (Fix constant-pattern  equality suggestion spans in macros)
 - #165318 (Fix explicit destructor-call suggestion spans in macros)
 - #164440 ([Outreachy] alloc: Add test coverage for try_clone_from_ref_in (Box, Arc, Rc))
 - #165001 (Document allocator swap in BinaryHeap::append)
 - #165257 (Revert FCW on lint attributes on macro calls)
 - #165330 (Impl read_le/read_be for f16 and f128)
 - #165364 (Update books)
 - #165414 (Remove unusued query key impl)
 - #165424 (Update amdgpu datalayout for LLVM 24)
 - #165440 (docker: bump node to v24.22.2 in shared script)
 - #165443 (Add `Discriminant::ord`)
 - #165445 (Add an unstable option to increase the chain depth of the next solver overflow FCW)
rust-bors Bot pushed a commit that referenced this pull request Nov 4, 2026
…uwer

Rollup of 17 pull requests

Successful merges:

 - #164752 (Apply the Cortex-A53 843419 CC mitigation to aarch64 targets )
 - #165011 (std: Clean up and improve errors for `is_*_feature_detected` macros)
 - #165376 (Add `Forget` trait feature gate)
 - #164482 (Remove the label starting with 0 in the test binary_asm_labels_allowed.rs)
 - #165201 (Move a bunch of methods out of `AttributeExt`)
 - #165268 (Fix constant-pattern  equality suggestion spans in macros)
 - #165318 (Fix explicit destructor-call suggestion spans in macros)
 - #164440 ([Outreachy] alloc: Add test coverage for try_clone_from_ref_in (Box, Arc, Rc))
 - #165001 (Document allocator swap in BinaryHeap::append)
 - #165257 (Revert FCW on lint attributes on macro calls)
 - #165330 (Impl read_le/read_be for f16 and f128)
 - #165364 (Update books)
 - #165414 (Remove unusued query key impl)
 - #165424 (Update amdgpu datalayout for LLVM 24)
 - #165440 (docker: bump node to v24.22.2 in shared script)
 - #165443 (Add `Discriminant::ord`)
 - #165445 (Add an unstable option to increase the chain depth of the next solver overflow FCW)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants