Skip to content

Commit 41e4c4e

Browse files
Add tests
1 parent 141723f commit 41e4c4e

20 files changed

+450
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//@ compile-flags: -Znext-solver
2+
#![feature(const_trait_impl, effects)]
3+
//~^ WARN the feature `effects` is incomplete
4+
5+
#[const_trait] trait Foo {
6+
fn foo();
7+
}
8+
9+
const fn foo<T: ~const Foo>() {
10+
const { T::foo() }
11+
//~^ ERROR the trait bound `T: const Foo` is not satisfied
12+
}
13+
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
warning: the feature `effects` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/call-const-in-tilde-const.rs:2:30
3+
|
4+
LL | #![feature(const_trait_impl, effects)]
5+
| ^^^^^^^
6+
|
7+
= note: see issue #102090 <https://github.com/rust-lang/rust/issues/102090> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
error[E0277]: the trait bound `T: const Foo` is not satisfied
11+
--> $DIR/call-const-in-tilde-const.rs:10:13
12+
|
13+
LL | const { T::foo() }
14+
| ^^^^^^^^
15+
16+
error: aborting due to 1 previous error; 1 warning emitted
17+
18+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//@ compile-flags: -Znext-solver
2+
//@ check-pass
3+
4+
#![feature(const_trait_impl, effects)]
5+
//~^ WARN the feature `effects` is incomplete
6+
7+
#[const_trait] trait Foo {
8+
fn foo();
9+
}
10+
11+
fn foo<T: const Foo>() {
12+
const { T::foo() }
13+
}
14+
15+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `effects` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/const-bound-in-host.rs:4:30
3+
|
4+
LL | #![feature(const_trait_impl, effects)]
5+
| ^^^^^^^
6+
|
7+
= note: see issue #102090 <https://github.com/rust-lang/rust/issues/102090> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//@ compile-flags: -Znext-solver
2+
//@ check-pass
3+
4+
#![feature(const_trait_impl, effects)]
5+
//~^ WARN the feature `effects` is incomplete
6+
7+
#[const_trait] trait Trait {
8+
fn method();
9+
}
10+
11+
const fn foo<T: Trait>() {
12+
let _ = || {
13+
// Make sure this doesn't enforce `T: ~const Trait`
14+
T::method();
15+
};
16+
}
17+
18+
fn bar<T: const Trait>() {
19+
let _ = || {
20+
// Make sure unconditionally const bounds propagate from parent.
21+
const { T::method(); };
22+
};
23+
}
24+
25+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `effects` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/const-in-closure.rs:4:30
3+
|
4+
LL | #![feature(const_trait_impl, effects)]
5+
| ^^^^^^^
6+
|
7+
= note: see issue #102090 <https://github.com/rust-lang/rust/issues/102090> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ compile-flags: -Znext-solver
2+
//@ check-pass
3+
4+
#![feature(const_trait_impl, effects)]
5+
//~^ WARN the feature `effects` is incomplete
6+
7+
const fn opaque() -> impl Sized {}
8+
9+
fn main() {
10+
let mut x = const { opaque() };
11+
x = opaque();
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `effects` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/dont-observe-host-opaque.rs:4:30
3+
|
4+
LL | #![feature(const_trait_impl, effects)]
5+
| ^^^^^^^
6+
|
7+
= note: see issue #102090 <https://github.com/rust-lang/rust/issues/102090> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//@ compile-flags: -Znext-solver
2+
//@ check-pass
3+
4+
#![feature(const_trait_impl, effects)]
5+
//~^ WARN the feature `effects` is incomplete
6+
7+
#[const_trait]
8+
trait Trait {
9+
fn method() {}
10+
}
11+
12+
impl const Trait for () {}
13+
14+
fn main() {
15+
let mut x = const {
16+
let x = <()>::method;
17+
x();
18+
x
19+
};
20+
let y = <()>::method;
21+
y();
22+
x = y;
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `effects` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/dont-observe-host.rs:4:30
3+
|
4+
LL | #![feature(const_trait_impl, effects)]
5+
| ^^^^^^^
6+
|
7+
= note: see issue #102090 <https://github.com/rust-lang/rust/issues/102090> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@ compile-flags: -Znext-solver
2+
//@ check-pass
3+
4+
#![feature(const_trait_impl, effects)]
5+
//~^ WARN the feature `effects` is incomplete
6+
7+
const fn foo() {}
8+
const fn bar() {}
9+
fn baz() {}
10+
11+
const fn caller(branch: bool) {
12+
let mut x = if branch {
13+
foo
14+
} else {
15+
bar
16+
};
17+
x = baz;
18+
}
19+
20+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `effects` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/fn-ptr-lub.rs:4:30
3+
|
4+
LL | #![feature(const_trait_impl, effects)]
5+
| ^^^^^^^
6+
|
7+
= note: see issue #102090 <https://github.com/rust-lang/rust/issues/102090> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//@ compile-flags: -Znext-solver
2+
#![feature(const_trait_impl, effects)]
3+
//~^ WARN the feature `effects` is incomplete
4+
5+
#[const_trait] trait Foo {
6+
type Assoc<T>: ~const Bar
7+
where
8+
T: ~const Bar;
9+
}
10+
11+
#[const_trait] trait Bar {}
12+
struct N<T>(T);
13+
impl<T> Bar for N<T> where T: Bar {}
14+
struct C<T>(T);
15+
impl<T> const Bar for C<T> where T: ~const Bar {}
16+
17+
impl const Foo for u32 {
18+
type Assoc<T> = N<T>
19+
//~^ ERROR the trait bound `N<T>: ~const Bar` is not satisfied
20+
where
21+
T: ~const Bar;
22+
}
23+
24+
impl const Foo for i32 {
25+
type Assoc<T> = C<T>
26+
//~^ ERROR the trait bound `T: ~const Bar` is not satisfied
27+
where
28+
T: Bar;
29+
}
30+
31+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
warning: the feature `effects` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/item-bound-entailment-fails.rs:2:30
3+
|
4+
LL | #![feature(const_trait_impl, effects)]
5+
| ^^^^^^^
6+
|
7+
= note: see issue #102090 <https://github.com/rust-lang/rust/issues/102090> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
error[E0277]: the trait bound `N<T>: ~const Bar` is not satisfied
11+
--> $DIR/item-bound-entailment-fails.rs:18:21
12+
|
13+
LL | type Assoc<T> = N<T>
14+
| ^^^^
15+
|
16+
note: required by a bound in `Foo::Assoc`
17+
--> $DIR/item-bound-entailment-fails.rs:6:20
18+
|
19+
LL | type Assoc<T>: ~const Bar
20+
| ^^^^^^^^^^ required by this bound in `Foo::Assoc`
21+
22+
error[E0277]: the trait bound `T: ~const Bar` is not satisfied
23+
--> $DIR/item-bound-entailment-fails.rs:25:21
24+
|
25+
LL | type Assoc<T> = C<T>
26+
| ^^^^
27+
|
28+
note: required by a bound in `Foo::Assoc`
29+
--> $DIR/item-bound-entailment-fails.rs:6:20
30+
|
31+
LL | type Assoc<T>: ~const Bar
32+
| ^^^^^^^^^^ required by this bound in `Foo::Assoc`
33+
34+
error: aborting due to 2 previous errors; 1 warning emitted
35+
36+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//@ compile-flags: -Znext-solver
2+
//@ check-pass
3+
4+
#![feature(const_trait_impl, effects)]
5+
//~^ WARN the feature `effects` is incomplete
6+
7+
#[const_trait] trait Foo {
8+
type Assoc<T>: ~const Bar
9+
where
10+
T: ~const Bar;
11+
}
12+
13+
#[const_trait] trait Bar {}
14+
struct N<T>(T);
15+
impl<T> Bar for N<T> where T: Bar {}
16+
struct C<T>(T);
17+
impl<T> const Bar for C<T> where T: ~const Bar {}
18+
19+
impl Foo for u32 {
20+
type Assoc<T> = N<T>
21+
where
22+
T: Bar;
23+
}
24+
25+
impl const Foo for i32 {
26+
type Assoc<T> = C<T>
27+
where
28+
T: ~const Bar;
29+
}
30+
31+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `effects` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/item-bound-entailment.rs:4:30
3+
|
4+
LL | #![feature(const_trait_impl, effects)]
5+
| ^^^^^^^
6+
|
7+
= note: see issue #102090 <https://github.com/rust-lang/rust/issues/102090> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//@ compile-flags: -Znext-solver
2+
#![feature(const_trait_impl, effects)]
3+
//~^ WARN the feature `effects` is incomplete
4+
5+
#[const_trait] trait Bar {}
6+
impl const Bar for () {}
7+
8+
9+
#[const_trait] trait TildeConst {
10+
type Bar<T> where T: ~const Bar;
11+
12+
fn foo<T>() where T: ~const Bar;
13+
}
14+
impl TildeConst for () {
15+
type Bar<T> = () where T: const Bar;
16+
//~^ ERROR impl has stricter requirements than trait
17+
18+
fn foo<T>() where T: const Bar {}
19+
//~^ ERROR impl has stricter requirements than trait
20+
}
21+
22+
23+
#[const_trait] trait NeverConst {
24+
type Bar<T> where T: Bar;
25+
26+
fn foo<T>() where T: Bar;
27+
}
28+
impl NeverConst for i32 {
29+
type Bar<T> = () where T: const Bar;
30+
//~^ ERROR impl has stricter requirements than trait
31+
32+
fn foo<T>() where T: const Bar {}
33+
//~^ ERROR impl has stricter requirements than trait
34+
}
35+
impl const NeverConst for u32 {
36+
type Bar<T> = () where T: ~const Bar;
37+
//~^ ERROR impl has stricter requirements than trait
38+
39+
fn foo<T>() where T: ~const Bar {}
40+
//~^ ERROR impl has stricter requirements than trait
41+
}
42+
43+
fn main() {}

0 commit comments

Comments
 (0)