-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
consts in patterns in const contexts with feature effects
causes warning (soon: error) about not implementing PartialEq
#119398
Comments
Because |
Yes, i understand that, but it still seems like a incorrect diagnostic. |
|
@fmease: What do you mean by that? That lint isn't recognizing a For the record, this code works: #![feature(derive_const, effects)]
#[derive_const(PartialEq)]
#[derive(Eq)] // `Eq` is not a const trait, so we must regular-derive it.
pub struct Y(u8);
pub const GREEN: Y = Y(4);
pub const fn is_green(x: Y) -> bool {
match x { GREEN => true, _ => false }
} |
Er, excuse me, but what is |
Revisiting this, yesterday I totally missed that the
- warning: to use a constant of type `Y` in a pattern, the type must implement `PartialEq`
+ warning: to use a constant of type `Y` in a pattern in a const context, the type must implement `const PartialEq`
--> src/main.rs:7:15
|
7 | match x { GREEN => true, _ => false }
| ^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #116122 <https://github.com/rust-lang/rust/issues/116122>
= note: `#[warn(const_patterns_without_partial_eq)]` on by default |
Oh, that's unfortunate, it's an auto-generated message. To clarify, it says likely internal (via). In this case, I don't think it's internal but simply an experimental feature without a tracking issue since the keyword generics / effects story is still ongoing.
|
effects
featureeffects
Hmm, nonetheless it's weird that we don't lint against that without |
effects
effects
causes warning (soon: error) about not implementing PartialEq
The lint will become a hard error when #120805 lands. Note that this code works on stable and has worked for quite a while: #[derive(Eq, PartialEq)]
pub struct TypeThatIsPartialEq(u8);
pub const GREEN: TypeThatIsPartialEq = TypeThatIsPartialEq(4);
pub const fn is_green(x: TypeThatIsPartialEq) -> bool {
match x { GREEN => true, _ => false }
} So, I think there's a bug with the |
No longer reproduces. |
Cc @compiler-errors who changed a bunch of stuff here recently. |
@RalfJung: This is a real fix, because we no longer erroneously require that It's still somewhat conceptually dissatisfying/strange, though. In an abstract sense, it kinda feels right that we enforce that |
Agreed. But it'd be a breaking change to do that now... so this is basically just a back-compat hack. |
Rollup merge of rust-lang#135064 - RalfJung:const-in-pat-partial-eq-not-const, r=compiler-errors const-in-pattern: test that the PartialEq impl does not need to be const Fixes rust-lang#119398 by adding a test. `@compiler-errors` is there some place in the code where we could add a comment saying "as a backcompat hack, here we only require `PartialEq` and not `const PartialEq`"? r? `@compiler-errors`
Code
Current output
Desired output
Rationale and extra context
the T is Derive(PartialEq); why does it warn?
Other cases
No response
Anything else?
as requested by @fmease
The text was updated successfully, but these errors were encountered: