| 1 |
// { dg-additional-options "-frust-name-resolution-2.0 -frust-compile-until=lowering" } |
| 2 |
|
| 3 |
macro_rules! impl_fn_for_zst { |
| 4 |
($( |
| 5 |
$( #[$attr: meta] )* |
| 6 |
struct $Name: ident impl$( <$( $lifetime : lifetime ),+> )? Fn = |
| 7 |
|$( $arg: ident: $ArgTy: ty ),*| -> $ReturnTy: ty |
| 8 |
$body: block; |
| 9 |
)+) => { |
| 10 |
$( |
| 11 |
$( #[$attr] )* |
| 12 |
struct $Name; |
| 13 |
|
| 14 |
impl $( <$( $lifetime ),+> )? Fn<($( $ArgTy, )*)> for $Name { |
| 15 |
#[inline] |
| 16 |
extern "rust-call" fn call(&self, ($( $arg, )*): ($( $ArgTy, )*)) -> $ReturnTy { |
| 17 |
$body |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
impl $( <$( $lifetime ),+> )? FnMut<($( $ArgTy, )*)> for $Name { |
| 22 |
#[inline] |
| 23 |
extern "rust-call" fn call_mut( |
| 24 |
&mut self, |
| 25 |
($( $arg, )*): ($( $ArgTy, )*) |
| 26 |
) -> $ReturnTy { |
| 27 |
Fn::call(&*self, ($( $arg, )*)) |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
impl $( <$( $lifetime ),+> )? FnOnce<($( $ArgTy, )*)> for $Name { |
| 32 |
type Output = $ReturnTy; |
| 33 |
|
| 34 |
#[inline] |
| 35 |
extern "rust-call" fn call_once(self, ($( $arg, )*): ($( $ArgTy, )*)) -> $ReturnTy { |
| 36 |
Fn::call(&self, ($( $arg, )*)) |
| 37 |
} |
| 38 |
} |
| 39 |
)+ |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
#[lang = "sized"] |
| 44 |
trait Sized {} |
| 45 |
|
| 46 |
#[lang = "copy"] |
| 47 |
trait Copy {} |
| 48 |
|
| 49 |
#[lang = "fn"] |
| 50 |
pub trait Fn<Args>: FnMut<Args> { |
| 51 |
/// Performs the call operation. |
| 52 |
#[unstable(feature = "fn_traits", issue = "29625")] |
| 53 |
extern "rust-call" fn call(&self, args: Args) -> Self::Output; |
| 54 |
} |
| 55 |
|
| 56 |
#[lang = "fn_mut"] |
| 57 |
#[must_use = "closures are lazy and do nothing unless called"] |
| 58 |
pub trait FnMut<Args>: FnOnce<Args> { |
| 59 |
/// Performs the call operation. |
| 60 |
#[unstable(feature = "fn_traits", issue = "29625")] |
| 61 |
extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output; |
| 62 |
} |
| 63 |
|
| 64 |
#[lang = "fn_once"] |
| 65 |
pub trait FnOnce<Args> { |
| 66 |
/// The returned type after the call operator is used. |
| 67 |
#[lang = "fn_once_output"] |
| 68 |
#[stable(feature = "fn_once_output", since = "1.12.0")] |
| 69 |
type Output; |
| 70 |
|
| 71 |
/// Performs the call operation. |
| 72 |
#[unstable(feature = "fn_traits", issue = "29625")] |
| 73 |
extern "rust-call" fn call_once(self, args: Args) -> Self::Output; |
| 74 |
} |
| 75 |
|
| 76 |
impl_fn_for_zst! { |
| 77 |
#[derive(Copy)] |
| 78 |
struct LinesAnyMap impl<'a> Fn = |line: &'a str| -> () { |
| 79 |
}; |
| 80 |
} |