Skip to content

Commit 5c8bff7

Browse files
committed
Auto merge of #101263 - lopopolo:lopopolo/c-unwind-fn-ptr-impls, r=thomcc
Add default trait implementations for "c-unwind" ABI function pointers Following up on #92964, only add default trait implementations for the `c-unwind` family of function pointers. The previous attempt in #92964 added trait implementations for many more ABIs and ran into concerns regarding the increase in size of the libcore rlib. An attempt to abstract away function pointer types behind a unified trait to reduce the duplication of trait impls is being discussed in #99531 but this change looks to be blocked on a lang MCP. Following `@RalfJung's` suggestion in #99531 (comment), this commit is another cut at #92964 but it _only_ adds the impls for `extern "C-unwind" fn` and `unsafe extern "C-unwind" fn`. I am interested in landing this patch to unblock the stabilization of the `c_unwind` feature. RFC: rust-lang/rfcs#2945 Tracking Issue: #74990
2 parents 57e2c06 + efe61da commit 5c8bff7

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@
174174
#![feature(allow_internal_unstable)]
175175
#![feature(associated_type_bounds)]
176176
#![feature(auto_traits)]
177+
#![feature(c_unwind)]
177178
#![feature(cfg_sanitize)]
178179
#![feature(cfg_target_has_atomic)]
179180
#![feature(cfg_target_has_atomic_equal_alignment)]

library/core/src/ptr/mod.rs

+20-7
Original file line numberDiff line numberDiff line change
@@ -1862,9 +1862,16 @@ macro_rules! maybe_fnptr_doc {
18621862
// Impls for function pointers
18631863
macro_rules! fnptr_impls_safety_abi {
18641864
($FnTy: ty, $($Arg: ident),*) => {
1865+
fnptr_impls_safety_abi! { #[stable(feature = "fnptr_impls", since = "1.4.0")] $FnTy, $($Arg),* }
1866+
};
1867+
(@c_unwind $FnTy: ty, $($Arg: ident),*) => {
1868+
#[cfg(not(bootstrap))]
1869+
fnptr_impls_safety_abi! { #[unstable(feature = "c_unwind", issue = "74990")] $FnTy, $($Arg),* }
1870+
};
1871+
(#[$meta:meta] $FnTy: ty, $($Arg: ident),*) => {
18651872
maybe_fnptr_doc! {
18661873
$($Arg)* @
1867-
#[stable(feature = "fnptr_impls", since = "1.4.0")]
1874+
#[$meta]
18681875
impl<Ret, $($Arg),*> PartialEq for $FnTy {
18691876
#[inline]
18701877
fn eq(&self, other: &Self) -> bool {
@@ -1875,13 +1882,13 @@ macro_rules! fnptr_impls_safety_abi {
18751882

18761883
maybe_fnptr_doc! {
18771884
$($Arg)* @
1878-
#[stable(feature = "fnptr_impls", since = "1.4.0")]
1885+
#[$meta]
18791886
impl<Ret, $($Arg),*> Eq for $FnTy {}
18801887
}
18811888

18821889
maybe_fnptr_doc! {
18831890
$($Arg)* @
1884-
#[stable(feature = "fnptr_impls", since = "1.4.0")]
1891+
#[$meta]
18851892
impl<Ret, $($Arg),*> PartialOrd for $FnTy {
18861893
#[inline]
18871894
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
@@ -1892,7 +1899,7 @@ macro_rules! fnptr_impls_safety_abi {
18921899

18931900
maybe_fnptr_doc! {
18941901
$($Arg)* @
1895-
#[stable(feature = "fnptr_impls", since = "1.4.0")]
1902+
#[$meta]
18961903
impl<Ret, $($Arg),*> Ord for $FnTy {
18971904
#[inline]
18981905
fn cmp(&self, other: &Self) -> Ordering {
@@ -1903,7 +1910,7 @@ macro_rules! fnptr_impls_safety_abi {
19031910

19041911
maybe_fnptr_doc! {
19051912
$($Arg)* @
1906-
#[stable(feature = "fnptr_impls", since = "1.4.0")]
1913+
#[$meta]
19071914
impl<Ret, $($Arg),*> hash::Hash for $FnTy {
19081915
fn hash<HH: hash::Hasher>(&self, state: &mut HH) {
19091916
state.write_usize(*self as usize)
@@ -1913,7 +1920,7 @@ macro_rules! fnptr_impls_safety_abi {
19131920

19141921
maybe_fnptr_doc! {
19151922
$($Arg)* @
1916-
#[stable(feature = "fnptr_impls", since = "1.4.0")]
1923+
#[$meta]
19171924
impl<Ret, $($Arg),*> fmt::Pointer for $FnTy {
19181925
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19191926
fmt::pointer_fmt_inner(*self as usize, f)
@@ -1923,7 +1930,7 @@ macro_rules! fnptr_impls_safety_abi {
19231930

19241931
maybe_fnptr_doc! {
19251932
$($Arg)* @
1926-
#[stable(feature = "fnptr_impls", since = "1.4.0")]
1933+
#[$meta]
19271934
impl<Ret, $($Arg),*> fmt::Debug for $FnTy {
19281935
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19291936
fmt::pointer_fmt_inner(*self as usize, f)
@@ -1938,16 +1945,22 @@ macro_rules! fnptr_impls_args {
19381945
fnptr_impls_safety_abi! { extern "Rust" fn($($Arg),+) -> Ret, $($Arg),+ }
19391946
fnptr_impls_safety_abi! { extern "C" fn($($Arg),+) -> Ret, $($Arg),+ }
19401947
fnptr_impls_safety_abi! { extern "C" fn($($Arg),+ , ...) -> Ret, $($Arg),+ }
1948+
fnptr_impls_safety_abi! { @c_unwind extern "C-unwind" fn($($Arg),+) -> Ret, $($Arg),+ }
1949+
fnptr_impls_safety_abi! { @c_unwind extern "C-unwind" fn($($Arg),+ , ...) -> Ret, $($Arg),+ }
19411950
fnptr_impls_safety_abi! { unsafe extern "Rust" fn($($Arg),+) -> Ret, $($Arg),+ }
19421951
fnptr_impls_safety_abi! { unsafe extern "C" fn($($Arg),+) -> Ret, $($Arg),+ }
19431952
fnptr_impls_safety_abi! { unsafe extern "C" fn($($Arg),+ , ...) -> Ret, $($Arg),+ }
1953+
fnptr_impls_safety_abi! { @c_unwind unsafe extern "C-unwind" fn($($Arg),+) -> Ret, $($Arg),+ }
1954+
fnptr_impls_safety_abi! { @c_unwind unsafe extern "C-unwind" fn($($Arg),+ , ...) -> Ret, $($Arg),+ }
19441955
};
19451956
() => {
19461957
// No variadic functions with 0 parameters
19471958
fnptr_impls_safety_abi! { extern "Rust" fn() -> Ret, }
19481959
fnptr_impls_safety_abi! { extern "C" fn() -> Ret, }
1960+
fnptr_impls_safety_abi! { @c_unwind extern "C-unwind" fn() -> Ret, }
19491961
fnptr_impls_safety_abi! { unsafe extern "Rust" fn() -> Ret, }
19501962
fnptr_impls_safety_abi! { unsafe extern "C" fn() -> Ret, }
1963+
fnptr_impls_safety_abi! { @c_unwind unsafe extern "C-unwind" fn() -> Ret, }
19511964
};
19521965
}
19531966

src/test/ui/issues/issue-59488.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ LL | assert_eq!(Foo::Bar, i);
9999
extern "C" fn(A, B, C, D) -> Ret
100100
extern "C" fn(A, B, C, D, ...) -> Ret
101101
extern "C" fn(A, B, C, D, E) -> Ret
102-
and 68 others
102+
and 118 others
103103
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
104104

105105
error[E0277]: `fn(usize) -> Foo {Foo::Bar}` doesn't implement `Debug`
@@ -118,7 +118,7 @@ LL | assert_eq!(Foo::Bar, i);
118118
extern "C" fn(A, B, C, D) -> Ret
119119
extern "C" fn(A, B, C, D, ...) -> Ret
120120
extern "C" fn(A, B, C, D, E) -> Ret
121-
and 68 others
121+
and 118 others
122122
= note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
123123

124124
error: aborting due to 10 previous errors

0 commit comments

Comments
 (0)