1
Fork 0

Better error for non const PartialEq call generated by match

This commit is contained in:
Deadbeef 2023-06-18 05:24:38 +00:00
parent ed7281e784
commit 89c24af133
35 changed files with 211 additions and 100 deletions

View file

@ -512,6 +512,31 @@ pub struct CopyNonOverlapping<'tcx> {
pub count: Operand<'tcx>,
}
/// Represents how a `TerminatorKind::Call` was constructed, used for diagnostics
#[derive(Clone, Copy, TyEncodable, TyDecodable, Debug, PartialEq, Hash, HashStable)]
#[derive(TypeFoldable, TypeVisitable)]
pub enum CallSource {
/// This came from something such as `a > b` or `a + b`. In THIR, if `from_hir_call`
/// is false then this is the desugaring.
OverloadedOperator,
/// This was from comparison generated by a match, used by const-eval for better errors
/// when the comparison cannot be done in compile time.
///
/// See https://github.com/rust-lang/rust/issues/90237.
MatchCmp,
/// Other types of desugaring that did not come from the HIR, but we don't care about
/// for diagnostics (yet).
Misc,
/// Normal function call, no special source
Normal,
}
impl CallSource {
pub fn from_hir_call(self) -> bool {
matches!(self, CallSource::Normal)
}
}
///////////////////////////////////////////////////////////////////////////
// Terminators
@ -638,11 +663,10 @@ pub enum TerminatorKind<'tcx> {
target: Option<BasicBlock>,
/// Action to be taken if the call unwinds.
unwind: UnwindAction,
/// `true` if this is from a call in HIR rather than from an overloaded
/// operator. True for overloaded function call.
from_hir_call: bool,
/// Where this call came from in HIR/THIR.
call_source: CallSource,
/// This `Span` is the span of the function, without the dot and receiver
/// (e.g. `foo(a, b)` in `x.foo(a, b)`
/// e.g. `foo(a, b)` in `x.foo(a, b)`
fn_span: Span,
},

View file

@ -519,7 +519,7 @@ macro_rules! make_mir_visitor {
destination,
target: _,
unwind: _,
from_hir_call: _,
call_source: _,
fn_span: _
} => {
self.visit_operand(func, location);