diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2014-07-23 19:57:30 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-07-24 07:26:22 -0700 |
| commit | 3550068b531703bc492b0f97331c6a2bcafecf37 (patch) | |
| tree | 4f804314e83b3ed0f59dc56bd3e8405de3b353b2 /src/libcore | |
| parent | 31ac8a90f1fbe66c3ad34ef0e5f48bc5f7026059 (diff) | |
| download | rust-3550068b531703bc492b0f97331c6a2bcafecf37.tar.gz rust-3550068b531703bc492b0f97331c6a2bcafecf37.zip | |
librustc: Make bare functions implement the `FnMut` trait.
This is done entirely in the libraries for functions up to 16 arguments. A macro is used so that more arguments can be easily added if we need. Note that I had to adjust the overloaded call algorithm to not try calling the overloaded call operator if the callee is a built-in function type, to prevent loops. Closes #15448.
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/ops.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 0ebb6e94b9a..839243970ac 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -769,3 +769,37 @@ pub trait FnOnce<Args,Result> { fn call_once(self, args: Args) -> Result; } +macro_rules! def_fn_mut( + ($($args:ident)*) => ( + #[cfg(not(stage0))] + impl<Result$(,$args)*> + FnMut<($($args,)*),Result> + for extern "Rust" fn($($args: $args,)*) -> Result { + #[rust_call_abi_hack] + #[allow(uppercase_variables)] + fn call_mut(&mut self, args: ($($args,)*)) -> Result { + let ($($args,)*) = args; + (*self)($($args,)*) + } + } + ) +) + +def_fn_mut!() +def_fn_mut!(A0) +def_fn_mut!(A0 A1) +def_fn_mut!(A0 A1 A2) +def_fn_mut!(A0 A1 A2 A3) +def_fn_mut!(A0 A1 A2 A3 A4) +def_fn_mut!(A0 A1 A2 A3 A4 A5) +def_fn_mut!(A0 A1 A2 A3 A4 A5 A6) +def_fn_mut!(A0 A1 A2 A3 A4 A5 A6 A7) +def_fn_mut!(A0 A1 A2 A3 A4 A5 A6 A7 A8) +def_fn_mut!(A0 A1 A2 A3 A4 A5 A6 A7 A8 A9) +def_fn_mut!(A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10) +def_fn_mut!(A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11) +def_fn_mut!(A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12) +def_fn_mut!(A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13) +def_fn_mut!(A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14) +def_fn_mut!(A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14 A15) + |
