-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Const qualification for StructuralEq
#67343
Const qualification for StructuralEq
#67343
Conversation
748dfd0
to
75514ef
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
75514ef
to
31772ed
Compare
This comment has been minimized.
This comment has been minimized.
31772ed
to
db05be7
Compare
This comment has been minimized.
This comment has been minimized.
db05be7
to
6190dc6
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
6190dc6
to
3170ed3
Compare
This comment has been minimized.
This comment has been minimized.
3170ed3
to
338152c
Compare
StructuralEq
StructuralEq
@pnkfelix I've updated the PR description and this is now ready for review. |
LL | match Some(NoDerive) { NoDerive::ASSOC => dbg!(NoDerive::ASSOC), _ => panic!("whoops"), }; | ||
| ^^^^^^^^^^^^^^^ | ||
|
||
error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that these error messages are repeated for some reason. This does not happen on nightly, or when I run the test using rustc +stage1
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we don't deduplicate errors when running compiletest
? Tests like ui/consts/match_ice.rs
also have repeated output on master
.
b02f8b2
to
900cf82
Compare
@bors r=pnkfelix I believe I've addressed everything above that needed immediate attention. One |
📌 Commit e4c650c has been approved by |
☀️ Test successful - checks-azure |
📣 Toolstate changed by #67343! Tested on commit 36d13cb. 🎉 rustc-dev-guide on linux: test-fail → test-pass (cc @JohnTitor @amanjeev @spastorino @mark-i-m). |
Tested on commit rust-lang/rust@36d13cb. Direct link to PR: <rust-lang/rust#67343> 🎉 rustc-dev-guide on linux: test-fail → test-pass (cc @JohnTitor @amanjeev @spastorino @mark-i-m).
As expected, this was a perf regression of up to 6% on |
Furthers #62411. Resolves #62614.
The goal of this PR is to implement the logic in #67088 on the MIR instead of the HIR. It uses the
Qualif
trait to trackStructuralPartialEq
/StructuralEq
in the final value of aconst
. Then, if we encounter a constant during HAIR lowering whose value may not be structurally matchable, we emit theindirect_structural_match
lint.This PR contains all the tests present in #67088 and emits the proper warnings for the corner cases. This PR does not handle #65466, which would require that we be more aggressive when checking matched types for
PartialEq
. I think that should be done separately.Because this works on MIR and uses dataflow, this PR should accept more cases than #67088. Notably, the qualifs in the final value of a const are encoded cross-crate, so matching on a constant whose value is defined in another crate to be
Option::<TyWithCustomEqImpl>::None
should work. Additionally, if aconst
has branching/looping, we will only emit the warning if any possible control flow path could result in a type with a customPartialEq
impl ending up as the final value of aconst
. I'm not sure how #67088 handled this.AFAIK, it's not settled that these are the semantics we actually want: it's just how the
Qualif
framework happens to work. If the cross-crate part is undesirable, it would be quite easy to change the result ofmir_const_qualif().custom_eq
totrue
before encoding it in the crate metadata. This way, other crates would have to assume that all publicly exported constants may not be safe for matching.r? @pnkfelix
cc @eddyb