Merge conflicts and rebase onto master
This commit is contained in:
parent
29dccfe9e4
commit
d9891563d3
7 changed files with 56 additions and 30 deletions
|
@ -1,4 +1,6 @@
|
||||||
use crate::marker::Destruct;
|
use crate::marker::Destruct;
|
||||||
|
#[cfg(not(bootstrap))]
|
||||||
|
use crate::marker::Tuple;
|
||||||
|
|
||||||
/// Struct representing a closure with mutably borrowed data.
|
/// Struct representing a closure with mutably borrowed data.
|
||||||
///
|
///
|
||||||
|
@ -44,6 +46,7 @@ impl<'a, CapturedData: ?Sized, Function> ConstFnMutClosure<&'a mut CapturedData,
|
||||||
|
|
||||||
macro_rules! impl_fn_mut_tuple {
|
macro_rules! impl_fn_mut_tuple {
|
||||||
($($var:ident)*) => {
|
($($var:ident)*) => {
|
||||||
|
#[cfg(bootstrap)]
|
||||||
#[allow(unused_parens)]
|
#[allow(unused_parens)]
|
||||||
impl<'a, $($var,)* ClosureArguments, Function, ClosureReturnValue> const
|
impl<'a, $($var,)* ClosureArguments, Function, ClosureReturnValue> const
|
||||||
FnOnce<ClosureArguments> for ConstFnMutClosure<($(&'a mut $var),*), Function>
|
FnOnce<ClosureArguments> for ConstFnMutClosure<($(&'a mut $var),*), Function>
|
||||||
|
@ -56,6 +59,7 @@ macro_rules! impl_fn_mut_tuple {
|
||||||
self.call_mut(args)
|
self.call_mut(args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(bootstrap)]
|
||||||
#[allow(unused_parens)]
|
#[allow(unused_parens)]
|
||||||
impl<'a, $($var,)* ClosureArguments, Function, ClosureReturnValue> const
|
impl<'a, $($var,)* ClosureArguments, Function, ClosureReturnValue> const
|
||||||
FnMut<ClosureArguments> for ConstFnMutClosure<($(&'a mut $var),*), Function>
|
FnMut<ClosureArguments> for ConstFnMutClosure<($(&'a mut $var),*), Function>
|
||||||
|
@ -68,6 +72,32 @@ macro_rules! impl_fn_mut_tuple {
|
||||||
(self.func)(($($var),*), args)
|
(self.func)(($($var),*), args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(not(bootstrap))]
|
||||||
|
#[allow(unused_parens)]
|
||||||
|
impl<'a, $($var,)* ClosureArguments: Tuple, Function, ClosureReturnValue> const
|
||||||
|
FnOnce<ClosureArguments> for ConstFnMutClosure<($(&'a mut $var),*), Function>
|
||||||
|
where
|
||||||
|
Function: ~const Fn(($(&mut $var),*), ClosureArguments) -> ClosureReturnValue+ ~const Destruct,
|
||||||
|
{
|
||||||
|
type Output = ClosureReturnValue;
|
||||||
|
|
||||||
|
extern "rust-call" fn call_once(mut self, args: ClosureArguments) -> Self::Output {
|
||||||
|
self.call_mut(args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[cfg(not(bootstrap))]
|
||||||
|
#[allow(unused_parens)]
|
||||||
|
impl<'a, $($var,)* ClosureArguments: Tuple, Function, ClosureReturnValue> const
|
||||||
|
FnMut<ClosureArguments> for ConstFnMutClosure<($(&'a mut $var),*), Function>
|
||||||
|
where
|
||||||
|
Function: ~const Fn(($(&mut $var),*), ClosureArguments)-> ClosureReturnValue,
|
||||||
|
{
|
||||||
|
extern "rust-call" fn call_mut(&mut self, args: ClosureArguments) -> Self::Output {
|
||||||
|
#[allow(non_snake_case)]
|
||||||
|
let ($($var),*) = &mut self.data;
|
||||||
|
(self.func)(($($var),*), args)
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
impl_fn_mut_tuple!(A);
|
impl_fn_mut_tuple!(A);
|
||||||
|
|
|
@ -75,7 +75,6 @@ use crate::marker::Tuple;
|
||||||
)]
|
)]
|
||||||
#[fundamental] // so that regex can rely that `&str: !FnMut`
|
#[fundamental] // so that regex can rely that `&str: !FnMut`
|
||||||
#[must_use = "closures are lazy and do nothing unless called"]
|
#[must_use = "closures are lazy and do nothing unless called"]
|
||||||
#[cfg_attr(not(bootstrap), const_trait)]
|
|
||||||
pub trait Fn<Args>: FnMut<Args> {
|
pub trait Fn<Args>: FnMut<Args> {
|
||||||
/// Performs the call operation.
|
/// Performs the call operation.
|
||||||
#[unstable(feature = "fn_traits", issue = "29625")]
|
#[unstable(feature = "fn_traits", issue = "29625")]
|
||||||
|
@ -245,7 +244,6 @@ pub trait Fn<Args: Tuple>: FnMut<Args> {
|
||||||
)]
|
)]
|
||||||
#[fundamental] // so that regex can rely that `&str: !FnMut`
|
#[fundamental] // so that regex can rely that `&str: !FnMut`
|
||||||
#[must_use = "closures are lazy and do nothing unless called"]
|
#[must_use = "closures are lazy and do nothing unless called"]
|
||||||
#[cfg_attr(not(bootstrap), const_trait)]
|
|
||||||
pub trait FnMut<Args>: FnOnce<Args> {
|
pub trait FnMut<Args>: FnOnce<Args> {
|
||||||
/// Performs the call operation.
|
/// Performs the call operation.
|
||||||
#[unstable(feature = "fn_traits", issue = "29625")]
|
#[unstable(feature = "fn_traits", issue = "29625")]
|
||||||
|
@ -415,7 +413,6 @@ pub trait FnMut<Args: Tuple>: FnOnce<Args> {
|
||||||
)]
|
)]
|
||||||
#[fundamental] // so that regex can rely that `&str: !FnMut`
|
#[fundamental] // so that regex can rely that `&str: !FnMut`
|
||||||
#[must_use = "closures are lazy and do nothing unless called"]
|
#[must_use = "closures are lazy and do nothing unless called"]
|
||||||
#[cfg_attr(not(bootstrap), const_trait)]
|
|
||||||
pub trait FnOnce<Args> {
|
pub trait FnOnce<Args> {
|
||||||
/// The returned type after the call operator is used.
|
/// The returned type after the call operator is used.
|
||||||
#[lang = "fn_once_output"]
|
#[lang = "fn_once_output"]
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
#![feature(fn_traits)]
|
#![feature(fn_traits)]
|
||||||
#![feature(unboxed_closures)]
|
#![feature(unboxed_closures)]
|
||||||
|
#![feature(tuple_trait)]
|
||||||
|
|
||||||
fn foo<F: Fn<T>, T>(f: Option<F>, t: T) {
|
fn foo<F: Fn<T>, T:std::marker::Tuple>(f: Option<F>, t: T) {
|
||||||
let y = (f.unwrap()).call(t);
|
let y = (f.unwrap()).call(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error[E0277]: the size for values of type `str` cannot be known at compilation time
|
error[E0277]: the size for values of type `str` cannot be known at compilation time
|
||||||
--> $DIR/unsized-ret.rs:9:27
|
--> $DIR/unsized-ret.rs:10:27
|
||||||
|
|
|
|
||||||
LL | foo::<fn() -> str, _>(None, ());
|
LL | foo::<fn() -> str, _>(None, ());
|
||||||
| --------------------- ^^^^ doesn't have a size known at compile-time
|
| --------------------- ^^^^ doesn't have a size known at compile-time
|
||||||
|
@ -9,13 +9,13 @@ LL | foo::<fn() -> str, _>(None, ());
|
||||||
= help: within `fn() -> str`, the trait `Sized` is not implemented for `str`
|
= help: within `fn() -> str`, the trait `Sized` is not implemented for `str`
|
||||||
= note: required because it appears within the type `fn() -> str`
|
= note: required because it appears within the type `fn() -> str`
|
||||||
note: required by a bound in `foo`
|
note: required by a bound in `foo`
|
||||||
--> $DIR/unsized-ret.rs:4:11
|
--> $DIR/unsized-ret.rs:5:11
|
||||||
|
|
|
|
||||||
LL | fn foo<F: Fn<T>, T>(f: Option<F>, t: T) {
|
LL | fn foo<F: Fn<T>, T:std::marker::Tuple>(f: Option<F>, t: T) {
|
||||||
| ^^^^^ required by this bound in `foo`
|
| ^^^^^ required by this bound in `foo`
|
||||||
|
|
||||||
error[E0277]: the size for values of type `(dyn std::fmt::Display + 'a)` cannot be known at compilation time
|
error[E0277]: the size for values of type `(dyn std::fmt::Display + 'a)` cannot be known at compilation time
|
||||||
--> $DIR/unsized-ret.rs:12:66
|
--> $DIR/unsized-ret.rs:13:66
|
||||||
|
|
|
|
||||||
LL | foo::<for<'a> fn(&'a ()) -> (dyn std::fmt::Display + 'a), _>(None, (&(),));
|
LL | foo::<for<'a> fn(&'a ()) -> (dyn std::fmt::Display + 'a), _>(None, (&(),));
|
||||||
| ------------------------------------------------------------ ^^^^ doesn't have a size known at compile-time
|
| ------------------------------------------------------------ ^^^^ doesn't have a size known at compile-time
|
||||||
|
@ -25,9 +25,9 @@ LL | foo::<for<'a> fn(&'a ()) -> (dyn std::fmt::Display + 'a), _>(None, (&()
|
||||||
= help: within `for<'a> fn(&'a ()) -> (dyn std::fmt::Display + 'a)`, the trait `for<'a> Sized` is not implemented for `(dyn std::fmt::Display + 'a)`
|
= help: within `for<'a> fn(&'a ()) -> (dyn std::fmt::Display + 'a)`, the trait `for<'a> Sized` is not implemented for `(dyn std::fmt::Display + 'a)`
|
||||||
= note: required because it appears within the type `for<'a> fn(&'a ()) -> (dyn std::fmt::Display + 'a)`
|
= note: required because it appears within the type `for<'a> fn(&'a ()) -> (dyn std::fmt::Display + 'a)`
|
||||||
note: required by a bound in `foo`
|
note: required by a bound in `foo`
|
||||||
--> $DIR/unsized-ret.rs:4:11
|
--> $DIR/unsized-ret.rs:5:11
|
||||||
|
|
|
|
||||||
LL | fn foo<F: Fn<T>, T>(f: Option<F>, t: T) {
|
LL | fn foo<F: Fn<T>, T:std::marker::Tuple>(f: Option<F>, t: T) {
|
||||||
| ^^^^^ required by this bound in `foo`
|
| ^^^^^ required by this bound in `foo`
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
|
@ -94,8 +94,8 @@ LL | fn _f<F: fn(), G>(_: impl fn(), _: &dyn fn())
|
||||||
|
|
|
|
||||||
::: $SRC_DIR/core/src/ops/function.rs:LL:COL
|
::: $SRC_DIR/core/src/ops/function.rs:LL:COL
|
||||||
|
|
|
|
||||||
LL | pub trait Fn<Args>: FnMut<Args> {
|
LL | pub trait Fn<Args: Tuple>: FnMut<Args> {
|
||||||
| ------------------------------- similarly named trait `Fn` defined here
|
| -------------------------------------- similarly named trait `Fn` defined here
|
||||||
|
|
||||||
error[E0405]: cannot find trait `r#fn` in this scope
|
error[E0405]: cannot find trait `r#fn` in this scope
|
||||||
--> $DIR/kw-in-trait-bounds.rs:17:4
|
--> $DIR/kw-in-trait-bounds.rs:17:4
|
||||||
|
@ -105,8 +105,8 @@ LL | G: fn(),
|
||||||
|
|
|
|
||||||
::: $SRC_DIR/core/src/ops/function.rs:LL:COL
|
::: $SRC_DIR/core/src/ops/function.rs:LL:COL
|
||||||
|
|
|
|
||||||
LL | pub trait Fn<Args>: FnMut<Args> {
|
LL | pub trait Fn<Args: Tuple>: FnMut<Args> {
|
||||||
| ------------------------------- similarly named trait `Fn` defined here
|
| -------------------------------------- similarly named trait `Fn` defined here
|
||||||
|
|
||||||
error[E0405]: cannot find trait `r#fn` in this scope
|
error[E0405]: cannot find trait `r#fn` in this scope
|
||||||
--> $DIR/kw-in-trait-bounds.rs:3:27
|
--> $DIR/kw-in-trait-bounds.rs:3:27
|
||||||
|
@ -116,8 +116,8 @@ LL | fn _f<F: fn(), G>(_: impl fn(), _: &dyn fn())
|
||||||
|
|
|
|
||||||
::: $SRC_DIR/core/src/ops/function.rs:LL:COL
|
::: $SRC_DIR/core/src/ops/function.rs:LL:COL
|
||||||
|
|
|
|
||||||
LL | pub trait Fn<Args>: FnMut<Args> {
|
LL | pub trait Fn<Args: Tuple>: FnMut<Args> {
|
||||||
| ------------------------------- similarly named trait `Fn` defined here
|
| -------------------------------------- similarly named trait `Fn` defined here
|
||||||
|
|
||||||
error[E0405]: cannot find trait `r#fn` in this scope
|
error[E0405]: cannot find trait `r#fn` in this scope
|
||||||
--> $DIR/kw-in-trait-bounds.rs:3:41
|
--> $DIR/kw-in-trait-bounds.rs:3:41
|
||||||
|
@ -127,8 +127,8 @@ LL | fn _f<F: fn(), G>(_: impl fn(), _: &dyn fn())
|
||||||
|
|
|
|
||||||
::: $SRC_DIR/core/src/ops/function.rs:LL:COL
|
::: $SRC_DIR/core/src/ops/function.rs:LL:COL
|
||||||
|
|
|
|
||||||
LL | pub trait Fn<Args>: FnMut<Args> {
|
LL | pub trait Fn<Args: Tuple>: FnMut<Args> {
|
||||||
| ------------------------------- similarly named trait `Fn` defined here
|
| -------------------------------------- similarly named trait `Fn` defined here
|
||||||
|
|
||||||
error[E0405]: cannot find trait `r#struct` in this scope
|
error[E0405]: cannot find trait `r#struct` in this scope
|
||||||
--> $DIR/kw-in-trait-bounds.rs:24:10
|
--> $DIR/kw-in-trait-bounds.rs:24:10
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#![feature(unboxed_closures)]
|
#![feature(unboxed_closures)]
|
||||||
|
|
||||||
fn a<F: Fn<usize>>(f: F) {}
|
fn a<F: Fn<usize>>(f: F) {}
|
||||||
|
//~^ ERROR type parameter to bare `Fn` trait must be a tuple
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
a(|_: usize| {});
|
a(|_: usize| {});
|
||||||
//~^ ERROR mismatched types
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,15 @@
|
||||||
error[E0308]: mismatched types
|
error[E0059]: type parameter to bare `Fn` trait must be a tuple
|
||||||
--> $DIR/non-tupled-arg-mismatch.rs:6:5
|
|
||||||
|
|
|
||||||
LL | a(|_: usize| {});
|
|
||||||
| ^ types differ
|
|
||||||
|
|
|
||||||
= note: expected trait `Fn<usize>`
|
|
||||||
found trait `Fn<(usize,)>`
|
|
||||||
note: required by a bound in `a`
|
|
||||||
--> $DIR/non-tupled-arg-mismatch.rs:3:9
|
--> $DIR/non-tupled-arg-mismatch.rs:3:9
|
||||||
|
|
|
|
||||||
LL | fn a<F: Fn<usize>>(f: F) {}
|
LL | fn a<F: Fn<usize>>(f: F) {}
|
||||||
| ^^^^^^^^^ required by this bound in `a`
|
| ^^^^^^^^^ the trait `Tuple` is not implemented for `usize`
|
||||||
|
|
|
||||||
|
note: required by a bound in `Fn`
|
||||||
|
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
|
||||||
|
|
|
||||||
|
LL | pub trait Fn<Args: Tuple>: FnMut<Args> {
|
||||||
|
| ^^^^^ required by this bound in `Fn`
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0308`.
|
For more information about this error, try `rustc --explain E0059`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue