ParamEnv should be const when ImplItem is within a const impl.

This commit is contained in:
Deadbeef 2021-11-29 22:21:38 +08:00
parent 8710a2e169
commit 87cd1ce6c1
No known key found for this signature in database
GPG key ID: 6D017A96D8E6C2F9
4 changed files with 58 additions and 30 deletions

View file

@ -1,6 +1,5 @@
// FIXME(fee1-dead): this should have a better error message
#![feature(const_trait_impl)]
// check-pass
struct NonConstAdd(i32);
impl std::ops::Add for NonConstAdd {
@ -17,7 +16,7 @@ trait Foo {
impl const Foo for NonConstAdd {
type Bar = NonConstAdd;
//TODO: ~^ ERROR
//~^ ERROR
}
trait Baz {

View file

@ -0,0 +1,20 @@
error[E0277]: cannot add `NonConstAdd` to `NonConstAdd`
--> $DIR/assoc-type.rs:18:5
|
LL | type Bar = NonConstAdd;
| ^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `NonConstAdd + NonConstAdd`
|
= help: the trait `Add` is not implemented for `NonConstAdd`
note: required by a bound in `Foo::Bar`
--> $DIR/assoc-type.rs:14:15
|
LL | type Bar: ~const std::ops::Add;
| ^^^^^^^^^^^^^^^^^^^^ required by this bound in `Foo::Bar`
help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement
|
LL | impl const Foo for NonConstAdd where NonConstAdd: Add {
| ++++++++++++++++++++++
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.