Additionally gate negative bounds behind new -Zinternal-testing-features

This commit is contained in:
León Orell Valerian Liehr
2026-05-05 23:14:20 +02:00
parent a9625940af
commit fcbfc8f013
16 changed files with 58 additions and 36 deletions

View File

@@ -549,9 +549,17 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
.emit();
}
// Negative bounds are *super* internal.
// Under no circumstances do we want to advertise the feature name to users!
if !visitor.features.negative_bounds() {
// Negative bounds are *super* internal. We require `-Zinternal-testing-features` *and*
// `#![feature(negative_bounds)]` to prevent proliferation. Under no circumstances do we
// want to advertise the flag and the feature name to users!
//
// IMPORTANT: If you intend on turning negative bounds into a public-facing feature, please
// consult T-types and T-lang first! Do **not** just remove the `-Z` check!
//
// NOTE: `T: !Bound` means "`T` implements `Bound` negatively",
// it does **not** mean "`T` doesn't implement `Bound` (positively or negatively)"!
// The latter would be a SemVer hazard!
if !sess.opts.unstable_opts.internal_testing_features || !visitor.features.negative_bounds() {
for &span in spans.get(&sym::negative_bounds).into_iter().flatten() {
sess.dcx().emit_err(diagnostics::NegativeBoundUnsupported { span });
}

View File

@@ -2431,6 +2431,14 @@ options! {
`=skip-entry`
`=skip-exit`
Multiple options can be combined with commas."),
// The only purpose of this flag is to act as a deterrent:
// Marking a feature that's only meant for testing as internal might not preclude somebody from
// trying to use it in `core` or `std` as both enable various internal features and utilize them
// throughout. This is intentionally a flag not another internal feature as having to modify the
// build cfg in `bootstrap` is arguably scarier than just needing to add `#![feature]`. It also
// stands out a lot more during code review making it easier to get caught.
internal_testing_features: bool = (false, parse_bool, [TRACKED],
"allow certain internal language features to be enabled that help exercise & test the compiler"),
large_data_threshold: Option<u64> = (None, parse_opt_number, [TRACKED],
"set the threshold for objects to be stored in a \"large data\" section \
(only effective with -Ccode-model=medium, default: 65536)"),

View File

@@ -1,3 +1,4 @@
//@ compile-flags: -Zinternal-testing-features
#![feature(negative_bounds)]
trait Trait {

View File

@@ -1,29 +1,29 @@
error: associated type constraints not allowed on negative bounds
--> $DIR/associated-constraints.rs:7:19
--> $DIR/associated-constraints.rs:8:19
|
LL | fn test<T: !Trait<Assoc = i32>>() {}
| ^^^^^^^^^^^
error: associated type constraints not allowed on negative bounds
--> $DIR/associated-constraints.rs:10:31
--> $DIR/associated-constraints.rs:11:31
|
LL | fn test2<T>() where T: !Trait<Assoc = i32> {}
| ^^^^^^^^^^^
error: associated type constraints not allowed on negative bounds
--> $DIR/associated-constraints.rs:13:20
--> $DIR/associated-constraints.rs:14:20
|
LL | fn test3<T: !Trait<Assoc: Send>>() {}
| ^^^^^^^^^^^
error: associated type constraints not allowed on negative bounds
--> $DIR/associated-constraints.rs:16:31
--> $DIR/associated-constraints.rs:17:31
|
LL | fn test4<T>() where T: !Trait<Assoc: Send> {}
| ^^^^^^^^^^^
error: parenthetical notation may not be used for negative bounds
--> $DIR/associated-constraints.rs:19:25
--> $DIR/associated-constraints.rs:20:25
|
LL | fn test5<T>() where T: !Fn() -> i32 {}
| ^^^^^^^^^^^

View File

@@ -1,35 +1,35 @@
error[E0277]: the trait bound `T: !MetaSized` is not satisfied
--> $DIR/negative-metasized.rs:12:11
--> $DIR/negative-metasized.rs:13:11
|
LL | foo::<T>();
| ^ the trait bound `T: !MetaSized` is not satisfied
|
note: required by a bound in `foo`
--> $DIR/negative-metasized.rs:9:11
--> $DIR/negative-metasized.rs:10:11
|
LL | fn foo<T: !MetaSized>() {}
| ^^^^^^^^^^ required by this bound in `foo`
error[E0277]: the trait bound `(): !MetaSized` is not satisfied
--> $DIR/negative-metasized.rs:17:11
--> $DIR/negative-metasized.rs:18:11
|
LL | foo::<()>();
| ^^ the trait bound `(): !MetaSized` is not satisfied
|
note: required by a bound in `foo`
--> $DIR/negative-metasized.rs:9:11
--> $DIR/negative-metasized.rs:10:11
|
LL | fn foo<T: !MetaSized>() {}
| ^^^^^^^^^^ required by this bound in `foo`
error[E0277]: the trait bound `str: !MetaSized` is not satisfied
--> $DIR/negative-metasized.rs:19:11
--> $DIR/negative-metasized.rs:20:11
|
LL | foo::<str>();
| ^^^ the trait bound `str: !MetaSized` is not satisfied
|
note: required by a bound in `foo`
--> $DIR/negative-metasized.rs:9:11
--> $DIR/negative-metasized.rs:10:11
|
LL | fn foo<T: !MetaSized>() {}
| ^^^^^^^^^^ required by this bound in `foo`

View File

@@ -1,35 +1,35 @@
error[E0277]: the trait bound `T: !MetaSized` is not satisfied
--> $DIR/negative-metasized.rs:12:11
--> $DIR/negative-metasized.rs:13:11
|
LL | foo::<T>();
| ^ the trait bound `T: !MetaSized` is not satisfied
|
note: required by a bound in `foo`
--> $DIR/negative-metasized.rs:9:11
--> $DIR/negative-metasized.rs:10:11
|
LL | fn foo<T: !MetaSized>() {}
| ^^^^^^^^^^ required by this bound in `foo`
error[E0277]: the trait bound `(): !MetaSized` is not satisfied
--> $DIR/negative-metasized.rs:17:11
--> $DIR/negative-metasized.rs:18:11
|
LL | foo::<()>();
| ^^ the trait bound `(): !MetaSized` is not satisfied
|
note: required by a bound in `foo`
--> $DIR/negative-metasized.rs:9:11
--> $DIR/negative-metasized.rs:10:11
|
LL | fn foo<T: !MetaSized>() {}
| ^^^^^^^^^^ required by this bound in `foo`
error[E0277]: the trait bound `str: !MetaSized` is not satisfied
--> $DIR/negative-metasized.rs:19:11
--> $DIR/negative-metasized.rs:20:11
|
LL | foo::<str>();
| ^^^ the trait bound `str: !MetaSized` is not satisfied
|
note: required by a bound in `foo`
--> $DIR/negative-metasized.rs:9:11
--> $DIR/negative-metasized.rs:10:11
|
LL | fn foo<T: !MetaSized>() {}
| ^^^^^^^^^^ required by this bound in `foo`

View File

@@ -1,6 +1,7 @@
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver
//@ compile-flags: -Zinternal-testing-features
#![feature(negative_bounds)]
#![feature(sized_hierarchy)]

View File

@@ -1,3 +1,4 @@
//@ compile-flags: -Zinternal-testing-features
#![feature(negative_bounds)]
fn foo<T: !Sized>() {}

View File

@@ -1,11 +1,11 @@
error[E0277]: the trait bound `(): !Sized` is not satisfied
--> $DIR/negative-sized.rs:6:11
--> $DIR/negative-sized.rs:7:11
|
LL | foo::<()>();
| ^^ the trait bound `(): !Sized` is not satisfied
|
note: required by a bound in `foo`
--> $DIR/negative-sized.rs:3:11
--> $DIR/negative-sized.rs:4:11
|
LL | fn foo<T: !Sized>() {}
| ^^^^^^ required by this bound in `foo`

View File

@@ -1,3 +1,4 @@
//@ compile-flags: -Zinternal-testing-features
//@ reference: attributes.diagnostic.on_unimplemented.intro
#![feature(negative_bounds)]

View File

@@ -1,5 +1,5 @@
error[E0277]: the trait bound `NotFoo: !Foo` is not satisfied
--> $DIR/on-unimplemented.rs:9:15
--> $DIR/on-unimplemented.rs:10:15
|
LL | fn hello() -> impl !Foo {
| ^^^^^^^^^ unsatisfied trait bound
@@ -8,7 +8,7 @@ LL | NotFoo
| ------ return type was inferred to be `NotFoo` here
|
help: the trait bound `NotFoo: !Foo` is not satisfied
--> $DIR/on-unimplemented.rs:7:1
--> $DIR/on-unimplemented.rs:8:1
|
LL | struct NotFoo;
| ^^^^^^^^^^^^^

View File

@@ -1,4 +1,4 @@
//@ compile-flags: -Znext-solver
//@ compile-flags: -Znext-solver -Zinternal-testing-features
#![feature(negative_bounds, negative_impls)]

View File

@@ -1,4 +1,4 @@
//@ compile-flags: -Znext-solver
//@ compile-flags: -Znext-solver -Zinternal-testing-features
#![feature(negative_bounds, unboxed_closures)]

View File

@@ -1,3 +1,4 @@
//@ compile-flags: -Zinternal-testing-features
#![feature(negative_bounds, negative_impls)]
fn not_copy<T: !Copy>() {}

View File

@@ -1,57 +1,57 @@
error[E0277]: the trait bound `T: !Copy` is not satisfied
--> $DIR/simple.rs:10:16
--> $DIR/simple.rs:11:16
|
LL | not_copy::<T>();
| ^ the trait bound `T: !Copy` is not satisfied
|
note: required by a bound in `not_copy`
--> $DIR/simple.rs:3:16
--> $DIR/simple.rs:4:16
|
LL | fn not_copy<T: !Copy>() {}
| ^^^^^ required by this bound in `not_copy`
error[E0277]: the trait bound `T: !Copy` is not satisfied
--> $DIR/simple.rs:15:16
--> $DIR/simple.rs:16:16
|
LL | not_copy::<T>();
| ^ the trait bound `T: !Copy` is not satisfied
|
note: required by a bound in `not_copy`
--> $DIR/simple.rs:3:16
--> $DIR/simple.rs:4:16
|
LL | fn not_copy<T: !Copy>() {}
| ^^^^^ required by this bound in `not_copy`
error[E0277]: the trait bound `Copyable: !Copy` is not satisfied
--> $DIR/simple.rs:30:16
--> $DIR/simple.rs:31:16
|
LL | not_copy::<Copyable>();
| ^^^^^^^^ unsatisfied trait bound
|
help: the trait bound `Copyable: !Copy` is not satisfied
--> $DIR/simple.rs:27:1
--> $DIR/simple.rs:28:1
|
LL | struct Copyable;
| ^^^^^^^^^^^^^^^
note: required by a bound in `not_copy`
--> $DIR/simple.rs:3:16
--> $DIR/simple.rs:4:16
|
LL | fn not_copy<T: !Copy>() {}
| ^^^^^ required by this bound in `not_copy`
error[E0277]: the trait bound `NotNecessarilyCopyable: !Copy` is not satisfied
--> $DIR/simple.rs:37:16
--> $DIR/simple.rs:38:16
|
LL | not_copy::<NotNecessarilyCopyable>();
| ^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
|
help: the trait bound `NotNecessarilyCopyable: !Copy` is not satisfied
--> $DIR/simple.rs:34:1
--> $DIR/simple.rs:35:1
|
LL | struct NotNecessarilyCopyable;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: required by a bound in `not_copy`
--> $DIR/simple.rs:3:16
--> $DIR/simple.rs:4:16
|
LL | fn not_copy<T: !Copy>() {}
| ^^^^^ required by this bound in `not_copy`

View File

@@ -1,3 +1,4 @@
//@ compile-flags: -Zinternal-testing-features
//@ check-pass
#![feature(negative_bounds)]