Add tests

This commit is contained in:
Michael Goulet 2024-10-21 20:16:33 +00:00
parent 779b3943d3
commit 25c9253379
24 changed files with 513 additions and 0 deletions

View File

@ -0,0 +1,22 @@
//@ compile-flags: -Znext-solver
//@ edition:2021
#![feature(const_trait_impl, effects, const_closures)]
#![allow(incomplete_features)]
#[const_trait]
trait Bar {
fn foo(&self);
}
impl Bar for () {
fn foo(&self) {}
}
const FOO: () = {
(const || ().foo())();
//~^ ERROR the trait bound `(): ~const Bar` is not satisfied
// FIXME(effects): The constness environment for const closures is wrong.
};
fn main() {}

View File

@ -0,0 +1,9 @@
error[E0277]: the trait bound `(): ~const Bar` is not satisfied
--> $DIR/call-const-closure.rs:17:15
|
LL | (const || ().foo())();
| ^^^^^^^^
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`.

View File

@ -0,0 +1,14 @@
//@ compile-flags: -Znext-solver
#![feature(const_trait_impl, effects)]
//~^ WARN the feature `effects` is incomplete
#[const_trait] trait Foo {
fn foo();
}
const fn foo<T: ~const Foo>() {
const { T::foo() }
//~^ ERROR the trait bound `T: const Foo` is not satisfied
}
fn main() {}

View File

@ -0,0 +1,18 @@
warning: the feature `effects` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/call-const-in-tilde-const.rs:2:30
|
LL | #![feature(const_trait_impl, effects)]
| ^^^^^^^
|
= note: see issue #102090 <https://github.com/rust-lang/rust/issues/102090> for more information
= note: `#[warn(incomplete_features)]` on by default
error[E0277]: the trait bound `T: const Foo` is not satisfied
--> $DIR/call-const-in-tilde-const.rs:10:13
|
LL | const { T::foo() }
| ^^^^^^^^
error: aborting due to 1 previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0277`.

View File

@ -0,0 +1,15 @@
//@ compile-flags: -Znext-solver
//@ check-pass
#![feature(const_trait_impl, effects)]
//~^ WARN the feature `effects` is incomplete
#[const_trait] trait Foo {
fn foo();
}
fn foo<T: const Foo>() {
const { T::foo() }
}
fn main() {}

View File

@ -0,0 +1,11 @@
warning: the feature `effects` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/const-bound-in-host.rs:4:30
|
LL | #![feature(const_trait_impl, effects)]
| ^^^^^^^
|
= note: see issue #102090 <https://github.com/rust-lang/rust/issues/102090> for more information
= note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted

View File

@ -0,0 +1,25 @@
//@ compile-flags: -Znext-solver
//@ check-pass
#![feature(const_trait_impl, effects)]
//~^ WARN the feature `effects` is incomplete
#[const_trait] trait Trait {
fn method();
}
const fn foo<T: Trait>() {
let _ = || {
// Make sure this doesn't enforce `T: ~const Trait`
T::method();
};
}
fn bar<T: const Trait>() {
let _ = || {
// Make sure unconditionally const bounds propagate from parent.
const { T::method(); };
};
}
fn main() {}

View File

@ -0,0 +1,11 @@
warning: the feature `effects` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/const-in-closure.rs:4:30
|
LL | #![feature(const_trait_impl, effects)]
| ^^^^^^^
|
= note: see issue #102090 <https://github.com/rust-lang/rust/issues/102090> for more information
= note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted

View File

@ -0,0 +1,12 @@
//@ compile-flags: -Znext-solver
//@ check-pass
#![feature(const_trait_impl, effects)]
//~^ WARN the feature `effects` is incomplete
const fn opaque() -> impl Sized {}
fn main() {
let mut x = const { opaque() };
x = opaque();
}

View File

@ -0,0 +1,11 @@
warning: the feature `effects` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/dont-observe-host-opaque.rs:4:30
|
LL | #![feature(const_trait_impl, effects)]
| ^^^^^^^
|
= note: see issue #102090 <https://github.com/rust-lang/rust/issues/102090> for more information
= note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted

View File

@ -0,0 +1,23 @@
//@ compile-flags: -Znext-solver
//@ check-pass
#![feature(const_trait_impl, effects)]
//~^ WARN the feature `effects` is incomplete
#[const_trait]
trait Trait {
fn method() {}
}
impl const Trait for () {}
fn main() {
let mut x = const {
let x = <()>::method;
x();
x
};
let y = <()>::method;
y();
x = y;
}

View File

@ -0,0 +1,11 @@
warning: the feature `effects` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/dont-observe-host.rs:4:30
|
LL | #![feature(const_trait_impl, effects)]
| ^^^^^^^
|
= note: see issue #102090 <https://github.com/rust-lang/rust/issues/102090> for more information
= note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted

View File

@ -0,0 +1,20 @@
//@ compile-flags: -Znext-solver
//@ check-pass
#![feature(const_trait_impl, effects)]
//~^ WARN the feature `effects` is incomplete
const fn foo() {}
const fn bar() {}
fn baz() {}
const fn caller(branch: bool) {
let mut x = if branch {
foo
} else {
bar
};
x = baz;
}
fn main() {}

View File

@ -0,0 +1,11 @@
warning: the feature `effects` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/fn-ptr-lub.rs:4:30
|
LL | #![feature(const_trait_impl, effects)]
| ^^^^^^^
|
= note: see issue #102090 <https://github.com/rust-lang/rust/issues/102090> for more information
= note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted

View File

@ -0,0 +1,31 @@
//@ compile-flags: -Znext-solver
#![feature(const_trait_impl, effects)]
//~^ WARN the feature `effects` is incomplete
#[const_trait] trait Foo {
type Assoc<T>: ~const Bar
where
T: ~const Bar;
}
#[const_trait] trait Bar {}
struct N<T>(T);
impl<T> Bar for N<T> where T: Bar {}
struct C<T>(T);
impl<T> const Bar for C<T> where T: ~const Bar {}
impl const Foo for u32 {
type Assoc<T> = N<T>
//~^ ERROR the trait bound `N<T>: ~const Bar` is not satisfied
where
T: ~const Bar;
}
impl const Foo for i32 {
type Assoc<T> = C<T>
//~^ ERROR the trait bound `T: ~const Bar` is not satisfied
where
T: Bar;
}
fn main() {}

View File

@ -0,0 +1,36 @@
warning: the feature `effects` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/item-bound-entailment-fails.rs:2:30
|
LL | #![feature(const_trait_impl, effects)]
| ^^^^^^^
|
= note: see issue #102090 <https://github.com/rust-lang/rust/issues/102090> for more information
= note: `#[warn(incomplete_features)]` on by default
error[E0277]: the trait bound `N<T>: ~const Bar` is not satisfied
--> $DIR/item-bound-entailment-fails.rs:18:21
|
LL | type Assoc<T> = N<T>
| ^^^^
|
note: required by a bound in `Foo::Assoc`
--> $DIR/item-bound-entailment-fails.rs:6:20
|
LL | type Assoc<T>: ~const Bar
| ^^^^^^^^^^ required by this bound in `Foo::Assoc`
error[E0277]: the trait bound `T: ~const Bar` is not satisfied
--> $DIR/item-bound-entailment-fails.rs:25:21
|
LL | type Assoc<T> = C<T>
| ^^^^
|
note: required by a bound in `Foo::Assoc`
--> $DIR/item-bound-entailment-fails.rs:6:20
|
LL | type Assoc<T>: ~const Bar
| ^^^^^^^^^^ required by this bound in `Foo::Assoc`
error: aborting due to 2 previous errors; 1 warning emitted
For more information about this error, try `rustc --explain E0277`.

View File

@ -0,0 +1,31 @@
//@ compile-flags: -Znext-solver
//@ check-pass
#![feature(const_trait_impl, effects)]
//~^ WARN the feature `effects` is incomplete
#[const_trait] trait Foo {
type Assoc<T>: ~const Bar
where
T: ~const Bar;
}
#[const_trait] trait Bar {}
struct N<T>(T);
impl<T> Bar for N<T> where T: Bar {}
struct C<T>(T);
impl<T> const Bar for C<T> where T: ~const Bar {}
impl Foo for u32 {
type Assoc<T> = N<T>
where
T: Bar;
}
impl const Foo for i32 {
type Assoc<T> = C<T>
where
T: ~const Bar;
}
fn main() {}

View File

@ -0,0 +1,11 @@
warning: the feature `effects` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/item-bound-entailment.rs:4:30
|
LL | #![feature(const_trait_impl, effects)]
| ^^^^^^^
|
= note: see issue #102090 <https://github.com/rust-lang/rust/issues/102090> for more information
= note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted

View File

@ -0,0 +1,43 @@
//@ compile-flags: -Znext-solver
#![feature(const_trait_impl, effects)]
//~^ WARN the feature `effects` is incomplete
#[const_trait] trait Bar {}
impl const Bar for () {}
#[const_trait] trait TildeConst {
type Bar<T> where T: ~const Bar;
fn foo<T>() where T: ~const Bar;
}
impl TildeConst for () {
type Bar<T> = () where T: const Bar;
//~^ ERROR impl has stricter requirements than trait
fn foo<T>() where T: const Bar {}
//~^ ERROR impl has stricter requirements than trait
}
#[const_trait] trait NeverConst {
type Bar<T> where T: Bar;
fn foo<T>() where T: Bar;
}
impl NeverConst for i32 {
type Bar<T> = () where T: const Bar;
//~^ ERROR impl has stricter requirements than trait
fn foo<T>() where T: const Bar {}
//~^ ERROR impl has stricter requirements than trait
}
impl const NeverConst for u32 {
type Bar<T> = () where T: ~const Bar;
//~^ ERROR impl has stricter requirements than trait
fn foo<T>() where T: ~const Bar {}
//~^ ERROR impl has stricter requirements than trait
}
fn main() {}

View File

@ -0,0 +1,66 @@
warning: the feature `effects` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/predicate-entailment-fails.rs:2:30
|
LL | #![feature(const_trait_impl, effects)]
| ^^^^^^^
|
= note: see issue #102090 <https://github.com/rust-lang/rust/issues/102090> for more information
= note: `#[warn(incomplete_features)]` on by default
error[E0276]: impl has stricter requirements than trait
--> $DIR/predicate-entailment-fails.rs:15:31
|
LL | type Bar<T> where T: ~const Bar;
| ----------- definition of `Bar` from trait
...
LL | type Bar<T> = () where T: const Bar;
| ^^^^^^^^^ impl has extra requirement `T: const Bar`
error[E0276]: impl has stricter requirements than trait
--> $DIR/predicate-entailment-fails.rs:18:26
|
LL | fn foo<T>() where T: ~const Bar;
| -------------------------------- definition of `foo` from trait
...
LL | fn foo<T>() where T: const Bar {}
| ^^^^^^^^^ impl has extra requirement `T: const Bar`
error[E0276]: impl has stricter requirements than trait
--> $DIR/predicate-entailment-fails.rs:29:31
|
LL | type Bar<T> where T: Bar;
| ----------- definition of `Bar` from trait
...
LL | type Bar<T> = () where T: const Bar;
| ^^^^^^^^^ impl has extra requirement `T: const Bar`
error[E0276]: impl has stricter requirements than trait
--> $DIR/predicate-entailment-fails.rs:32:26
|
LL | fn foo<T>() where T: Bar;
| ------------------------- definition of `foo` from trait
...
LL | fn foo<T>() where T: const Bar {}
| ^^^^^^^^^ impl has extra requirement `T: const Bar`
error[E0276]: impl has stricter requirements than trait
--> $DIR/predicate-entailment-fails.rs:36:31
|
LL | type Bar<T> where T: Bar;
| ----------- definition of `Bar` from trait
...
LL | type Bar<T> = () where T: ~const Bar;
| ^^^^^^^^^^ impl has extra requirement `T: ~const Bar`
error[E0276]: impl has stricter requirements than trait
--> $DIR/predicate-entailment-fails.rs:39:26
|
LL | fn foo<T>() where T: Bar;
| ------------------------- definition of `foo` from trait
...
LL | fn foo<T>() where T: ~const Bar {}
| ^^^^^^^^^^ impl has extra requirement `T: ~const Bar`
error: aborting due to 6 previous errors; 1 warning emitted
For more information about this error, try `rustc --explain E0276`.

View File

@ -0,0 +1,39 @@
//@ compile-flags: -Znext-solver
//@ check-pass
#![feature(const_trait_impl, effects)]
//~^ WARN the feature `effects` is incomplete
#[const_trait] trait Bar {}
impl const Bar for () {}
#[const_trait] trait TildeConst {
type Bar<T> where T: ~const Bar;
fn foo<T>() where T: ~const Bar;
}
impl TildeConst for () {
type Bar<T> = () where T: Bar;
fn foo<T>() where T: Bar {}
}
#[const_trait] trait AlwaysConst {
type Bar<T> where T: const Bar;
fn foo<T>() where T: const Bar;
}
impl AlwaysConst for i32 {
type Bar<T> = () where T: Bar;
fn foo<T>() where T: Bar {}
}
impl const AlwaysConst for u32 {
type Bar<T> = () where T: ~const Bar;
fn foo<T>() where T: ~const Bar {}
}
fn main() {}

View File

@ -0,0 +1,11 @@
warning: the feature `effects` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/predicate-entailment-passes.rs:4:30
|
LL | #![feature(const_trait_impl, effects)]
| ^^^^^^^
|
= note: see issue #102090 <https://github.com/rust-lang/rust/issues/102090> for more information
= note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted

View File

@ -0,0 +1,21 @@
//@ compile-flags: -Znext-solver
//@ known-bug: #132067
//@ check-pass
#![feature(const_trait_impl, effects)]
struct S;
#[const_trait]
trait Trait<const N: u32> {}
const fn f<
T: Trait<
{
struct I<U: ~const Trait<0>>(U);
0
},
>,
>() {
}
pub fn main() {}

View File

@ -0,0 +1,11 @@
warning: the feature `effects` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/tilde-const-in-struct-args.rs:5:30
|
LL | #![feature(const_trait_impl, effects)]
| ^^^^^^^
|
= note: see issue #102090 <https://github.com/rust-lang/rust/issues/102090> for more information
= note: `#[warn(incomplete_features)]` on by default
warning: 1 warning emitted