Skip to content
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

#[derive_const] adding a non ~const trait bound #107774

Closed
onestacked opened this issue Feb 7, 2023 · 0 comments · Fixed by #107777
Closed

#[derive_const] adding a non ~const trait bound #107774

onestacked opened this issue Feb 7, 2023 · 0 comments · Fixed by #107777
Assignees
Labels
C-bug Category: This is a bug.

Comments

@onestacked
Copy link
Contributor

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() {}

@onestacked onestacked added the C-bug Category: This is a bug. label Feb 7, 2023
@compiler-errors compiler-errors self-assigned this Feb 7, 2023
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Feb 8, 2023
…lly-derive-const, r=fee1-dead

Make `derive_const` derive properly const-if-const impls

Fixes rust-lang#107774
Fixes rust-lang#107666

Also fixes rendering of const-if-const bounds in pretty printing.

r? `@oli-obk` or `@fee1-dead`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 8, 2023
…lly-derive-const, r=fee1-dead

Make `derive_const` derive properly const-if-const impls

Fixes rust-lang#107774
Fixes rust-lang#107666

Also fixes rendering of const-if-const bounds in pretty printing.

r? ``@oli-obk`` or ``@fee1-dead``
@bors bors closed this as completed in 5b8403c Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants