Skip to content

Commit d989156

Browse files
Merge conflicts and rebase onto master
1 parent 29dccfe commit d989156

File tree

7 files changed

+56
-30
lines changed

7 files changed

+56
-30
lines changed

Diff for: library/core/src/const_closure.rs

+30
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use crate::marker::Destruct;
2+
#[cfg(not(bootstrap))]
3+
use crate::marker::Tuple;
24

35
/// Struct representing a closure with mutably borrowed data.
46
///
@@ -44,6 +46,7 @@ impl<'a, CapturedData: ?Sized, Function> ConstFnMutClosure<&'a mut CapturedData,
4446

4547
macro_rules! impl_fn_mut_tuple {
4648
($($var:ident)*) => {
49+
#[cfg(bootstrap)]
4750
#[allow(unused_parens)]
4851
impl<'a, $($var,)* ClosureArguments, Function, ClosureReturnValue> const
4952
FnOnce<ClosureArguments> for ConstFnMutClosure<($(&'a mut $var),*), Function>
@@ -56,6 +59,7 @@ macro_rules! impl_fn_mut_tuple {
5659
self.call_mut(args)
5760
}
5861
}
62+
#[cfg(bootstrap)]
5963
#[allow(unused_parens)]
6064
impl<'a, $($var,)* ClosureArguments, Function, ClosureReturnValue> const
6165
FnMut<ClosureArguments> for ConstFnMutClosure<($(&'a mut $var),*), Function>
@@ -68,6 +72,32 @@ macro_rules! impl_fn_mut_tuple {
6872
(self.func)(($($var),*), args)
6973
}
7074
}
75+
#[cfg(not(bootstrap))]
76+
#[allow(unused_parens)]
77+
impl<'a, $($var,)* ClosureArguments: Tuple, Function, ClosureReturnValue> const
78+
FnOnce<ClosureArguments> for ConstFnMutClosure<($(&'a mut $var),*), Function>
79+
where
80+
Function: ~const Fn(($(&mut $var),*), ClosureArguments) -> ClosureReturnValue+ ~const Destruct,
81+
{
82+
type Output = ClosureReturnValue;
83+
84+
extern "rust-call" fn call_once(mut self, args: ClosureArguments) -> Self::Output {
85+
self.call_mut(args)
86+
}
87+
}
88+
#[cfg(not(bootstrap))]
89+
#[allow(unused_parens)]
90+
impl<'a, $($var,)* ClosureArguments: Tuple, Function, ClosureReturnValue> const
91+
FnMut<ClosureArguments> for ConstFnMutClosure<($(&'a mut $var),*), Function>
92+
where
93+
Function: ~const Fn(($(&mut $var),*), ClosureArguments)-> ClosureReturnValue,
94+
{
95+
extern "rust-call" fn call_mut(&mut self, args: ClosureArguments) -> Self::Output {
96+
#[allow(non_snake_case)]
97+
let ($($var),*) = &mut self.data;
98+
(self.func)(($($var),*), args)
99+
}
100+
}
71101
};
72102
}
73103
impl_fn_mut_tuple!(A);

Diff for: library/core/src/ops/function.rs

-3
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ use crate::marker::Tuple;
7575
)]
7676
#[fundamental] // so that regex can rely that `&str: !FnMut`
7777
#[must_use = "closures are lazy and do nothing unless called"]
78-
#[cfg_attr(not(bootstrap), const_trait)]
7978
pub trait Fn<Args>: FnMut<Args> {
8079
/// Performs the call operation.
8180
#[unstable(feature = "fn_traits", issue = "29625")]
@@ -245,7 +244,6 @@ pub trait Fn<Args: Tuple>: FnMut<Args> {
245244
)]
246245
#[fundamental] // so that regex can rely that `&str: !FnMut`
247246
#[must_use = "closures are lazy and do nothing unless called"]
248-
#[cfg_attr(not(bootstrap), const_trait)]
249247
pub trait FnMut<Args>: FnOnce<Args> {
250248
/// Performs the call operation.
251249
#[unstable(feature = "fn_traits", issue = "29625")]
@@ -415,7 +413,6 @@ pub trait FnMut<Args: Tuple>: FnOnce<Args> {
415413
)]
416414
#[fundamental] // so that regex can rely that `&str: !FnMut`
417415
#[must_use = "closures are lazy and do nothing unless called"]
418-
#[cfg_attr(not(bootstrap), const_trait)]
419416
pub trait FnOnce<Args> {
420417
/// The returned type after the call operator is used.
421418
#[lang = "fn_once_output"]

Diff for: src/test/ui/function-pointer/unsized-ret.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#![feature(fn_traits)]
22
#![feature(unboxed_closures)]
3+
#![feature(tuple_trait)]
34

4-
fn foo<F: Fn<T>, T>(f: Option<F>, t: T) {
5+
fn foo<F: Fn<T>, T:std::marker::Tuple>(f: Option<F>, t: T) {
56
let y = (f.unwrap()).call(t);
67
}
78

Diff for: src/test/ui/function-pointer/unsized-ret.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: the size for values of type `str` cannot be known at compilation time
2-
--> $DIR/unsized-ret.rs:9:27
2+
--> $DIR/unsized-ret.rs:10:27
33
|
44
LL | foo::<fn() -> str, _>(None, ());
55
| --------------------- ^^^^ doesn't have a size known at compile-time
@@ -9,13 +9,13 @@ LL | foo::<fn() -> str, _>(None, ());
99
= help: within `fn() -> str`, the trait `Sized` is not implemented for `str`
1010
= note: required because it appears within the type `fn() -> str`
1111
note: required by a bound in `foo`
12-
--> $DIR/unsized-ret.rs:4:11
12+
--> $DIR/unsized-ret.rs:5:11
1313
|
14-
LL | fn foo<F: Fn<T>, T>(f: Option<F>, t: T) {
14+
LL | fn foo<F: Fn<T>, T:std::marker::Tuple>(f: Option<F>, t: T) {
1515
| ^^^^^ required by this bound in `foo`
1616

1717
error[E0277]: the size for values of type `(dyn std::fmt::Display + 'a)` cannot be known at compilation time
18-
--> $DIR/unsized-ret.rs:12:66
18+
--> $DIR/unsized-ret.rs:13:66
1919
|
2020
LL | foo::<for<'a> fn(&'a ()) -> (dyn std::fmt::Display + 'a), _>(None, (&(),));
2121
| ------------------------------------------------------------ ^^^^ 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, (&()
2525
= 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)`
2626
= note: required because it appears within the type `for<'a> fn(&'a ()) -> (dyn std::fmt::Display + 'a)`
2727
note: required by a bound in `foo`
28-
--> $DIR/unsized-ret.rs:4:11
28+
--> $DIR/unsized-ret.rs:5:11
2929
|
30-
LL | fn foo<F: Fn<T>, T>(f: Option<F>, t: T) {
30+
LL | fn foo<F: Fn<T>, T:std::marker::Tuple>(f: Option<F>, t: T) {
3131
| ^^^^^ required by this bound in `foo`
3232

3333
error: aborting due to 2 previous errors

Diff for: src/test/ui/parser/kw-in-trait-bounds.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ LL | fn _f<F: fn(), G>(_: impl fn(), _: &dyn fn())
9494
|
9595
::: $SRC_DIR/core/src/ops/function.rs:LL:COL
9696
|
97-
LL | pub trait Fn<Args>: FnMut<Args> {
98-
| ------------------------------- similarly named trait `Fn` defined here
97+
LL | pub trait Fn<Args: Tuple>: FnMut<Args> {
98+
| -------------------------------------- similarly named trait `Fn` defined here
9999

100100
error[E0405]: cannot find trait `r#fn` in this scope
101101
--> $DIR/kw-in-trait-bounds.rs:17:4
@@ -105,8 +105,8 @@ LL | G: fn(),
105105
|
106106
::: $SRC_DIR/core/src/ops/function.rs:LL:COL
107107
|
108-
LL | pub trait Fn<Args>: FnMut<Args> {
109-
| ------------------------------- similarly named trait `Fn` defined here
108+
LL | pub trait Fn<Args: Tuple>: FnMut<Args> {
109+
| -------------------------------------- similarly named trait `Fn` defined here
110110

111111
error[E0405]: cannot find trait `r#fn` in this scope
112112
--> $DIR/kw-in-trait-bounds.rs:3:27
@@ -116,8 +116,8 @@ LL | fn _f<F: fn(), G>(_: impl fn(), _: &dyn fn())
116116
|
117117
::: $SRC_DIR/core/src/ops/function.rs:LL:COL
118118
|
119-
LL | pub trait Fn<Args>: FnMut<Args> {
120-
| ------------------------------- similarly named trait `Fn` defined here
119+
LL | pub trait Fn<Args: Tuple>: FnMut<Args> {
120+
| -------------------------------------- similarly named trait `Fn` defined here
121121

122122
error[E0405]: cannot find trait `r#fn` in this scope
123123
--> $DIR/kw-in-trait-bounds.rs:3:41
@@ -127,8 +127,8 @@ LL | fn _f<F: fn(), G>(_: impl fn(), _: &dyn fn())
127127
|
128128
::: $SRC_DIR/core/src/ops/function.rs:LL:COL
129129
|
130-
LL | pub trait Fn<Args>: FnMut<Args> {
131-
| ------------------------------- similarly named trait `Fn` defined here
130+
LL | pub trait Fn<Args: Tuple>: FnMut<Args> {
131+
| -------------------------------------- similarly named trait `Fn` defined here
132132

133133
error[E0405]: cannot find trait `r#struct` in this scope
134134
--> $DIR/kw-in-trait-bounds.rs:24:10
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#![feature(unboxed_closures)]
22

33
fn a<F: Fn<usize>>(f: F) {}
4+
//~^ ERROR type parameter to bare `Fn` trait must be a tuple
45

56
fn main() {
67
a(|_: usize| {});
7-
//~^ ERROR mismatched types
88
}
+9-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
error[E0308]: mismatched types
2-
--> $DIR/non-tupled-arg-mismatch.rs:6:5
3-
|
4-
LL | a(|_: usize| {});
5-
| ^ types differ
6-
|
7-
= note: expected trait `Fn<usize>`
8-
found trait `Fn<(usize,)>`
9-
note: required by a bound in `a`
1+
error[E0059]: type parameter to bare `Fn` trait must be a tuple
102
--> $DIR/non-tupled-arg-mismatch.rs:3:9
113
|
124
LL | fn a<F: Fn<usize>>(f: F) {}
13-
| ^^^^^^^^^ required by this bound in `a`
5+
| ^^^^^^^^^ the trait `Tuple` is not implemented for `usize`
6+
|
7+
note: required by a bound in `Fn`
8+
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
9+
|
10+
LL | pub trait Fn<Args: Tuple>: FnMut<Args> {
11+
| ^^^^^ required by this bound in `Fn`
1412

1513
error: aborting due to previous error
1614

17-
For more information about this error, try `rustc --explain E0308`.
15+
For more information about this error, try `rustc --explain E0059`.

0 commit comments

Comments
 (0)