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

if !visitor.features.negative_bounds() {
// Negative bounds are *super* internal. We require `-Ztrait-solver-testing-features` *and*
// `#![feature(negative_bounds)]` to prevent proliferation. Under no circumstances do we
// want to advertise the zee flag and the feature name to users!
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"zee flag" caught me off guard. I've never seen it used before, and I don't see any other examples like it in the codebase. Just drop the "zee" so it says "the flag"?

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

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants