Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Oct 22, 2024
1 parent 335c47d commit 1eb7baa
Show file tree
Hide file tree
Showing 20 changed files with 450 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/ui/traits/const-traits/call-const-in-tilde-const.rs
Original file line number Diff line number Diff line change
@@ -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() {}
18 changes: 18 additions & 0 deletions tests/ui/traits/const-traits/call-const-in-tilde-const.stderr
Original file line number Diff line number Diff line change
@@ -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`.
15 changes: 15 additions & 0 deletions tests/ui/traits/const-traits/const-bound-in-host.rs
Original file line number Diff line number Diff line change
@@ -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() {}
11 changes: 11 additions & 0 deletions tests/ui/traits/const-traits/const-bound-in-host.stderr
Original file line number Diff line number Diff line change
@@ -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

25 changes: 25 additions & 0 deletions tests/ui/traits/const-traits/const-in-closure.rs
Original file line number Diff line number Diff line change
@@ -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() {}
11 changes: 11 additions & 0 deletions tests/ui/traits/const-traits/const-in-closure.stderr
Original file line number Diff line number Diff line change
@@ -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

12 changes: 12 additions & 0 deletions tests/ui/traits/const-traits/dont-observe-host-opaque.rs
Original file line number Diff line number Diff line change
@@ -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();
}
11 changes: 11 additions & 0 deletions tests/ui/traits/const-traits/dont-observe-host-opaque.stderr
Original file line number Diff line number Diff line change
@@ -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

23 changes: 23 additions & 0 deletions tests/ui/traits/const-traits/dont-observe-host.rs
Original file line number Diff line number Diff line change
@@ -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;
}
11 changes: 11 additions & 0 deletions tests/ui/traits/const-traits/dont-observe-host.stderr
Original file line number Diff line number Diff line change
@@ -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

20 changes: 20 additions & 0 deletions tests/ui/traits/const-traits/fn-ptr-lub.rs
Original file line number Diff line number Diff line change
@@ -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() {}
11 changes: 11 additions & 0 deletions tests/ui/traits/const-traits/fn-ptr-lub.stderr
Original file line number Diff line number Diff line change
@@ -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

31 changes: 31 additions & 0 deletions tests/ui/traits/const-traits/item-bound-entailment-fails.rs
Original file line number Diff line number Diff line change
@@ -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() {}
36 changes: 36 additions & 0 deletions tests/ui/traits/const-traits/item-bound-entailment-fails.stderr
Original file line number Diff line number Diff line change
@@ -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`.
31 changes: 31 additions & 0 deletions tests/ui/traits/const-traits/item-bound-entailment.rs
Original file line number Diff line number Diff line change
@@ -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() {}
11 changes: 11 additions & 0 deletions tests/ui/traits/const-traits/item-bound-entailment.stderr
Original file line number Diff line number Diff line change
@@ -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

43 changes: 43 additions & 0 deletions tests/ui/traits/const-traits/predicate-entailment-fails.rs
Original file line number Diff line number Diff line change
@@ -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() {}
Loading

0 comments on commit 1eb7baa

Please sign in to comment.