1
Fork 0

Rollup merge of #112232 - fee1-dead-contrib:match-eq-const-msg, r=b-naber

Better error for non const `PartialEq` call generated by `match`

Resolves #90237
This commit is contained in:
Michael Goulet 2023-06-19 17:53:33 -07:00 committed by GitHub
commit 31d1fbf8d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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,
},