Skip to content

Additionally gate negative bounds behind new -Ztrait-solver-testing-features#156212

Open
fmease wants to merge 1 commit intorust-lang:mainfrom
fmease:double-gate-negative-bounds
Open

Additionally gate negative bounds behind new -Ztrait-solver-testing-features#156212
fmease wants to merge 1 commit intorust-lang:mainfrom
fmease:double-gate-negative-bounds

Conversation

@fmease
Copy link
Copy Markdown
Member

@fmease fmease commented May 5, 2026

Support for negative bounds (not to be confused with negative impls) was added in PR RUST-110791 (2023) for internal testing purposes only.

In PR RUST-119354 (2023) I marked it internal. Moreover, we intentionally never advertise this feature and we declare it as an internal-only feature for testing the trait solver in the Unstable Book (via).

However, these measures didn't prevent someone from trying to use them in the public API of the stdlib1! I can't blame them in the slightest: The stdlib uses unstable and internal features left and right, even in stable APIs. What's more, there's the sibling feature negative impls that obviously bears a similar name, is not internal and is used in stable APIs. I can see that it's easy to miss that their status differs so drastically.

Well, I have to admit, it's unlikely that such a PR would ever pass review. However, there's a chance it might, I don't know. Last time it was me who caught it.

I argue that "better docs" just wouldn't really help, a tidy rule would be too much effort & be too fragile and triagebot mentions would be the wrong tool for the job (see also) even if their functionality got extended.

Therefore I've decided to additionally gate negative bounds behind a new -Ztrait-solver-testing-features flag. This should be deterrent enough since surely nobody would modify the build flags for the stdlib I'm thinking and the name should scream "I'm unfit for general use".

If y'all disagree with the hypothesis and the solution, please voice your concern! I'm fine with retracting this PR if it's not liked.

Footnotes

  1. This should go without saying but don't put any blame on individuals! Context: https://github.com/rust-lang/rust/pull/146668#issuecomment-3303881805.

@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 May 5, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 5, 2026

r? @nnethercote

rustbot has assigned @nnethercote.
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: compiler
  • compiler expanded to 73 candidates
  • Random selection from 20 candidates

track_diagnostics: bool = (false, parse_bool, [UNTRACKED],
"tracks where in rustc a diagnostic was emitted"),
trait_solver_testing_features: bool = (false, parse_bool, [TRACKED],
"allow certain internal language features to be enabled that help exercise & test the trait solver"),
Copy link
Copy Markdown
Member Author

@fmease fmease May 5, 2026

Choose a reason for hiding this comment

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

it's "allow […] to be enabled" not "allow" since it doesn't automatically allow negative bounds as they're still gated behind internal feature negative_bounds; it merely allows you to allow negative_bounds.

View changes since the review

track_diagnostics: bool = (false, parse_bool, [UNTRACKED],
"tracks where in rustc a diagnostic was emitted"),
trait_solver_testing_features: bool = (false, parse_bool, [TRACKED],
"allow certain internal language features to be enabled that help exercise & test the trait solver"),
Copy link
Copy Markdown
Member Author

@fmease fmease May 5, 2026

Choose a reason for hiding this comment

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

I'm not saying "trait solvers", plural, so this description doesn't need to be updated when the next solver supersedes the old one.

View changes since the review

Copy link
Copy Markdown
Contributor

@nnethercote nnethercote left a comment

Choose a reason for hiding this comment

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

If y'all disagree with the hypothesis and the solution, please voice your concern! I'm fine with retracting this PR if it's not liked.

This seems fine to me: simple and reasonable. But I'm not an expert on feature (stable and unstable). Do you want to wait for (or request) feedback from additional people?

View changes since this review

Comment thread compiler/rustc_ast_passes/src/feature_gate.rs Outdated
@mejrs
Copy link
Copy Markdown
Contributor

mejrs commented May 6, 2026

I like using the playground to experiment with all the crazy internal stuff. Will that no longer be possible with this? At least you can pass arguments on rust.godbolt.org, but stilll...

Can we instead rename the feature gate to something like trait_system_testing_internals? Or require both that and negative_bounds enabled or something like that?

@fmease
Copy link
Copy Markdown
Member Author

fmease commented May 6, 2026

Interesting point which I do understand but on the other hand it would sadden me if playground limitations actively dictated how we design our internals.

I also use the playground for experimenting with wacky features and for finding bugs from time to time (and it's easier to use on the phone compared to Godbolt last time I checked). In recent years however I almost always use my local machine for speed, access to IR-dumping -Z flags (oh well), the possibility to compare behavior against much older toolchains etc. One can't even test the next solver on the playground.

I need to think on that.

@fmease fmease force-pushed the double-gate-negative-bounds branch from 0f6b69b to 5105d28 Compare May 6, 2026 08:52
@fmease fmease 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 May 6, 2026
@fmease
Copy link
Copy Markdown
Member Author

fmease commented May 6, 2026

Do you want to wait for (or request) feedback from additional people?

cc @lcnr for visibility

@lcnr
Copy link
Copy Markdown
Contributor

lcnr commented May 6, 2026

we could generalize this just to -Ztest-internals 🤔 🤷

generally in favor, yeah

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

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

5 participants