Skip to content

correctly lower impl const to bind to host effect param #114545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bless tests
  • Loading branch information
fee1-dead committed Aug 6, 2023
commit 6c1e3bb6e97f4c6d760859c4e804f98b8cc64fe2
2 changes: 1 addition & 1 deletion tests/ui/const-generics/const_trait_fn-issue-88433.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// build-pass

#![feature(const_trait_impl)]
#![feature(const_trait_impl, effects)]

#[const_trait]
trait Func<T> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
error: const `impl` for trait `Add` which is not marked with `#[const_trait]`
--> $DIR/unify-op-with-fn-call.rs:10:12
error[E0741]: `Foo` must implement `ConstParamTy` to be used as the type of a const generic parameter
--> $DIR/unify-op-with-fn-call.rs:18:29
|
LL | impl const std::ops::Add for Foo {
| ^^^^^^^^^^^^^
LL | struct Evaluatable<const N: Foo>;
| ^^^
|
help: add `#[derive(ConstParamTy)]` to the struct
|
LL + #[derive(ConstParamTy)]
LL | struct Foo(u8);
|

error[E0741]: `Foo` must implement `ConstParamTy` to be used as the type of a const generic parameter
--> $DIR/unify-op-with-fn-call.rs:20:17
|
LL | fn foo<const N: Foo>(a: Evaluatable<{ N + N }>) {
| ^^^
|
help: add `#[derive(ConstParamTy)]` to the struct
|
LL + #[derive(ConstParamTy)]
LL | struct Foo(u8);
|

error[E0741]: `Foo` must implement `ConstParamTy` to be used as the type of a const generic parameter
--> $DIR/unify-op-with-fn-call.rs:24:17
|
LL | fn bar<const N: Foo>() {}
| ^^^
|
help: add `#[derive(ConstParamTy)]` to the struct
|
LL + #[derive(ConstParamTy)]
LL | struct Foo(u8);
|
= 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
error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0741`.
33 changes: 21 additions & 12 deletions tests/ui/consts/const-try.stderr
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
error: const `impl` for trait `FromResidual` which is not marked with `#[const_trait]`
--> $DIR/const-try.rs:15:12
error[E0015]: `?` cannot determine the branch of `TryMe` in constant functions
--> $DIR/const-try.rs:33:5
|
LL | impl const FromResidual<Error> for TryMe {
| ^^^^^^^^^^^^^^^^^^^
LL | TryMe?;
| ^^^^^^
|
= 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: const `impl` for trait `Try` which is not marked with `#[const_trait]`
--> $DIR/const-try.rs:21:12
note: impl defined here, but it is not `const`
--> $DIR/const-try.rs:21:1
|
LL | impl const Try for TryMe {
| ^^^
| ^^^^^^^^^^^^^^^^^^^^^^^^
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants

error[E0015]: `?` cannot convert from residual of `TryMe` in constant functions
--> $DIR/const-try.rs:33:5
|
= 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
LL | TryMe?;
| ^^^^^^
|
note: impl defined here, but it is not `const`
--> $DIR/const-try.rs:15:1
|
LL | impl const FromResidual<Error> for TryMe {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0015`.
2 changes: 1 addition & 1 deletion tests/ui/consts/rustc-impl-const-stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#![crate_type = "lib"]
#![feature(staged_api)]
#![feature(const_trait_impl)]
#![feature(const_trait_impl, effects)]
#![stable(feature = "foo", since = "1.0.0")]

#[stable(feature = "potato", since = "1.27.0")]
Expand Down
19 changes: 18 additions & 1 deletion tests/ui/consts/rustc-impl-const-stability.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,22 @@ LL | impl const Default for Data {
= 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
error[E0107]: missing generics for trait `Default`
--> $DIR/rustc-impl-const-stability.rs:15:12
|
LL | impl const Default for Data {
| ^^^^^^^ expected 18446744073709551615 generic arguments

error[E0207]: the const parameter `host` is not constrained by the impl trait, self type, or predicates
--> $DIR/rustc-impl-const-stability.rs:15:6
|
LL | impl const Default for Data {
| ^^^^^ unconstrained const parameter
|
= note: expressions using a const parameter must map each value to a distinct output value
= note: proving the result of expressions other than the parameter are unique is not supported

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0107, E0207.
For more information about an error, try `rustc --explain E0107`.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(const_trait_impl)]
#![feature(const_trait_impl, effects)]

#[const_trait]
pub trait MyTrait {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(const_trait_impl)]
#![feature(const_trait_impl, effects)]
#![feature(staged_api)]
#![stable(feature = "rust1", since = "1.0.0")]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(const_trait_impl)]
#![feature(const_trait_impl, effects)]

#[const_trait]
pub trait Plus {
Expand All @@ -23,7 +23,7 @@ pub const fn add_i32(a: i32, b: i32) -> i32 {

pub const fn add_u32(a: u32, b: u32) -> u32 {
a.plus(b)
//~^ ERROR cannot call
//~^ ERROR the trait bound
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0015]: cannot call non-const fn `<u32 as Plus>::plus` in constant functions
error[E0277]: the trait bound `u32: ~const Plus` is not satisfied
--> $DIR/call-const-trait-method-fail.rs:25:7
|
LL | a.plus(b)
| ^^^^^^^
| ^^^^ the trait `Plus` is not implemented for `u32`
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= help: the trait `Plus` is implemented for `u32`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0015`.
For more information about this error, try `rustc --explain E0277`.
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
error: const `impl` for trait `Add` which is not marked with `#[const_trait]`
--> $DIR/call-const-trait-method-pass.rs:7:12
error[E0015]: cannot call non-const fn `<i32 as Plus>::plus` in constant functions
--> $DIR/call-const-trait-method-pass.rs:36:7
|
LL | impl const std::ops::Add for Int {
| ^^^^^^^^^^^^^
LL | a.plus(b)
| ^^^^^^^
|
= 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
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants

error: const `impl` for trait `PartialEq` which is not marked with `#[const_trait]`
--> $DIR/call-const-trait-method-pass.rs:15:12
error[E0015]: cannot call non-const operator in constants
--> $DIR/call-const-trait-method-pass.rs:39:22
|
LL | const ADD_INT: Int = Int(1i32) + Int(2i32);
| ^^^^^^^^^^^^^^^^^^^^^
|
LL | impl const PartialEq for Int {
| ^^^^^^^^^
note: impl defined here, but it is not `const`
--> $DIR/call-const-trait-method-pass.rs:7:1
|
= 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
LL | impl const std::ops::Add for Int {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: calls in constants are limited to constant functions, tuple structs and tuple variants

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0015`.
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
error: const `impl` for trait `PartialEq` which is not marked with `#[const_trait]`
--> $DIR/call-generic-method-chain.rs:9:12
|
LL | impl const PartialEq for S {
| ^^^^^^^^^
|
= 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: ~const can only be applied to `#[const_trait]` traits
--> $DIR/call-generic-method-chain.rs:18:32
|
Expand All @@ -19,5 +10,5 @@ error: ~const can only be applied to `#[const_trait]` traits
LL | const fn equals_self_wrapper<T: ~const PartialEq>(t: &T) -> bool {
| ^^^^^^^^^

error: aborting due to 3 previous errors
error: aborting due to 2 previous errors

Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
error: const `impl` for trait `PartialEq` which is not marked with `#[const_trait]`
--> $DIR/call-generic-method-dup-bound.rs:7:12
|
LL | impl const PartialEq for S {
| ^^^^^^^^^
|
= 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: ~const can only be applied to `#[const_trait]` traits
--> $DIR/call-generic-method-dup-bound.rs:18:44
|
Expand All @@ -19,5 +10,5 @@ error: ~const can only be applied to `#[const_trait]` traits
LL | const fn equals_self2<T: A + ~const PartialEq>(t: &T) -> bool {
| ^^^^^^^^^

error: aborting due to 3 previous errors
error: aborting due to 2 previous errors

Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
error: const `impl` for trait `PartialEq` which is not marked with `#[const_trait]`
--> $DIR/call-generic-method-pass.rs:9:12
|
LL | impl const PartialEq for S {
| ^^^^^^^^^
|
= 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: ~const can only be applied to `#[const_trait]` traits
--> $DIR/call-generic-method-pass.rs:18:32
|
LL | const fn equals_self<T: ~const PartialEq>(t: &T) -> bool {
| ^^^^^^^^^

error: aborting due to 2 previous errors
error: aborting due to previous error

Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
error: const `impl` for trait `Add` which is not marked with `#[const_trait]`
--> $DIR/const-and-non-const-impl.rs:7:12
error[E0117]: only traits defined in the current crate can be implemented for primitive types
--> $DIR/const-and-non-const-impl.rs:7:1
|
LL | impl const std::ops::Add for i32 {
| ^^^^^^^^^^^^^
| ^^^^^^^^^^^-------------^^^^^---
| | | |
| | | `i32` is not defined in the current crate
| | `i32` is not defined in the current crate
| impl doesn't use only types from inside the current crate
|
= 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
= note: define and implement a trait or new type instead

error: const `impl` for trait `Add` which is not marked with `#[const_trait]`
--> $DIR/const-and-non-const-impl.rs:23:12
error[E0119]: conflicting implementations of trait `Add` for type `Int`
--> $DIR/const-and-non-const-impl.rs:23:1
|
LL | impl std::ops::Add for Int {
| -------------------------- first implementation here
...
LL | impl const std::ops::Add for Int {
| ^^^^^^^^^^^^^
|
= 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
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Int`

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0117, E0119.
For more information about an error, try `rustc --explain E0117`.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(const_trait_impl)]
#![feature(const_trait_impl, effects)]

struct S;
#[const_trait]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(const_trait_impl)]
#![feature(const_trait_impl, effects)]

#[const_trait]
trait ConstDefaultFn: Sized {
Expand All @@ -22,7 +22,7 @@ impl const ConstDefaultFn for ConstImpl {

const fn test() {
NonConstImpl.a();
//~^ ERROR cannot call
//~^ ERROR the trait bound
ConstImpl.a();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0015]: cannot call non-const fn `<NonConstImpl as ConstDefaultFn>::a` in constant functions
error[E0277]: the trait bound `NonConstImpl: ~const ConstDefaultFn` is not satisfied
--> $DIR/const-default-method-bodies.rs:24:18
|
LL | NonConstImpl.a();
| ^^^
| ^ the trait `ConstDefaultFn` is not implemented for `NonConstImpl`
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
= help: the trait `ConstDefaultFn` is implemented for `NonConstImpl`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0015`.
For more information about this error, try `rustc --explain E0277`.
9 changes: 6 additions & 3 deletions tests/ui/rfcs/rfc-2632-const-trait-impl/const-drop-fail-2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// known-bug: #110395
#![feature(const_trait_impl, effects)]
#![feature(const_trait_impl)]
#![feature(const_mut_refs)]
#![cfg_attr(precise, feature(const_precise_live_drops))]

Expand All @@ -18,6 +18,10 @@ trait A { fn a() { } }

impl A for NonTrivialDrop {}

const fn check<T: ~const Destruct>(_: T) {}


/* FIXME(effects)
struct ConstDropImplWithBounds<T: ~const A>(PhantomData<T>);

impl<T: ~const A> const Drop for ConstDropImplWithBounds<T> {
Expand All @@ -26,11 +30,10 @@ impl<T: ~const A> const Drop for ConstDropImplWithBounds<T> {
}
}

const fn check<T: ~const Destruct>(_: T) {}

const _: () = check::<ConstDropImplWithBounds<NonTrivialDrop>>(
ConstDropImplWithBounds(PhantomData)
);
*/

struct ConstDropImplWithNonConstBounds<T: A>(PhantomData<T>);

Expand Down
Loading