-
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
base: master
Are you sure you want to change the base?
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 |
r? @fee1-dead or @compiler-errors
something generally useful but also required for #142789