Skip to content

Commit ad44a99

Browse files
committed
Fix traits implemented for function items
This fixes the set of traits implemented for function items. `Fn` family traits are not implemented in some cases. This is roughly implemented in [`assemble_fn_pointer_candidates`](https://github.com/rust-lang/rust/blob/8c32e313cccf7df531e2d49ffb8227bb92304aee/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs#L553-L585). I did not include "has variadic", since that also requires unsafe and extern "C" and is thus covered by the other rules, AFAIK. Could also add that to CYA, though. Fixes #1968
1 parent ff45844 commit ad44a99

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/types/function-item.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@ let foo_ptr_2 = if want_i32 {
5050
```
5151

5252
r[type.fn-item.traits]
53-
All function items implement [`Fn`], [`FnMut`], [`FnOnce`], [`Copy`],
54-
[`Clone`], [`Send`], and [`Sync`].
53+
All function items implement [`Copy`], [`Clone`], [`Send`], and [`Sync`].
54+
55+
[`Fn`], [`FnMut`], and [`FnOnce`] are implemented unless the function has any of the following:
56+
57+
- an [`unsafe`][unsafe.fn] qualifier
58+
- a [`target_feature` attribute][attributes.codegen.target_feature]
59+
- an [ABI][items.fn.extern] other than `"Rust"`
5560

5661
[`Clone`]: ../special-types-and-traits.md#clone
5762
[`Copy`]: ../special-types-and-traits.md#copy

0 commit comments

Comments
 (0)