diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:11:38 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:13:23 +0000 |
commit | 20431706a863f92cb37dc512fef6e48d192aaf2c (patch) | |
tree | 2867f13f5fd5437ba628c67d7f87309ccadcd286 /src/test/ui/rfc-2632-const-trait-impl | |
parent | Releasing progress-linux version 1.65.0+dfsg1-2~progress7.99u1. (diff) | |
download | rustc-20431706a863f92cb37dc512fef6e48d192aaf2c.tar.xz rustc-20431706a863f92cb37dc512fef6e48d192aaf2c.zip |
Merging upstream version 1.66.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
73 files changed, 726 insertions, 258 deletions
diff --git a/src/test/ui/rfc-2632-const-trait-impl/assoc-type-const-bound-usage.rs b/src/test/ui/rfc-2632-const-trait-impl/assoc-type-const-bound-usage.rs new file mode 100644 index 000000000..780a510c5 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/assoc-type-const-bound-usage.rs @@ -0,0 +1,14 @@ +// check-pass +#![feature(const_trait_impl)] + +#[const_trait] +trait Foo { + type Assoc: ~const Foo; + fn foo() {} +} + +const fn foo<T: ~const Foo>() { + <T as Foo>::Assoc::foo(); +} + +fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/assoc-type.rs b/src/test/ui/rfc-2632-const-trait-impl/assoc-type.rs index 99eacaa83..7d9dae52c 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/assoc-type.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/assoc-type.rs @@ -10,6 +10,7 @@ impl std::ops::Add for NonConstAdd { } } +#[const_trait] trait Foo { type Bar: ~const std::ops::Add; } @@ -19,6 +20,7 @@ impl const Foo for NonConstAdd { //~^ ERROR: cannot add `NonConstAdd` to `NonConstAdd` in const contexts } +#[const_trait] trait Baz { type Qux: std::ops::Add; } diff --git a/src/test/ui/rfc-2632-const-trait-impl/assoc-type.stderr b/src/test/ui/rfc-2632-const-trait-impl/assoc-type.stderr index 64501c523..89177b0f1 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/assoc-type.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/assoc-type.stderr @@ -1,24 +1,20 @@ error[E0277]: cannot add `NonConstAdd` to `NonConstAdd` in const contexts - --> $DIR/assoc-type.rs:18:16 + --> $DIR/assoc-type.rs:19:16 | LL | type Bar = NonConstAdd; | ^^^^^^^^^^^ no implementation for `NonConstAdd + NonConstAdd` | = help: the trait `~const Add` is not implemented for `NonConstAdd` note: the trait `Add` is implemented for `NonConstAdd`, but that implementation is not `const` - --> $DIR/assoc-type.rs:18:16 + --> $DIR/assoc-type.rs:19:16 | LL | type Bar = NonConstAdd; | ^^^^^^^^^^^ note: required by a bound in `Foo::Bar` - --> $DIR/assoc-type.rs:14:15 + --> $DIR/assoc-type.rs:15:15 | LL | type Bar: ~const std::ops::Add; | ^^^^^^^^^^^^^^^^^^^^ required by this bound in `Foo::Bar` -help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement - | -LL | impl const Foo for NonConstAdd where NonConstAdd: ~const Add { - | +++++++++++++++++++++++++++++ error: aborting due to previous error diff --git a/src/test/ui/rfc-2632-const-trait-impl/auxiliary/staged-api.rs b/src/test/ui/rfc-2632-const-trait-impl/auxiliary/staged-api.rs index 19e900609..589e3f024 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/auxiliary/staged-api.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/auxiliary/staged-api.rs @@ -3,6 +3,7 @@ #![stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")] +#[const_trait] pub trait MyTrait { #[stable(feature = "rust1", since = "1.0.0")] fn func(); diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-fail.rs b/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-fail.rs index 24b9235bb..dd9933974 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-fail.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-fail.rs @@ -1,5 +1,6 @@ #![feature(const_trait_impl)] +#[const_trait] pub trait Plus { fn plus(self, rhs: Self) -> Self; } @@ -23,7 +24,6 @@ pub const fn add_i32(a: i32, b: i32) -> i32 { pub const fn add_u32(a: u32, b: u32) -> u32 { a.plus(b) //~^ ERROR the trait bound - //~| ERROR cannot call non-const fn } fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-fail.stderr b/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-fail.stderr index 1fc9db277..7350909ba 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-fail.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-fail.stderr @@ -1,24 +1,15 @@ error[E0277]: the trait bound `u32: ~const Plus` is not satisfied - --> $DIR/call-const-trait-method-fail.rs:24:7 + --> $DIR/call-const-trait-method-fail.rs:25:7 | LL | a.plus(b) - | ^^^^^^^ the trait `~const Plus` is not implemented for `u32` + | ^^^^ the trait `~const Plus` is not implemented for `u32` | note: the trait `Plus` is implemented for `u32`, but that implementation is not `const` - --> $DIR/call-const-trait-method-fail.rs:24:7 + --> $DIR/call-const-trait-method-fail.rs:25:7 | LL | a.plus(b) - | ^^^^^^^ + | ^^^^ -error[E0015]: cannot call non-const fn `<u32 as Plus>::plus` in constant functions - --> $DIR/call-const-trait-method-fail.rs:24:7 - | -LL | a.plus(b) - | ^^^^^^^ - | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - -error: aborting due to 2 previous errors +error: aborting due to previous error -Some errors have detailed explanations: E0015, E0277. -For more information about an error, try `rustc --explain E0015`. +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-pass.rs b/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-pass.rs index cf38bc3c9..b64161b6a 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-pass.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-pass.rs @@ -21,6 +21,7 @@ impl const PartialEq for Int { } } +#[const_trait] pub trait Plus { fn plus(self, rhs: Self) -> Self; } diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-in-impl.rs b/src/test/ui/rfc-2632-const-trait-impl/call-generic-in-impl.rs index 89dc47aad..50c465790 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/call-generic-in-impl.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-in-impl.rs @@ -1,6 +1,7 @@ // check-pass #![feature(const_trait_impl)] +#[const_trait] trait MyPartialEq { fn eq(&self, other: &Self) -> bool; } diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-fail.stderr b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-fail.stderr index 83d395dda..31e6dbdab 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-fail.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-fail.stderr @@ -9,7 +9,6 @@ note: the trait `PartialEq<_>` is implemented for `T`, but that implementation i | LL | *t == *t | ^^ - = help: the trait `PartialEq<&B>` is implemented for `&A` error: aborting due to previous error diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.rs b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.rs index d3e14a53a..414a8c87d 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.rs @@ -2,13 +2,18 @@ struct S; -impl PartialEq for S { +#[const_trait] +trait Foo { + fn eq(&self, _: &Self) -> bool; +} + +impl Foo for S { fn eq(&self, _: &S) -> bool { true } } -const fn equals_self<T: ~const PartialEq>(t: &T) -> bool { +const fn equals_self<T: ~const Foo>(t: &T) -> bool { true } diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr index 0a2a5f0f2..706f52343 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr @@ -1,26 +1,21 @@ -error[E0277]: can't compare `S` with `S` in const contexts - --> $DIR/call-generic-method-nonconst.rs:18:34 +error[E0277]: the trait bound `S: ~const Foo` is not satisfied + --> $DIR/call-generic-method-nonconst.rs:23:34 | LL | pub const EQ: bool = equals_self(&S); - | ----------- ^^ no implementation for `S == S` + | ----------- ^^ the trait `~const Foo` is not implemented for `S` | | | required by a bound introduced by this call | - = help: the trait `~const PartialEq` is not implemented for `S` -note: the trait `PartialEq` is implemented for `S`, but that implementation is not `const` - --> $DIR/call-generic-method-nonconst.rs:18:34 +note: the trait `Foo` is implemented for `S`, but that implementation is not `const` + --> $DIR/call-generic-method-nonconst.rs:23:34 | LL | pub const EQ: bool = equals_self(&S); | ^^ note: required by a bound in `equals_self` - --> $DIR/call-generic-method-nonconst.rs:11:25 - | -LL | const fn equals_self<T: ~const PartialEq>(t: &T) -> bool { - | ^^^^^^^^^^^^^^^^ required by this bound in `equals_self` -help: consider annotating `S` with `#[derive(PartialEq)]` - | -LL | #[derive(PartialEq)] + --> $DIR/call-generic-method-nonconst.rs:16:25 | +LL | const fn equals_self<T: ~const Foo>(t: &T) -> bool { + | ^^^^^^^^^^ required by this bound in `equals_self` error: aborting due to previous error diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-check-fns-in-const-impl.rs b/src/test/ui/rfc-2632-const-trait-impl/const-check-fns-in-const-impl.rs index b3e3dd62b..52984fb6b 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-check-fns-in-const-impl.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/const-check-fns-in-const-impl.rs @@ -1,6 +1,7 @@ #![feature(const_trait_impl)] struct S; +#[const_trait] trait T { fn foo(); } diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-check-fns-in-const-impl.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-check-fns-in-const-impl.stderr index 9e49785c5..c8783de4c 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-check-fns-in-const-impl.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/const-check-fns-in-const-impl.stderr @@ -1,5 +1,5 @@ error[E0015]: cannot call non-const fn `non_const` in constant functions - --> $DIR/const-check-fns-in-const-impl.rs:11:16 + --> $DIR/const-check-fns-in-const-impl.rs:12:16 | LL | fn foo() { non_const() } | ^^^^^^^^^^^ diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-default-method-bodies.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-default-method-bodies.stderr index fddc8d37f..c64930db9 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-default-method-bodies.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/const-default-method-bodies.stderr @@ -11,10 +11,6 @@ note: the trait `ConstDefaultFn` is implemented for `NonConstImpl`, but that imp | LL | NonConstImpl.a(); | ^^^^^^^^^^^^ -help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement - | -LL | const fn test() where NonConstImpl: ~const ConstDefaultFn { - | +++++++++++++++++++++++++++++++++++++++++ error: aborting due to previous error diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.precise.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.precise.stderr index 2295a822f..796c0d388 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.precise.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.precise.stderr @@ -1,5 +1,5 @@ error[E0277]: can't drop `NonTrivialDrop` in const contexts - --> $DIR/const-drop-fail.rs:43:5 + --> $DIR/const-drop-fail.rs:44:5 | LL | const _: () = check($exp); | ----- required by a bound introduced by this call @@ -9,7 +9,7 @@ LL | NonTrivialDrop, | = note: the trait bound `NonTrivialDrop: ~const Destruct` is not satisfied note: required by a bound in `check` - --> $DIR/const-drop-fail.rs:34:19 + --> $DIR/const-drop-fail.rs:35:19 | LL | const fn check<T: ~const Destruct>(_: T) {} | ^^^^^^^^^^^^^^^ required by this bound in `check` @@ -21,7 +21,7 @@ LL | &mut NonTrivialDrop, | ++++ error[E0277]: can't drop `NonTrivialDrop` in const contexts - --> $DIR/const-drop-fail.rs:45:5 + --> $DIR/const-drop-fail.rs:46:5 | LL | const _: () = check($exp); | ----- required by a bound introduced by this call @@ -30,7 +30,7 @@ LL | ConstImplWithDropGlue(NonTrivialDrop), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `ConstImplWithDropGlue`, the trait `~const Destruct` is not implemented for `NonTrivialDrop` | note: the trait `Destruct` is implemented for `NonTrivialDrop`, but that implementation is not `const` - --> $DIR/const-drop-fail.rs:45:5 + --> $DIR/const-drop-fail.rs:46:5 | LL | ConstImplWithDropGlue(NonTrivialDrop), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,39 +40,60 @@ note: required because it appears within the type `ConstImplWithDropGlue` LL | struct ConstImplWithDropGlue(NonTrivialDrop); | ^^^^^^^^^^^^^^^^^^^^^ note: required by a bound in `check` - --> $DIR/const-drop-fail.rs:34:19 + --> $DIR/const-drop-fail.rs:35:19 | LL | const fn check<T: ~const Destruct>(_: T) {} | ^^^^^^^^^^^^^^^ required by this bound in `check` -error[E0277]: the trait bound `ConstDropImplWithBounds<NonTrivialDrop>: ~const Destruct` is not satisfied - --> $DIR/const-drop-fail.rs:47:5 +error[E0277]: the trait bound `NonTrivialDrop: ~const A` is not satisfied + --> $DIR/const-drop-fail.rs:48:47 | -LL | const _: () = check($exp); - | ----- required by a bound introduced by this call -... LL | ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `~const Destruct` is not implemented for `ConstDropImplWithBounds<NonTrivialDrop>` + | ----------------------------------------- ^^^^^^^^^^^ the trait `~const A` is not implemented for `NonTrivialDrop` + | | + | required by a bound introduced by this call | -note: required for `ConstDropImplWithBounds<NonTrivialDrop>` to implement `~const Destruct` - --> $DIR/const-drop-fail.rs:28:25 +note: the trait `A` is implemented for `NonTrivialDrop`, but that implementation is not `const` + --> $DIR/const-drop-fail.rs:48:47 | -LL | impl<T: ~const A> const Drop for ConstDropImplWithBounds<T> { - | ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: 1 redundant requirement hidden - = note: required for `ConstDropImplWithBounds<NonTrivialDrop>` to implement `~const Destruct` -note: required by a bound in `check` - --> $DIR/const-drop-fail.rs:34:19 +LL | ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData), + | ^^^^^^^^^^^ +note: required by a bound in `ConstDropImplWithBounds` + --> $DIR/const-drop-fail.rs:27:35 | -LL | const fn check<T: ~const Destruct>(_: T) {} - | ^^^^^^^^^^^^^^^ required by this bound in `check` -help: consider borrowing here +LL | struct ConstDropImplWithBounds<T: ~const A>(PhantomData<T>); + | ^^^^^^^^ required by this bound in `ConstDropImplWithBounds` + +error[E0277]: the trait bound `NonTrivialDrop: ~const A` is not satisfied + --> $DIR/const-drop-fail.rs:48:5 | -LL | &ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData), - | + -LL | &mut ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData), - | ++++ +LL | ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `~const A` is not implemented for `NonTrivialDrop` + | +note: the trait `A` is implemented for `NonTrivialDrop`, but that implementation is not `const` + --> $DIR/const-drop-fail.rs:48:5 + | +LL | ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: required by a bound in `ConstDropImplWithBounds` + --> $DIR/const-drop-fail.rs:27:35 + | +LL | struct ConstDropImplWithBounds<T: ~const A>(PhantomData<T>); + | ^^^^^^^^ required by this bound in `ConstDropImplWithBounds` + +error[E0367]: `Drop` impl requires `T: ~const A` but the struct it is implemented for does not + --> $DIR/const-drop-fail.rs:55:9 + | +LL | impl<T: ~const A> const Drop for ConstDropImplWithNonConstBounds<T> { + | ^^^^^^^^ + | +note: the implementor must specify the same requirement + --> $DIR/const-drop-fail.rs:53:1 + | +LL | struct ConstDropImplWithNonConstBounds<T: A>(PhantomData<T>); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 3 previous errors +error: aborting due to 5 previous errors -For more information about this error, try `rustc --explain E0277`. +Some errors have detailed explanations: E0277, E0367. +For more information about an error, try `rustc --explain E0277`. diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.rs b/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.rs index 001dd430a..d36c7f81c 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.rs @@ -19,11 +19,12 @@ impl const Drop for ConstImplWithDropGlue { fn drop(&mut self) {} } -trait A { fn a() { println!("A"); } } +#[const_trait] +trait A { fn a() { } } impl A for NonTrivialDrop {} -struct ConstDropImplWithBounds<T: A>(PhantomData<T>); +struct ConstDropImplWithBounds<T: ~const A>(PhantomData<T>); impl<T: ~const A> const Drop for ConstDropImplWithBounds<T> { fn drop(&mut self) { @@ -46,6 +47,16 @@ check_all! { //~^ ERROR can't drop ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData), //~^ ERROR the trait bound + //~| ERROR the trait bound +} + +struct ConstDropImplWithNonConstBounds<T: A>(PhantomData<T>); + +impl<T: ~const A> const Drop for ConstDropImplWithNonConstBounds<T> { +//~^ ERROR `Drop` impl requires `T: ~const A` but the struct it is implemented for does not + fn drop(&mut self) { + T::a(); + } } fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.stock.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.stock.stderr index 2295a822f..796c0d388 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.stock.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.stock.stderr @@ -1,5 +1,5 @@ error[E0277]: can't drop `NonTrivialDrop` in const contexts - --> $DIR/const-drop-fail.rs:43:5 + --> $DIR/const-drop-fail.rs:44:5 | LL | const _: () = check($exp); | ----- required by a bound introduced by this call @@ -9,7 +9,7 @@ LL | NonTrivialDrop, | = note: the trait bound `NonTrivialDrop: ~const Destruct` is not satisfied note: required by a bound in `check` - --> $DIR/const-drop-fail.rs:34:19 + --> $DIR/const-drop-fail.rs:35:19 | LL | const fn check<T: ~const Destruct>(_: T) {} | ^^^^^^^^^^^^^^^ required by this bound in `check` @@ -21,7 +21,7 @@ LL | &mut NonTrivialDrop, | ++++ error[E0277]: can't drop `NonTrivialDrop` in const contexts - --> $DIR/const-drop-fail.rs:45:5 + --> $DIR/const-drop-fail.rs:46:5 | LL | const _: () = check($exp); | ----- required by a bound introduced by this call @@ -30,7 +30,7 @@ LL | ConstImplWithDropGlue(NonTrivialDrop), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `ConstImplWithDropGlue`, the trait `~const Destruct` is not implemented for `NonTrivialDrop` | note: the trait `Destruct` is implemented for `NonTrivialDrop`, but that implementation is not `const` - --> $DIR/const-drop-fail.rs:45:5 + --> $DIR/const-drop-fail.rs:46:5 | LL | ConstImplWithDropGlue(NonTrivialDrop), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -40,39 +40,60 @@ note: required because it appears within the type `ConstImplWithDropGlue` LL | struct ConstImplWithDropGlue(NonTrivialDrop); | ^^^^^^^^^^^^^^^^^^^^^ note: required by a bound in `check` - --> $DIR/const-drop-fail.rs:34:19 + --> $DIR/const-drop-fail.rs:35:19 | LL | const fn check<T: ~const Destruct>(_: T) {} | ^^^^^^^^^^^^^^^ required by this bound in `check` -error[E0277]: the trait bound `ConstDropImplWithBounds<NonTrivialDrop>: ~const Destruct` is not satisfied - --> $DIR/const-drop-fail.rs:47:5 +error[E0277]: the trait bound `NonTrivialDrop: ~const A` is not satisfied + --> $DIR/const-drop-fail.rs:48:47 | -LL | const _: () = check($exp); - | ----- required by a bound introduced by this call -... LL | ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData), - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `~const Destruct` is not implemented for `ConstDropImplWithBounds<NonTrivialDrop>` + | ----------------------------------------- ^^^^^^^^^^^ the trait `~const A` is not implemented for `NonTrivialDrop` + | | + | required by a bound introduced by this call | -note: required for `ConstDropImplWithBounds<NonTrivialDrop>` to implement `~const Destruct` - --> $DIR/const-drop-fail.rs:28:25 +note: the trait `A` is implemented for `NonTrivialDrop`, but that implementation is not `const` + --> $DIR/const-drop-fail.rs:48:47 | -LL | impl<T: ~const A> const Drop for ConstDropImplWithBounds<T> { - | ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: 1 redundant requirement hidden - = note: required for `ConstDropImplWithBounds<NonTrivialDrop>` to implement `~const Destruct` -note: required by a bound in `check` - --> $DIR/const-drop-fail.rs:34:19 +LL | ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData), + | ^^^^^^^^^^^ +note: required by a bound in `ConstDropImplWithBounds` + --> $DIR/const-drop-fail.rs:27:35 | -LL | const fn check<T: ~const Destruct>(_: T) {} - | ^^^^^^^^^^^^^^^ required by this bound in `check` -help: consider borrowing here +LL | struct ConstDropImplWithBounds<T: ~const A>(PhantomData<T>); + | ^^^^^^^^ required by this bound in `ConstDropImplWithBounds` + +error[E0277]: the trait bound `NonTrivialDrop: ~const A` is not satisfied + --> $DIR/const-drop-fail.rs:48:5 | -LL | &ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData), - | + -LL | &mut ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData), - | ++++ +LL | ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `~const A` is not implemented for `NonTrivialDrop` + | +note: the trait `A` is implemented for `NonTrivialDrop`, but that implementation is not `const` + --> $DIR/const-drop-fail.rs:48:5 + | +LL | ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: required by a bound in `ConstDropImplWithBounds` + --> $DIR/const-drop-fail.rs:27:35 + | +LL | struct ConstDropImplWithBounds<T: ~const A>(PhantomData<T>); + | ^^^^^^^^ required by this bound in `ConstDropImplWithBounds` + +error[E0367]: `Drop` impl requires `T: ~const A` but the struct it is implemented for does not + --> $DIR/const-drop-fail.rs:55:9 + | +LL | impl<T: ~const A> const Drop for ConstDropImplWithNonConstBounds<T> { + | ^^^^^^^^ + | +note: the implementor must specify the same requirement + --> $DIR/const-drop-fail.rs:53:1 + | +LL | struct ConstDropImplWithNonConstBounds<T: A>(PhantomData<T>); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 3 previous errors +error: aborting due to 5 previous errors -For more information about this error, try `rustc --explain E0277`. +Some errors have detailed explanations: E0277, E0367. +For more information about an error, try `rustc --explain E0277`. diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-drop.rs b/src/test/ui/rfc-2632-const-trait-impl/const-drop.rs index 04462c0a1..b0fc3adf9 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-drop.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/const-drop.rs @@ -48,6 +48,7 @@ mod t { pub struct HasConstDrop(pub ConstDrop); pub struct TrivialFields(pub u8, pub i8, pub usize, pub isize); + #[const_trait] pub trait SomeTrait { fn foo(); } @@ -59,7 +60,7 @@ mod t { fn foo() {} } - pub struct ConstDropWithBound<T: SomeTrait>(pub core::marker::PhantomData<T>); + pub struct ConstDropWithBound<T: ~const SomeTrait>(pub core::marker::PhantomData<T>); impl<T: ~const SomeTrait> const Drop for ConstDropWithBound<T> { fn drop(&mut self) { diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-impl-recovery.rs b/src/test/ui/rfc-2632-const-trait-impl/const-impl-recovery.rs index 470c653dd..837124db0 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-impl-recovery.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/const-impl-recovery.rs @@ -1,9 +1,11 @@ #![feature(const_trait_impl)] +#[const_trait] trait Foo {} const impl Foo for i32 {} //~ ERROR: expected identifier, found keyword +#[const_trait] trait Bar {} const impl<T: Foo> Bar for T {} //~ ERROR: expected identifier, found keyword diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-impl-recovery.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-impl-recovery.stderr index 709084c86..7217fc855 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-impl-recovery.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/const-impl-recovery.stderr @@ -1,5 +1,5 @@ error: expected identifier, found keyword `impl` - --> $DIR/const-impl-recovery.rs:5:7 + --> $DIR/const-impl-recovery.rs:6:7 | LL | const impl Foo for i32 {} | ^^^^ expected identifier, found keyword @@ -11,7 +11,7 @@ LL + impl const Foo for i32 {} | error: expected identifier, found keyword `impl` - --> $DIR/const-impl-recovery.rs:9:7 + --> $DIR/const-impl-recovery.rs:11:7 | LL | const impl<T: Foo> Bar for T {} | ^^^^ expected identifier, found keyword diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-impl-requires-const-trait.rs b/src/test/ui/rfc-2632-const-trait-impl/const-impl-requires-const-trait.rs new file mode 100644 index 000000000..2b4963991 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/const-impl-requires-const-trait.rs @@ -0,0 +1,9 @@ +#![feature(const_trait_impl)] + +pub trait A {} +//~^ HELP: mark `A` as const + +impl const A for () {} +//~^ ERROR: const `impl` for trait `A` which is not marked with `#[const_trait]` + +fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-impl-requires-const-trait.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-impl-requires-const-trait.stderr new file mode 100644 index 000000000..478adcf3e --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/const-impl-requires-const-trait.stderr @@ -0,0 +1,14 @@ +error: const `impl` for trait `A` which is not marked with `#[const_trait]` + --> $DIR/const-impl-requires-const-trait.rs:6:12 + | +LL | pub trait A {} + | - help: mark `A` as const: `#[const_trait]` +... +LL | impl const A for () {} + | ^ + | + = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` + = note: adding a non-const method body in the future would be a breaking change + +error: aborting due to previous error + diff --git a/src/test/ui/rfc-2632-const-trait-impl/cross-crate.gatednc.stderr b/src/test/ui/rfc-2632-const-trait-impl/cross-crate.gatednc.stderr index d4fa44b4b..925ae53e3 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/cross-crate.gatednc.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/cross-crate.gatednc.stderr @@ -11,10 +11,6 @@ note: the trait `cross_crate::MyTrait` is implemented for `cross_crate::NonConst | LL | NonConst.func(); | ^^^^^^^^ -help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement - | -LL | const fn const_context() where cross_crate::NonConst: ~const cross_crate::MyTrait { - | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ error: aborting due to previous error diff --git a/src/test/ui/rfc-2632-const-trait-impl/cross-crate.stocknc.stderr b/src/test/ui/rfc-2632-const-trait-impl/cross-crate.stocknc.stderr index 71ecd9b06..11db0c2b8 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/cross-crate.stocknc.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/cross-crate.stocknc.stderr @@ -11,10 +11,6 @@ note: the trait `cross_crate::MyTrait` is implemented for `cross_crate::NonConst | LL | NonConst.func(); | ^^^^^^^^ -help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement - | -LL | const fn const_context() where cross_crate::NonConst: ~const cross_crate::MyTrait { - | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ error: aborting due to previous error diff --git a/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-body-checking.rs b/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-body-checking.rs index d27291231..96acdc300 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-body-checking.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-body-checking.rs @@ -1,5 +1,6 @@ #![feature(const_trait_impl)] +#[const_trait] trait Tr {} impl Tr for () {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-body-checking.stderr b/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-body-checking.stderr index 7542b81fe..a244ab10c 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-body-checking.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-body-checking.stderr @@ -1,23 +1,19 @@ error[E0277]: the trait bound `(): ~const Tr` is not satisfied - --> $DIR/default-method-body-is-const-body-checking.rs:11:15 + --> $DIR/default-method-body-is-const-body-checking.rs:12:15 | LL | foo::<()>(); | ^^ the trait `~const Tr` is not implemented for `()` | note: the trait `Tr` is implemented for `()`, but that implementation is not `const` - --> $DIR/default-method-body-is-const-body-checking.rs:11:15 + --> $DIR/default-method-body-is-const-body-checking.rs:12:15 | LL | foo::<()>(); | ^^ note: required by a bound in `foo` - --> $DIR/default-method-body-is-const-body-checking.rs:6:28 + --> $DIR/default-method-body-is-const-body-checking.rs:7:28 | LL | const fn foo<T>() where T: ~const Tr {} | ^^^^^^^^^ required by this bound in `foo` -help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement - | -LL | pub trait Foo where (): ~const Tr { - | +++++++++++++++++++ error: aborting due to previous error diff --git a/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.stderr b/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.stderr index 85285ba84..c2c16921c 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.stderr @@ -11,10 +11,6 @@ note: the trait `Tr` is implemented for `()`, but that implementation is not `co | LL | ().a() | ^^ -help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement - | -LL | pub trait Tr where (): ~const Tr { - | +++++++++++++++++++ error: aborting due to previous error diff --git a/src/test/ui/rfc-2632-const-trait-impl/feature-gate.gated.stderr b/src/test/ui/rfc-2632-const-trait-impl/feature-gate.gated.stderr index af4d3909e..4c630d33c 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/feature-gate.gated.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/feature-gate.gated.stderr @@ -1,5 +1,5 @@ error: fatal error triggered by #[rustc_error] - --> $DIR/feature-gate.rs:13:1 + --> $DIR/feature-gate.rs:14:1 | LL | fn main() {} | ^^^^^^^^^ diff --git a/src/test/ui/rfc-2632-const-trait-impl/feature-gate.rs b/src/test/ui/rfc-2632-const-trait-impl/feature-gate.rs index 7bac72e1b..0b409fbaa 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/feature-gate.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/feature-gate.rs @@ -5,6 +5,7 @@ #![feature(rustc_attrs)] struct S; +#[const_trait] //[stock]~ ERROR `const_trait` is a temporary placeholder trait T {} impl const T for S {} //[stock]~^ ERROR const trait impls are experimental diff --git a/src/test/ui/rfc-2632-const-trait-impl/feature-gate.stock.stderr b/src/test/ui/rfc-2632-const-trait-impl/feature-gate.stock.stderr index 91a8bb578..0e938c1c5 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/feature-gate.stock.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/feature-gate.stock.stderr @@ -1,5 +1,5 @@ error[E0658]: const trait impls are experimental - --> $DIR/feature-gate.rs:9:6 + --> $DIR/feature-gate.rs:10:6 | LL | impl const T for S {} | ^^^^^ @@ -7,6 +7,15 @@ LL | impl const T for S {} = note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable -error: aborting due to previous error +error[E0658]: `const_trait` is a temporary placeholder for marking a trait that is suitable for `const` `impls` and all default bodies as `const`, which may be removed or renamed in the future. + --> $DIR/feature-gate.rs:8:1 + | +LL | #[const_trait] + | ^^^^^^^^^^^^^^ + | + = note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information + = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.rs b/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.rs index 80a4442de..337c73340 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.rs @@ -2,6 +2,7 @@ #![feature(const_trait_impl)] +#[const_trait] pub trait MyTrait { fn method(&self) -> Option<()>; } diff --git a/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.stderr b/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.stderr index 32df63e44..6d2be1daa 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.stderr @@ -1,5 +1,5 @@ error[E0658]: `?` is not allowed in a `const fn` - --> $DIR/hir-const-check.rs:11:9 + --> $DIR/hir-const-check.rs:12:9 | LL | Some(())?; | ^^^^^^^^^ diff --git a/src/test/ui/rfc-2632-const-trait-impl/inherent-impl-const-bounds.rs b/src/test/ui/rfc-2632-const-trait-impl/inherent-impl-const-bounds.rs index 2cef803a9..f8ac793e4 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/inherent-impl-const-bounds.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/inherent-impl-const-bounds.rs @@ -3,7 +3,9 @@ struct S; +#[const_trait] trait A {} +#[const_trait] trait B {} impl const A for S {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/issue-100222.rs b/src/test/ui/rfc-2632-const-trait-impl/issue-100222.rs index 1004bb28c..9f3f38ad4 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/issue-100222.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/issue-100222.rs @@ -16,6 +16,7 @@ pub trait IndexMut where Self: Index { impl Index for () { type Output = (); } +#[cfg(not(any(nn, yn)))] impl const IndexMut for <() as Index>::Output { const C: <Self as Index>::Output = (); type Assoc = <Self as Index>::Output; @@ -24,6 +25,15 @@ impl const IndexMut for <() as Index>::Output { {} } +#[cfg(any(nn, yn))] +impl IndexMut for <() as Index>::Output { + const C: <Self as Index>::Output = (); + type Assoc = <Self as Index>::Output; + fn foo(&mut self, x: <Self as Index>::Output) -> <Self as Index>::Output + where <Self as Index>::Output:, + {} +} + const C: <() as Index>::Output = (); fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/issue-102156.rs b/src/test/ui/rfc-2632-const-trait-impl/issue-102156.rs new file mode 100644 index 000000000..fe4e91081 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/issue-102156.rs @@ -0,0 +1,15 @@ +#![feature(allocator_api)] +#![feature(const_trait_impl)] + +use core::convert::{From, TryFrom}; +//~^ ERROR +//~| ERROR + +use std::pin::Pin; +use std::alloc::Allocator; +impl<T: ?Sized, A: Allocator> const From<Box<T, A>> for Pin<Box<T, A>> +where + A: 'static, +{} + +pub fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/issue-102156.stderr b/src/test/ui/rfc-2632-const-trait-impl/issue-102156.stderr new file mode 100644 index 000000000..8bf00eaff --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/issue-102156.stderr @@ -0,0 +1,19 @@ +error[E0433]: failed to resolve: maybe a missing crate `core`? + --> $DIR/issue-102156.rs:4:5 + | +LL | use core::convert::{From, TryFrom}; + | ^^^^ maybe a missing crate `core`? + | + = help: consider adding `extern crate core` to use the `core` crate + +error[E0433]: failed to resolve: maybe a missing crate `core`? + --> $DIR/issue-102156.rs:4:5 + | +LL | use core::convert::{From, TryFrom}; + | ^^^^ maybe a missing crate `core`? + | + = help: consider adding `extern crate core` to use the `core` crate + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0433`. diff --git a/src/test/ui/rfc-2632-const-trait-impl/issue-102985.rs b/src/test/ui/rfc-2632-const-trait-impl/issue-102985.rs new file mode 100644 index 000000000..07d3f51ed --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/issue-102985.rs @@ -0,0 +1,12 @@ +#![feature(const_trait_impl)] + +struct Bug { + inner: [(); match || 1 { + n => n(), + //~^ ERROR the trait bound + //~| ERROR the trait bound + //~| ERROR cannot call non-const closure in constants + }], +} + +fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/issue-102985.stderr b/src/test/ui/rfc-2632-const-trait-impl/issue-102985.stderr new file mode 100644 index 000000000..b98ccbe5d --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/issue-102985.stderr @@ -0,0 +1,41 @@ +error[E0277]: the trait bound `[closure@$DIR/issue-102985.rs:4:23: 4:25]: ~const Fn<()>` is not satisfied + --> $DIR/issue-102985.rs:5:14 + | +LL | n => n(), + | ^^^ expected an `Fn<()>` closure, found `[closure@$DIR/issue-102985.rs:4:23: 4:25]` + | + = help: the trait `~const Fn<()>` is not implemented for closure `[closure@$DIR/issue-102985.rs:4:23: 4:25]` +note: the trait `Fn<()>` is implemented for `[closure@$DIR/issue-102985.rs:4:23: 4:25]`, but that implementation is not `const` + --> $DIR/issue-102985.rs:5:14 + | +LL | n => n(), + | ^^^ + = note: wrap the `[closure@$DIR/issue-102985.rs:4:23: 4:25]` in a closure with no arguments: `|| { /* code */ }` + +error[E0277]: the trait bound `[closure@$DIR/issue-102985.rs:4:23: 4:25]: ~const Fn<()>` is not satisfied + --> $DIR/issue-102985.rs:5:14 + | +LL | n => n(), + | ^^^ expected an `Fn<()>` closure, found `[closure@$DIR/issue-102985.rs:4:23: 4:25]` + | + = help: the trait `~const Fn<()>` is not implemented for closure `[closure@$DIR/issue-102985.rs:4:23: 4:25]` +note: the trait `Fn<()>` is implemented for `[closure@$DIR/issue-102985.rs:4:23: 4:25]`, but that implementation is not `const` + --> $DIR/issue-102985.rs:5:14 + | +LL | n => n(), + | ^^^ + = note: wrap the `[closure@$DIR/issue-102985.rs:4:23: 4:25]` in a closure with no arguments: `|| { /* code */ }` + +error[E0015]: cannot call non-const closure in constants + --> $DIR/issue-102985.rs:5:14 + | +LL | n => n(), + | ^^^ + | + = note: closures need an RFC before allowed to be called in constants + = note: calls in constants are limited to constant functions, tuple structs and tuple variants + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0015, E0277. +For more information about an error, try `rustc --explain E0015`. diff --git a/src/test/ui/rfc-2632-const-trait-impl/issue-103677.rs b/src/test/ui/rfc-2632-const-trait-impl/issue-103677.rs new file mode 100644 index 000000000..d81724a36 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/issue-103677.rs @@ -0,0 +1,5 @@ +// check-pass + +const _: fn(&String) = |s| { &*s as &str; }; + +fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/issue-90052.rs b/src/test/ui/rfc-2632-const-trait-impl/issue-90052.rs new file mode 100644 index 000000000..21ddf4ab4 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/issue-90052.rs @@ -0,0 +1,9 @@ +#![feature(const_trait_impl)] + +#[const_trait] +trait Bar {} + +fn foo<T>() where T: ~const Bar {} +//~^ ERROR `~const` is not allowed + +fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/issue-90052.stderr b/src/test/ui/rfc-2632-const-trait-impl/issue-90052.stderr new file mode 100644 index 000000000..b2a936537 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/issue-90052.stderr @@ -0,0 +1,14 @@ +error: `~const` is not allowed here + --> $DIR/issue-90052.rs:6:22 + | +LL | fn foo<T>() where T: ~const Bar {} + | ^^^^^^^^^^ + | +note: this function is not `const`, so it cannot have `~const` trait bounds + --> $DIR/issue-90052.rs:6:4 + | +LL | fn foo<T>() where T: ~const Bar {} + | ^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/rfc-2632-const-trait-impl/issue-92230-wf-super-trait-env.rs b/src/test/ui/rfc-2632-const-trait-impl/issue-92230-wf-super-trait-env.rs index 97c27ce1a..4d3469653 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/issue-92230-wf-super-trait-env.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/issue-92230-wf-super-trait-env.rs @@ -4,7 +4,9 @@ #![feature(const_trait_impl)] +#[const_trait] pub trait Super {} +#[const_trait] pub trait Sub: Super {} impl<A> const Super for &A where A: ~const Super {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/nested-closure.rs b/src/test/ui/rfc-2632-const-trait-impl/nested-closure.rs new file mode 100644 index 000000000..a85113600 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/nested-closure.rs @@ -0,0 +1,12 @@ +// check-pass + +#![feature(const_trait_impl, once_cell)] + +use std::sync::LazyLock; + +static EXTERN_FLAGS: LazyLock<String> = LazyLock::new(|| { + let x = || String::new(); + x() +}); + +fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/non-const-op-in-closure-in-const.rs b/src/test/ui/rfc-2632-const-trait-impl/non-const-op-in-closure-in-const.rs index defef9e04..1a4509b18 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/non-const-op-in-closure-in-const.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/non-const-op-in-closure-in-const.rs @@ -2,6 +2,7 @@ #![feature(const_trait_impl)] +#[const_trait] trait Convert<T> { fn to(self) -> T; } diff --git a/src/test/ui/rfc-2632-const-trait-impl/specializing-constness-2.rs b/src/test/ui/rfc-2632-const-trait-impl/specializing-constness-2.rs new file mode 100644 index 000000000..633543700 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/specializing-constness-2.rs @@ -0,0 +1,31 @@ +#![feature(const_trait_impl, min_specialization, rustc_attrs)] + +#[rustc_specialization_trait] +#[const_trait] +pub trait Sup {} + +impl const Sup for () {} + +#[const_trait] +pub trait A { + fn a() -> u32; +} + +impl<T: Default> A for T { + default fn a() -> u32 { + 2 + } +} + +impl<T: Default + ~const Sup> const A for T { + fn a() -> u32 { + 3 + } +} + +const fn generic<T: Default>() { + <T as A>::a(); + //~^ ERROR: the trait bound `T: ~const Sup` is not satisfied +} + +fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/specializing-constness-2.stderr b/src/test/ui/rfc-2632-const-trait-impl/specializing-constness-2.stderr new file mode 100644 index 000000000..c554671e1 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/specializing-constness-2.stderr @@ -0,0 +1,19 @@ +error[E0277]: the trait bound `T: ~const Sup` is not satisfied + --> $DIR/specializing-constness-2.rs:27:5 + | +LL | <T as A>::a(); + | ^^^^^^^^^^^^^ the trait `~const Sup` is not implemented for `T` + | +note: required for `T` to implement `~const A` + --> $DIR/specializing-constness-2.rs:20:37 + | +LL | impl<T: Default + ~const Sup> const A for T { + | ^ ^ +help: consider further restricting this bound + | +LL | const fn generic<T: Default + ~const Sup>() { + | ++++++++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/rfc-2632-const-trait-impl/specializing-constness.rs b/src/test/ui/rfc-2632-const-trait-impl/specializing-constness.rs new file mode 100644 index 000000000..ff0cd489d --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/specializing-constness.rs @@ -0,0 +1,26 @@ +#![feature(const_trait_impl, min_specialization, rustc_attrs)] + +#[rustc_specialization_trait] +#[const_trait] +pub trait Sup {} + +impl const Sup for () {} + +#[const_trait] +pub trait A { + fn a() -> u32; +} + +impl<T: ~const Default> const A for T { + default fn a() -> u32 { + 2 + } +} + +impl<T: Default + Sup> A for T { //~ ERROR: cannot specialize + fn a() -> u32 { + 3 + } +} + +fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/specializing-constness.stderr b/src/test/ui/rfc-2632-const-trait-impl/specializing-constness.stderr new file mode 100644 index 000000000..3296c109c --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/specializing-constness.stderr @@ -0,0 +1,8 @@ +error: cannot specialize on trait `Default` + --> $DIR/specializing-constness.rs:20:9 + | +LL | impl<T: Default + Sup> A for T { + | ^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/rfc-2632-const-trait-impl/static-const-trait-bound.rs b/src/test/ui/rfc-2632-const-trait-impl/static-const-trait-bound.rs new file mode 100644 index 000000000..4520a3696 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/static-const-trait-bound.rs @@ -0,0 +1,18 @@ +// check-pass +pub struct S<T, F: FnOnce() -> T = fn() -> T> { + f: F, + x: Option<T>, +} + +impl<T, F: FnOnce() -> T> S<T, F> { + pub const fn new(f: F) -> Self { + Self { f, x: None } + } +} + +#[derive(Default)] +pub struct Foo; + +static LOCKED_CALLSITES: S<Foo> = S::new(Default::default); + +fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.nn.stderr b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.nn.stderr new file mode 100644 index 000000000..d4f42b787 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.nn.stderr @@ -0,0 +1,8 @@ +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/super-traits-fail-2.rs:11:19 + | +LL | trait Bar: ~const Foo {} + | ^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.ny.stderr b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.ny.stderr new file mode 100644 index 000000000..d4f42b787 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.ny.stderr @@ -0,0 +1,8 @@ +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/super-traits-fail-2.rs:11:19 + | +LL | trait Bar: ~const Foo {} + | ^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.rs b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.rs index 7b38c15af..d183efde2 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.rs @@ -1,14 +1,19 @@ #![feature(const_trait_impl)] +// revisions: yy yn ny nn + +#[cfg_attr(any(yy, yn), const_trait)] trait Foo { fn a(&self); } + +#[cfg_attr(any(yy, ny), const_trait)] trait Bar: ~const Foo {} +//[ny,nn]~^ ERROR: ~const can only be applied to `#[const_trait]` const fn foo<T: Bar>(x: &T) { x.a(); - //~^ ERROR the trait bound - //~| ERROR cannot call + //[yn,yy]~^ ERROR the trait bound } fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.stderr b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.stderr deleted file mode 100644 index 1766cdbee..000000000 --- a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.stderr +++ /dev/null @@ -1,24 +0,0 @@ -error[E0277]: the trait bound `T: ~const Foo` is not satisfied - --> $DIR/super-traits-fail-2.rs:9:7 - | -LL | x.a(); - | ^^^ the trait `~const Foo` is not implemented for `T` - | -note: the trait `Foo` is implemented for `T`, but that implementation is not `const` - --> $DIR/super-traits-fail-2.rs:9:7 - | -LL | x.a(); - | ^^^ - -error[E0015]: cannot call non-const fn `<T as Foo>::a` in constant functions - --> $DIR/super-traits-fail-2.rs:9:7 - | -LL | x.a(); - | ^^^ - | - = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants - -error: aborting due to 2 previous errors - -Some errors have detailed explanations: E0015, E0277. -For more information about an error, try `rustc --explain E0015`. diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.yn.stderr b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.yn.stderr new file mode 100644 index 000000000..b52eb2c03 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.yn.stderr @@ -0,0 +1,21 @@ +error[E0277]: the trait bound `T: ~const Foo` is not satisfied + --> $DIR/super-traits-fail-2.rs:15:5 + | +LL | x.a(); + | ^ - required by a bound introduced by this call + | | + | the trait `~const Foo` is not implemented for `T` + | +note: the trait `Foo` is implemented for `T`, but that implementation is not `const` + --> $DIR/super-traits-fail-2.rs:15:5 + | +LL | x.a(); + | ^ +help: consider further restricting this bound + | +LL | const fn foo<T: Bar + ~const Foo>(x: &T) { + | ++++++++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.yy.stderr b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.yy.stderr new file mode 100644 index 000000000..b52eb2c03 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.yy.stderr @@ -0,0 +1,21 @@ +error[E0277]: the trait bound `T: ~const Foo` is not satisfied + --> $DIR/super-traits-fail-2.rs:15:5 + | +LL | x.a(); + | ^ - required by a bound introduced by this call + | | + | the trait `~const Foo` is not implemented for `T` + | +note: the trait `Foo` is implemented for `T`, but that implementation is not `const` + --> $DIR/super-traits-fail-2.rs:15:5 + | +LL | x.a(); + | ^ +help: consider further restricting this bound + | +LL | const fn foo<T: Bar + ~const Foo>(x: &T) { + | ++++++++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-3.nn.stderr b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-3.nn.stderr new file mode 100644 index 000000000..d433e1cfa --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-3.nn.stderr @@ -0,0 +1,14 @@ +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/super-traits-fail-3.rs:12:19 + | +LL | trait Bar: ~const Foo {} + | ^^^ + +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/super-traits-fail-3.rs:15:24 + | +LL | const fn foo<T: ~const Bar>(x: &T) { + | ^^^ + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-3.ny.stderr b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-3.ny.stderr new file mode 100644 index 000000000..2a7e8e00b --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-3.ny.stderr @@ -0,0 +1,8 @@ +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/super-traits-fail-3.rs:12:19 + | +LL | trait Bar: ~const Foo {} + | ^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-3.rs b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-3.rs new file mode 100644 index 000000000..70d2936d3 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-3.rs @@ -0,0 +1,20 @@ +#![feature(const_trait_impl)] + +// revisions: yy yn ny nn +//[yy] check-pass + +#[cfg_attr(any(yy, yn), const_trait)] +trait Foo { + fn a(&self); +} + +#[cfg_attr(any(yy, ny), const_trait)] +trait Bar: ~const Foo {} +//[ny,nn]~^ ERROR: ~const can only be applied to `#[const_trait]` + +const fn foo<T: ~const Bar>(x: &T) { + //[yn,nn]~^ ERROR: ~const can only be applied to `#[const_trait]` + x.a(); +} + +fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-3.yn.stderr b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-3.yn.stderr new file mode 100644 index 000000000..e5978c12a --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-3.yn.stderr @@ -0,0 +1,8 @@ +error: ~const can only be applied to `#[const_trait]` traits + --> $DIR/super-traits-fail-3.rs:15:24 + | +LL | const fn foo<T: ~const Bar>(x: &T) { + | ^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.rs b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.rs index af465cad3..3e2b81368 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.rs @@ -1,8 +1,10 @@ #![feature(const_trait_impl)] +#[const_trait] trait Foo { fn a(&self); } +#[const_trait] trait Bar: ~const Foo {} struct S; diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.stderr b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.stderr index 9e8b8f8c6..1f8f312df 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.stderr @@ -1,23 +1,19 @@ error[E0277]: the trait bound `S: ~const Foo` is not satisfied - --> $DIR/super-traits-fail.rs:13:12 + --> $DIR/super-traits-fail.rs:15:12 | LL | impl const Bar for S {} | ^^^ the trait `~const Foo` is not implemented for `S` | note: the trait `Foo` is implemented for `S`, but that implementation is not `const` - --> $DIR/super-traits-fail.rs:13:12 + --> $DIR/super-traits-fail.rs:15:12 | LL | impl const Bar for S {} | ^^^ note: required by a bound in `Bar` - --> $DIR/super-traits-fail.rs:6:12 + --> $DIR/super-traits-fail.rs:8:12 | LL | trait Bar: ~const Foo {} | ^^^^^^^^^^ required by this bound in `Bar` -help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement - | -LL | impl const Bar for S where S: ~const Foo {} - | +++++++++++++++++++ error: aborting due to previous error diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits.rs b/src/test/ui/rfc-2632-const-trait-impl/super-traits.rs index aded4ca9a..df96f6fb4 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/super-traits.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits.rs @@ -1,9 +1,12 @@ // check-pass #![feature(const_trait_impl)] +#[const_trait] trait Foo { fn a(&self); } + +#[const_trait] trait Bar: ~const Foo {} struct S; diff --git a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-and-const-params.rs b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-and-const-params.rs new file mode 100644 index 000000000..78a64b901 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-and-const-params.rs @@ -0,0 +1,34 @@ +#![feature(const_trait_impl)] +#![feature(generic_arg_infer)] +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +struct Foo<const N: usize>; + +impl<const N: usize> Foo<N> { + fn add<A: ~const Add42>(self) -> Foo<{ A::add(N) }> { + Foo + } +} + +#[const_trait] +trait Add42 { + fn add(a: usize) -> usize; +} + +impl const Add42 for () { + fn add(a: usize) -> usize { + a + 42 + } +} + +fn bar<A: ~const Add42, const N: usize>(_: Foo<N>) -> Foo<{ A::add(N) }> { + //~^ ERROR `~const` is not allowed here + Foo +} + +fn main() { + let foo = Foo::<0>; + let foo = bar::<(), _>(foo); + let _foo = bar::<(), _>(foo); +} diff --git a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-and-const-params.stderr b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-and-const-params.stderr new file mode 100644 index 000000000..aae72f36e --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-and-const-params.stderr @@ -0,0 +1,14 @@ +error: `~const` is not allowed here + --> $DIR/tilde-const-and-const-params.rs:25:11 + | +LL | fn bar<A: ~const Add42, const N: usize>(_: Foo<N>) -> Foo<{ A::add(N) }> { + | ^^^^^^^^^^^^ + | +note: this function is not `const`, so it cannot have `~const` trait bounds + --> $DIR/tilde-const-and-const-params.rs:25:4 + | +LL | fn bar<A: ~const Add42, const N: usize>(_: Foo<N>) -> Foo<{ A::add(N) }> { + | ^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.rs b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.rs index b4302f3e7..5bd52151f 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.rs @@ -1,6 +1,7 @@ #![feature(const_trait_impl)] #![feature(associated_type_bounds)] +#[const_trait] trait T {} struct S; impl T for S {} @@ -17,12 +18,6 @@ fn rpit_assoc_bound() -> impl IntoIterator<Item: ~const T> { Some(S) } fn apit_assoc_bound(_: impl IntoIterator<Item: ~const T>) {} //~^ ERROR `~const` is not allowed -fn generic<P: ~const T>() {} -//~^ ERROR `~const` is not allowed - -fn where_clause<P>() where P: ~const T {} -//~^ ERROR `~const` is not allowed - struct TildeQuestion<T: ~const ?Sized>(std::marker::PhantomData<T>); //~^ ERROR `~const` and `?` are mutually exclusive diff --git a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr index 033ec21ba..84867cb4a 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr @@ -1,56 +1,40 @@ error: `~const` is not allowed here - --> $DIR/tilde-const-invalid-places.rs:8:19 + --> $DIR/tilde-const-invalid-places.rs:9:19 | LL | fn rpit() -> impl ~const T { S } | ^^^^^^^^ | - = note: only allowed on bounds on traits' associated types and functions, const fns, const impls and its associated functions + = note: `impl Trait`s cannot have `~const` trait bounds error: `~const` is not allowed here - --> $DIR/tilde-const-invalid-places.rs:11:17 + --> $DIR/tilde-const-invalid-places.rs:12:17 | LL | fn apit(_: impl ~const T) {} | ^^^^^^^^ | - = note: only allowed on bounds on traits' associated types and functions, const fns, const impls and its associated functions + = note: `impl Trait`s cannot have `~const` trait bounds error: `~const` is not allowed here - --> $DIR/tilde-const-invalid-places.rs:14:50 + --> $DIR/tilde-const-invalid-places.rs:15:50 | LL | fn rpit_assoc_bound() -> impl IntoIterator<Item: ~const T> { Some(S) } | ^^^^^^^^ | - = note: only allowed on bounds on traits' associated types and functions, const fns, const impls and its associated functions + = note: `impl Trait`s cannot have `~const` trait bounds error: `~const` is not allowed here - --> $DIR/tilde-const-invalid-places.rs:17:48 + --> $DIR/tilde-const-invalid-places.rs:18:48 | LL | fn apit_assoc_bound(_: impl IntoIterator<Item: ~const T>) {} | ^^^^^^^^ | - = note: only allowed on bounds on traits' associated types and functions, const fns, const impls and its associated functions - -error: `~const` is not allowed here - --> $DIR/tilde-const-invalid-places.rs:20:15 - | -LL | fn generic<P: ~const T>() {} - | ^^^^^^^^ - | - = note: only allowed on bounds on traits' associated types and functions, const fns, const impls and its associated functions - -error: `~const` is not allowed here - --> $DIR/tilde-const-invalid-places.rs:23:31 - | -LL | fn where_clause<P>() where P: ~const T {} - | ^^^^^^^^ - | - = note: only allowed on bounds on traits' associated types and functions, const fns, const impls and its associated functions + = note: `impl Trait`s cannot have `~const` trait bounds error: `~const` and `?` are mutually exclusive - --> $DIR/tilde-const-invalid-places.rs:26:25 + --> $DIR/tilde-const-invalid-places.rs:21:25 | LL | struct TildeQuestion<T: ~const ?Sized>(std::marker::PhantomData<T>); | ^^^^^^^^^^^^^ -error: aborting due to 7 previous errors +error: aborting due to 5 previous errors diff --git a/src/test/ui/rfc-2632-const-trait-impl/tilde_const_on_impl_bound.rs b/src/test/ui/rfc-2632-const-trait-impl/tilde_const_on_impl_bound.rs new file mode 100644 index 000000000..285cef571 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/tilde_const_on_impl_bound.rs @@ -0,0 +1,17 @@ +// check-pass +#![feature(const_trait_impl)] + +#[const_trait] +trait Foo { + fn foo(&self) {} +} + +struct Bar<T>(T); + +impl<T: ~const Foo> Bar<T> { + const fn foo(&self) { + self.0.foo() + } +} + +fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-const.rs b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-const.rs new file mode 100644 index 000000000..bfe98b98c --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-const.rs @@ -0,0 +1,31 @@ +// Like trait-where-clause.rs, but we are calling from a const context. +// Checking the validity of traits' where clauses happen at a later stage. +// (`rustc_const_eval` instead of `rustc_hir_analysis`) Therefore one file as a +// test is not enough. +#![feature(const_trait_impl)] + +#[const_trait] +trait Bar {} + +#[const_trait] +trait Foo { + fn a(); + fn b() where Self: ~const Bar; + fn c<T: ~const Bar>(); +} + +const fn test1<T: ~const Foo + Bar>() { + T::a(); + T::b(); + //~^ ERROR the trait bound + T::c::<T>(); + //~^ ERROR the trait bound +} + +const fn test2<T: ~const Foo + ~const Bar>() { + T::a(); + T::b(); + T::c::<T>(); +} + +fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-const.stderr b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-const.stderr new file mode 100644 index 000000000..f2846b6a6 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-const.stderr @@ -0,0 +1,35 @@ +error[E0277]: the trait bound `T: ~const Bar` is not satisfied + --> $DIR/trait-where-clause-const.rs:19:5 + | +LL | T::b(); + | ^^^^^^ the trait `~const Bar` is not implemented for `T` + | +note: the trait `Bar` is implemented for `T`, but that implementation is not `const` + --> $DIR/trait-where-clause-const.rs:19:5 + | +LL | T::b(); + | ^^^^^^ +help: consider further restricting this bound + | +LL | const fn test1<T: ~const Foo + Bar + ~const Bar>() { + | ++++++++++++ + +error[E0277]: the trait bound `T: ~const Bar` is not satisfied + --> $DIR/trait-where-clause-const.rs:21:5 + | +LL | T::c::<T>(); + | ^^^^^^^^^^^ the trait `~const Bar` is not implemented for `T` + | +note: the trait `Bar` is implemented for `T`, but that implementation is not `const` + --> $DIR/trait-where-clause-const.rs:21:5 + | +LL | T::c::<T>(); + | ^^^^^^^^^^^ +help: consider further restricting this bound + | +LL | const fn test1<T: ~const Foo + Bar + ~const Bar>() { + | ++++++++++++ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-run.rs b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-run.rs index b7cf9a13b..4b8b00406 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-run.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-run.rs @@ -2,6 +2,7 @@ #![feature(const_trait_impl)] +#[const_trait] trait Bar { fn bar() -> u8; } diff --git a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-self-referential.rs b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-self-referential.rs index acea58eae..3b028ac48 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-self-referential.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause-self-referential.rs @@ -2,6 +2,7 @@ #![feature(const_trait_impl)] +#[const_trait] trait Foo { fn bar() where Self: ~const Foo; } diff --git a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.rs b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.rs index d37ed3bb8..85ca5fc90 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.rs @@ -1,5 +1,6 @@ #![feature(const_trait_impl)] +#[const_trait] trait Bar {} trait Foo { @@ -8,7 +9,7 @@ trait Foo { fn c<T: ~const Bar>(); } -const fn test1<T: ~const Foo + Bar>() { +fn test1<T: Foo>() { T::a(); T::b(); //~^ ERROR the trait bound @@ -16,21 +17,7 @@ const fn test1<T: ~const Foo + Bar>() { //~^ ERROR the trait bound } -const fn test2<T: ~const Foo + ~const Bar>() { - T::a(); - T::b(); - T::c::<T>(); -} - -fn test3<T: Foo>() { - T::a(); - T::b(); - //~^ ERROR the trait bound - T::c::<T>(); - //~^ ERROR the trait bound -} - -fn test4<T: Foo + Bar>() { +fn test2<T: Foo + Bar>() { T::a(); T::b(); T::c::<T>(); diff --git a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr index fd5fe25dd..11f0c4016 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/trait-where-clause.stderr @@ -1,77 +1,35 @@ -error[E0277]: the trait bound `T: ~const Bar` is not satisfied - --> $DIR/trait-where-clause.rs:13:5 - | -LL | T::b(); - | ^^^^ the trait `~const Bar` is not implemented for `T` - | -note: the trait `Bar` is implemented for `T`, but that implementation is not `const` - --> $DIR/trait-where-clause.rs:13:5 - | -LL | T::b(); - | ^^^^ -note: required by a bound in `Foo::b` - --> $DIR/trait-where-clause.rs:7:24 - | -LL | fn b() where Self: ~const Bar; - | ^^^^^^^^^^ required by this bound in `Foo::b` -help: consider further restricting this bound - | -LL | const fn test1<T: ~const Foo + Bar + ~const Bar>() { - | ++++++++++++ - -error[E0277]: the trait bound `T: ~const Bar` is not satisfied - --> $DIR/trait-where-clause.rs:15:12 - | -LL | T::c::<T>(); - | ^ the trait `~const Bar` is not implemented for `T` - | -note: the trait `Bar` is implemented for `T`, but that implementation is not `const` - --> $DIR/trait-where-clause.rs:15:12 - | -LL | T::c::<T>(); - | ^ -note: required by a bound in `Foo::c` - --> $DIR/trait-where-clause.rs:8:13 - | -LL | fn c<T: ~const Bar>(); - | ^^^^^^^^^^ required by this bound in `Foo::c` -help: consider further restricting this bound - | -LL | const fn test1<T: ~const Foo + Bar + ~const Bar>() { - | ++++++++++++ - error[E0277]: the trait bound `T: Bar` is not satisfied - --> $DIR/trait-where-clause.rs:27:5 + --> $DIR/trait-where-clause.rs:14:5 | LL | T::b(); | ^^^^ the trait `Bar` is not implemented for `T` | note: required by a bound in `Foo::b` - --> $DIR/trait-where-clause.rs:7:24 + --> $DIR/trait-where-clause.rs:8:24 | LL | fn b() where Self: ~const Bar; | ^^^^^^^^^^ required by this bound in `Foo::b` help: consider further restricting this bound | -LL | fn test3<T: Foo + Bar>() { +LL | fn test1<T: Foo + Bar>() { | +++++ error[E0277]: the trait bound `T: Bar` is not satisfied - --> $DIR/trait-where-clause.rs:29:12 + --> $DIR/trait-where-clause.rs:16:12 | LL | T::c::<T>(); | ^ the trait `Bar` is not implemented for `T` | note: required by a bound in `Foo::c` - --> $DIR/trait-where-clause.rs:8:13 + --> $DIR/trait-where-clause.rs:9:13 | LL | fn c<T: ~const Bar>(); | ^^^^^^^^^^ required by this bound in `Foo::c` help: consider further restricting this bound | -LL | fn test3<T: Foo + Bar>() { +LL | fn test1<T: Foo + Bar>() { | +++++ -error: aborting due to 4 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0277`. |