diff --git a/tests/ui/traits/const-traits/call-const-in-tilde-const.rs b/tests/ui/traits/const-traits/call-const-in-tilde-const.rs new file mode 100644 index 000000000000..970ee93fd49a --- /dev/null +++ b/tests/ui/traits/const-traits/call-const-in-tilde-const.rs @@ -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() { + const { T::foo() } + //~^ ERROR the trait bound `T: const Foo` is not satisfied +} + +fn main() {} diff --git a/tests/ui/traits/const-traits/call-const-in-tilde-const.stderr b/tests/ui/traits/const-traits/call-const-in-tilde-const.stderr new file mode 100644 index 000000000000..49c310f1f751 --- /dev/null +++ b/tests/ui/traits/const-traits/call-const-in-tilde-const.stderr @@ -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 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`. diff --git a/tests/ui/traits/const-traits/const-bound-in-host.rs b/tests/ui/traits/const-traits/const-bound-in-host.rs new file mode 100644 index 000000000000..6fbc21074b68 --- /dev/null +++ b/tests/ui/traits/const-traits/const-bound-in-host.rs @@ -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() { + const { T::foo() } +} + +fn main() {} diff --git a/tests/ui/traits/const-traits/const-bound-in-host.stderr b/tests/ui/traits/const-traits/const-bound-in-host.stderr new file mode 100644 index 000000000000..b815f745ee8f --- /dev/null +++ b/tests/ui/traits/const-traits/const-bound-in-host.stderr @@ -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 for more information + = note: `#[warn(incomplete_features)]` on by default + +warning: 1 warning emitted + diff --git a/tests/ui/traits/const-traits/const-in-closure.rs b/tests/ui/traits/const-traits/const-in-closure.rs new file mode 100644 index 000000000000..51b22c530361 --- /dev/null +++ b/tests/ui/traits/const-traits/const-in-closure.rs @@ -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() { + let _ = || { + // Make sure this doesn't enforce `T: ~const Trait` + T::method(); + }; +} + +fn bar() { + let _ = || { + // Make sure unconditionally const bounds propagate from parent. + const { T::method(); }; + }; +} + +fn main() {} diff --git a/tests/ui/traits/const-traits/const-in-closure.stderr b/tests/ui/traits/const-traits/const-in-closure.stderr new file mode 100644 index 000000000000..f4b03b9ed201 --- /dev/null +++ b/tests/ui/traits/const-traits/const-in-closure.stderr @@ -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 for more information + = note: `#[warn(incomplete_features)]` on by default + +warning: 1 warning emitted + diff --git a/tests/ui/traits/const-traits/dont-observe-host-opaque.rs b/tests/ui/traits/const-traits/dont-observe-host-opaque.rs new file mode 100644 index 000000000000..4a5ae346e396 --- /dev/null +++ b/tests/ui/traits/const-traits/dont-observe-host-opaque.rs @@ -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(); +} diff --git a/tests/ui/traits/const-traits/dont-observe-host-opaque.stderr b/tests/ui/traits/const-traits/dont-observe-host-opaque.stderr new file mode 100644 index 000000000000..1b457ab76432 --- /dev/null +++ b/tests/ui/traits/const-traits/dont-observe-host-opaque.stderr @@ -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 for more information + = note: `#[warn(incomplete_features)]` on by default + +warning: 1 warning emitted + diff --git a/tests/ui/traits/const-traits/dont-observe-host.rs b/tests/ui/traits/const-traits/dont-observe-host.rs new file mode 100644 index 000000000000..d027d578c42f --- /dev/null +++ b/tests/ui/traits/const-traits/dont-observe-host.rs @@ -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; +} diff --git a/tests/ui/traits/const-traits/dont-observe-host.stderr b/tests/ui/traits/const-traits/dont-observe-host.stderr new file mode 100644 index 000000000000..64ef611f011c --- /dev/null +++ b/tests/ui/traits/const-traits/dont-observe-host.stderr @@ -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 for more information + = note: `#[warn(incomplete_features)]` on by default + +warning: 1 warning emitted + diff --git a/tests/ui/traits/const-traits/fn-ptr-lub.rs b/tests/ui/traits/const-traits/fn-ptr-lub.rs new file mode 100644 index 000000000000..0fc326788270 --- /dev/null +++ b/tests/ui/traits/const-traits/fn-ptr-lub.rs @@ -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() {} diff --git a/tests/ui/traits/const-traits/fn-ptr-lub.stderr b/tests/ui/traits/const-traits/fn-ptr-lub.stderr new file mode 100644 index 000000000000..b333311b660e --- /dev/null +++ b/tests/ui/traits/const-traits/fn-ptr-lub.stderr @@ -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 for more information + = note: `#[warn(incomplete_features)]` on by default + +warning: 1 warning emitted + diff --git a/tests/ui/traits/const-traits/item-bound-entailment-fails.rs b/tests/ui/traits/const-traits/item-bound-entailment-fails.rs new file mode 100644 index 000000000000..42799e3700ca --- /dev/null +++ b/tests/ui/traits/const-traits/item-bound-entailment-fails.rs @@ -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: ~const Bar + where + T: ~const Bar; +} + +#[const_trait] trait Bar {} +struct N(T); +impl Bar for N where T: Bar {} +struct C(T); +impl const Bar for C where T: ~const Bar {} + +impl const Foo for u32 { + type Assoc = N + //~^ ERROR the trait bound `N: ~const Bar` is not satisfied + where + T: ~const Bar; +} + +impl const Foo for i32 { + type Assoc = C + //~^ ERROR the trait bound `T: ~const Bar` is not satisfied + where + T: Bar; +} + +fn main() {} diff --git a/tests/ui/traits/const-traits/item-bound-entailment-fails.stderr b/tests/ui/traits/const-traits/item-bound-entailment-fails.stderr new file mode 100644 index 000000000000..3b3868c4bc84 --- /dev/null +++ b/tests/ui/traits/const-traits/item-bound-entailment-fails.stderr @@ -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 for more information + = note: `#[warn(incomplete_features)]` on by default + +error[E0277]: the trait bound `N: ~const Bar` is not satisfied + --> $DIR/item-bound-entailment-fails.rs:18:21 + | +LL | type Assoc = N + | ^^^^ + | +note: required by a bound in `Foo::Assoc` + --> $DIR/item-bound-entailment-fails.rs:6:20 + | +LL | type Assoc: ~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 = C + | ^^^^ + | +note: required by a bound in `Foo::Assoc` + --> $DIR/item-bound-entailment-fails.rs:6:20 + | +LL | type Assoc: ~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`. diff --git a/tests/ui/traits/const-traits/item-bound-entailment.rs b/tests/ui/traits/const-traits/item-bound-entailment.rs new file mode 100644 index 000000000000..3670eabd66c0 --- /dev/null +++ b/tests/ui/traits/const-traits/item-bound-entailment.rs @@ -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: ~const Bar + where + T: ~const Bar; +} + +#[const_trait] trait Bar {} +struct N(T); +impl Bar for N where T: Bar {} +struct C(T); +impl const Bar for C where T: ~const Bar {} + +impl Foo for u32 { + type Assoc = N + where + T: Bar; +} + +impl const Foo for i32 { + type Assoc = C + where + T: ~const Bar; +} + +fn main() {} diff --git a/tests/ui/traits/const-traits/item-bound-entailment.stderr b/tests/ui/traits/const-traits/item-bound-entailment.stderr new file mode 100644 index 000000000000..b4a4ebdbee27 --- /dev/null +++ b/tests/ui/traits/const-traits/item-bound-entailment.stderr @@ -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 for more information + = note: `#[warn(incomplete_features)]` on by default + +warning: 1 warning emitted + diff --git a/tests/ui/traits/const-traits/predicate-entailment-fails.rs b/tests/ui/traits/const-traits/predicate-entailment-fails.rs new file mode 100644 index 000000000000..5d6109bfad3a --- /dev/null +++ b/tests/ui/traits/const-traits/predicate-entailment-fails.rs @@ -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 where T: ~const Bar; + + fn foo() where T: ~const Bar; +} +impl TildeConst for () { + type Bar = () where T: const Bar; + //~^ ERROR impl has stricter requirements than trait + + fn foo() where T: const Bar {} + //~^ ERROR impl has stricter requirements than trait +} + + +#[const_trait] trait NeverConst { + type Bar where T: Bar; + + fn foo() where T: Bar; +} +impl NeverConst for i32 { + type Bar = () where T: const Bar; + //~^ ERROR impl has stricter requirements than trait + + fn foo() where T: const Bar {} + //~^ ERROR impl has stricter requirements than trait +} +impl const NeverConst for u32 { + type Bar = () where T: ~const Bar; + //~^ ERROR impl has stricter requirements than trait + + fn foo() where T: ~const Bar {} + //~^ ERROR impl has stricter requirements than trait +} + +fn main() {} diff --git a/tests/ui/traits/const-traits/predicate-entailment-fails.stderr b/tests/ui/traits/const-traits/predicate-entailment-fails.stderr new file mode 100644 index 000000000000..9538630cbd3f --- /dev/null +++ b/tests/ui/traits/const-traits/predicate-entailment-fails.stderr @@ -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 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 where T: ~const Bar; + | ----------- definition of `Bar` from trait +... +LL | type Bar = () where T: const Bar; + | ^^^^^^^^^ impl has extra requirement `T: constBar` + +error[E0276]: impl has stricter requirements than trait + --> $DIR/predicate-entailment-fails.rs:18:26 + | +LL | fn foo() where T: ~const Bar; + | -------------------------------- definition of `foo` from trait +... +LL | fn foo() where T: const Bar {} + | ^^^^^^^^^ impl has extra requirement `T: constBar` + +error[E0276]: impl has stricter requirements than trait + --> $DIR/predicate-entailment-fails.rs:29:31 + | +LL | type Bar where T: Bar; + | ----------- definition of `Bar` from trait +... +LL | type Bar = () where T: const Bar; + | ^^^^^^^^^ impl has extra requirement `T: constBar` + +error[E0276]: impl has stricter requirements than trait + --> $DIR/predicate-entailment-fails.rs:32:26 + | +LL | fn foo() where T: Bar; + | ------------------------- definition of `foo` from trait +... +LL | fn foo() where T: const Bar {} + | ^^^^^^^^^ impl has extra requirement `T: constBar` + +error[E0276]: impl has stricter requirements than trait + --> $DIR/predicate-entailment-fails.rs:36:31 + | +LL | type Bar where T: Bar; + | ----------- definition of `Bar` from trait +... +LL | type Bar = () where T: ~const Bar; + | ^^^^^^^^^^ impl has extra requirement `T: ~constBar` + +error[E0276]: impl has stricter requirements than trait + --> $DIR/predicate-entailment-fails.rs:39:26 + | +LL | fn foo() where T: Bar; + | ------------------------- definition of `foo` from trait +... +LL | fn foo() where T: ~const Bar {} + | ^^^^^^^^^^ impl has extra requirement `T: ~constBar` + +error: aborting due to 6 previous errors; 1 warning emitted + +For more information about this error, try `rustc --explain E0276`. diff --git a/tests/ui/traits/const-traits/predicate-entailment-passes.rs b/tests/ui/traits/const-traits/predicate-entailment-passes.rs new file mode 100644 index 000000000000..b660329151be --- /dev/null +++ b/tests/ui/traits/const-traits/predicate-entailment-passes.rs @@ -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 where T: ~const Bar; + + fn foo() where T: ~const Bar; +} +impl TildeConst for () { + type Bar = () where T: Bar; + + fn foo() where T: Bar {} +} + + +#[const_trait] trait AlwaysConst { + type Bar where T: const Bar; + + fn foo() where T: const Bar; +} +impl AlwaysConst for i32 { + type Bar = () where T: Bar; + + fn foo() where T: Bar {} +} +impl const AlwaysConst for u32 { + type Bar = () where T: ~const Bar; + + fn foo() where T: ~const Bar {} +} + +fn main() {} diff --git a/tests/ui/traits/const-traits/predicate-entailment-passes.stderr b/tests/ui/traits/const-traits/predicate-entailment-passes.stderr new file mode 100644 index 000000000000..dcaeea73b580 --- /dev/null +++ b/tests/ui/traits/const-traits/predicate-entailment-passes.stderr @@ -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 for more information + = note: `#[warn(incomplete_features)]` on by default + +warning: 1 warning emitted +