Closed
Description
This code using derive_const
(from #102049) doesn't compile because the expansion of the macro adds only a non ~const
trait bount to the impl block. cc @fee1-dead
playground
#![feature(derive_const)]
#![feature(const_trait_impl)]
#[derive_const(PartialEq)]
pub struct Reverse<T>(T);
fn main() {}
Using Compiler:
Nightly version: 1.69.0-nightly
(2023-02-06 e1eaa2d5d4d1f5b7b895)
Compiler Output
error[[E0277]](https://doc.rust-lang.org/nightly/error-index.html#E0277): can't compare `T` with `_` in const contexts
--> src/main.rs:5:23
|
4 | #[derive_const(PartialEq)]
| --------- in this derive macro expansion
5 | pub struct Reverse<T>(T);
| ^ no implementation for `T == _`
|
note: the trait `PartialEq<_>` is implemented for `T`, but that implementation is not `const`
--> src/main.rs:5:23
|
4 | #[derive_const(PartialEq)]
| --------- in this derive macro expansion
5 | pub struct Reverse<T>(T);
| ^
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` due to previous error
Macro Expansion
#![feature(prelude_import)]
#![feature(derive_const)]
#![feature(const_trait_impl)]
#[prelude_import]
use std::prelude::rust_2021::*;
#[macro_use]
extern crate std;
pub struct Reverse<T>(T);
#[automatically_derived]
impl<T> ::core::marker::StructuralPartialEq for Reverse<T> { }
#[automatically_derived]
impl<T: ::core::cmp::PartialEq> const ::core::cmp::PartialEq for Reverse<T> {
#[inline]
fn eq(&self, other: &Reverse<T>) -> bool { self.0 == other.0 }
}
fn main() {}