-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Make PartialEq
a const_trait
#142822
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
Make PartialEq
a const_trait
#142822
Conversation
|
Dupe of #133995 |
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.
this is no longer testing the issue - can we change this to another one that still shows the errors? or just remove this test completely (or just have const_trait_impl removed in this test)
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.
This also means
rust/compiler/rustc_const_eval/src/check_consts/ops.rs
Lines 281 to 316 in 9972ebf
let mut sugg = None; | |
if ccx.tcx.is_lang_item(trait_id, LangItem::PartialEq) { | |
match (args[0].kind(), args[1].kind()) { | |
(GenericArgKind::Type(self_ty), GenericArgKind::Type(rhs_ty)) | |
if self_ty == rhs_ty | |
&& self_ty.is_ref() | |
&& self_ty.peel_refs().is_primitive() => | |
{ | |
let mut num_refs = 0; | |
let mut tmp_ty = self_ty; | |
while let rustc_middle::ty::Ref(_, inner_ty, _) = tmp_ty.kind() { | |
num_refs += 1; | |
tmp_ty = *inner_ty; | |
} | |
let deref = "*".repeat(num_refs); | |
if let Ok(call_str) = ccx.tcx.sess.source_map().span_to_snippet(span) { | |
if let Some(eq_idx) = call_str.find("==") { | |
if let Some(rhs_idx) = | |
call_str[(eq_idx + 2)..].find(|c: char| !c.is_whitespace()) | |
{ | |
let rhs_pos = | |
span.lo() + BytePos::from_usize(eq_idx + 2 + rhs_idx); | |
let rhs_span = span.with_lo(rhs_pos).with_hi(rhs_pos); | |
sugg = Some(errors::ConsiderDereferencing { | |
deref, | |
span: span.shrink_to_lo(), | |
rhs_span, | |
}); | |
} | |
} | |
} | |
} | |
_ => {} | |
} |
f693135
to
9933442
Compare
@bors r+ rollup |
Make `PartialEq` a `const_trait` r? `@fee1-dead` or `@compiler-errors` something generally useful but also required for rust-lang#142789
Rollup of 5 pull requests Successful merges: - #142493 (rework `#[naked]` attribute parser) - #142636 (bootstrap.example.toml: use less contextual format) - #142822 (Make `PartialEq` a `const_trait`) - #142892 (Fix ICE on debug builds where lints are delayed on the crate root) - #142904 (notify me when rdg is touched) Failed merges: - #142827 (Move error code explanation removal check into tidy) r? `@ghost` `@rustbot` modify labels: rollup
r? @fee1-dead or @compiler-errors
something generally useful but also required for #142789