From 46e38318a225f493436c15d6f13494549dc7f20c Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 19 Jan 2024 15:13:23 +0100 Subject: [PATCH] Stub out FnAbi::partial_eq as a workaround for now --- crates/hir-ty/src/display.rs | 13 +++++++------ crates/hir-ty/src/lib.rs | 17 ++++++++++++++++- crates/hir-ty/src/tests/coercion.rs | 2 +- crates/hir-ty/src/tests/display_source_code.rs | 4 ++-- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/crates/hir-ty/src/display.rs b/crates/hir-ty/src/display.rs index 76e36f054d..a630db05de 100644 --- a/crates/hir-ty/src/display.rs +++ b/crates/hir-ty/src/display.rs @@ -1327,15 +1327,16 @@ fn hir_fmt_generics( impl HirDisplay for CallableSig { fn hir_fmt(&self, f: &mut HirFormatter<'_>) -> Result<(), HirDisplayError> { - let CallableSig { params_and_return: _, is_varargs, safety, abi } = *self; + let CallableSig { params_and_return: _, is_varargs, safety, abi: _ } = *self; if let Safety::Unsafe = safety { write!(f, "unsafe ")?; } - if !matches!(abi, FnAbi::Rust) { - f.write_str("extern \"")?; - f.write_str(abi.as_str())?; - f.write_str("\" ")?; - } + // FIXME: Enable this when the FIXME on FnAbi regarding PartialEq is fixed. + // if !matches!(abi, FnAbi::Rust) { + // f.write_str("extern \"")?; + // f.write_str(abi.as_str())?; + // f.write_str("\" ")?; + // } write!(f, "fn(")?; f.write_joined(self.params(), ", ")?; if is_varargs { diff --git a/crates/hir-ty/src/lib.rs b/crates/hir-ty/src/lib.rs index 5888a4f403..61055583fc 100644 --- a/crates/hir-ty/src/lib.rs +++ b/crates/hir-ty/src/lib.rs @@ -356,7 +356,7 @@ pub struct CallableSig { has_interner!(CallableSig); -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Copy, Clone, Eq)] pub enum FnAbi { Aapcs, AapcsUnwind, @@ -398,6 +398,21 @@ pub enum FnAbi { Unknown, } +impl PartialEq for FnAbi { + fn eq(&self, _other: &Self) -> bool { + // FIXME: Proper equality breaks `coercion::two_closures_lub` test + true + } +} + +impl Hash for FnAbi { + fn hash(&self, state: &mut H) { + // Required because of the FIXME above and due to us implementing `Eq`, without this + // we would break the `Hash` + `Eq` contract + core::mem::discriminant(&Self::Unknown).hash(state); + } +} + impl FnAbi { pub fn from_str(s: &str) -> FnAbi { match s { diff --git a/crates/hir-ty/src/tests/coercion.rs b/crates/hir-ty/src/tests/coercion.rs index 798bc60056..d56b15b9b7 100644 --- a/crates/hir-ty/src/tests/coercion.rs +++ b/crates/hir-ty/src/tests/coercion.rs @@ -574,7 +574,7 @@ fn two_closures_lub() { r#" fn foo(c: i32) { let add = |a: i32, b: i32| a + b; - //^^^^^^^^^^^^ impl Fn(i32, i32) -> i32 + //^^^^^^^^^^^^^^^^^^^^^^ impl Fn(i32, i32) -> i32 let sub = |a, b| a - b; //^^^^^^^^^^^^ impl Fn(i32, i32) -> i32 if c > 42 { add } else { sub }; diff --git a/crates/hir-ty/src/tests/display_source_code.rs b/crates/hir-ty/src/tests/display_source_code.rs index af648b4ebe..e75b037e38 100644 --- a/crates/hir-ty/src/tests/display_source_code.rs +++ b/crates/hir-ty/src/tests/display_source_code.rs @@ -239,9 +239,9 @@ fn test() { let f = foo; //^ fn(i32) -> i64 let f = S::; - //^ extern "rust-call" fn(i8) -> S + //^ fn(i8) -> S let f = E::A; - //^ extern "rust-call" fn(usize) -> E + //^ fn(usize) -> E } "#, );