Closed
Description
Not sure whether this has been reported before.
I tried this code:
#![feature(const_generics)]
#![feature(structural_match)]
use std::marker::{StructuralPartialEq, StructuralEq};
struct Container<T: StructuralPartialEq + StructuralEq, const V: T>;
fn main() {
let container1: Container<i32, {42}> = Container;
let container2: Container<&'static str, "Hello world"> = Container;
}
I expected to see this happen: The compile passes.
Instead, this happened:
error[E0741]: the types of const generic parameters must derive `PartialEq` and `Eq`
--> src/main.rs:6:66
|
6 | struct Container<T: StructuralPartialEq + StructuralEq, const V: T>;
| ^ `T` doesn't derive both `PartialEq` and `Eq`
Meta
rustc --version --verbose
:
Nightly channel
Build using the Nightly version: 1.44.0-nightly
(2020-04-21 45d050cde277b22a7558)
Backtrace
<backtrace>
@rustbot modify labels to +A-const generics F-const generics T-compiler requires-nightly
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
rustbot commentedon Apr 22, 2020
Error: Label generics can only be set by Rust team members
Please let
@rust-lang/release
know if you're having trouble with this bot.crlf0710 commentedon Apr 22, 2020
@rustbot modify labels to +A-const-generics F-const_generics T-compiler requires-nightly
crlf0710 commentedon Apr 22, 2020
This also doesn't work.
varkor commentedon Apr 22, 2020
I'm pretty sure
StructuralPartialEq
andStructuralEq
are not supposed to be public like this… it's not valid to claim that an arbitrary type isstructural_match
. I don't expect this to work.cc @pnkfelix @eddyb
lcnr commentedon Apr 22, 2020
We don't allow const paramters with generic types at all afaik. So while the error message is misleading, I don't think that this will work soon.
varkor commentedon Apr 22, 2020
Right. This will actually be improved by #70845, which makes this explicit.
crlf0710 commentedon Apr 23, 2020
Thanks. Is this a language limitation or implementation limitation? Will lazy normalization allow this to be written?
varkor commentedon Apr 23, 2020
It won't be supported after lazy normalisation specifically, but we would like to be able to use const parameters with generic types eventually.
vmarkushin commentedon Dec 25, 2020
Also consider this example
lcnr commentedon Dec 25, 2020
@vmarkushin can you open a separate issue for this as your example seems distinct enough to be tracked separately?
4 remaining items