Skip to content

Commit 28819e0

Browse files
committed
Make const Fn require const FnMut
1 parent a2d1d14 commit 28819e0

File tree

6 files changed

+33
-4
lines changed

6 files changed

+33
-4
lines changed

library/core/src/ops/function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ use crate::marker::Tuple;
7373
#[fundamental] // so that regex can rely that `&str: !FnMut`
7474
#[must_use = "closures are lazy and do nothing unless called"]
7575
#[rustc_const_unstable(feature = "const_trait_impl", issue = "143874")]
76-
pub const trait Fn<Args: Tuple>: FnMut<Args> {
76+
pub const trait Fn<Args: Tuple>: [const] FnMut<Args> {
7777
/// Performs the call operation.
7878
#[unstable(feature = "fn_traits", issue = "29625")]
7979
extern "rust-call" fn call(&self, args: Args) -> Self::Output;

tests/ui/traits/const-traits/call.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
pub const _: () = {
77
assert!((const || true)());
88
//~^ ERROR }: [const] Fn()` is not satisfied
9+
//~| ERROR }: [const] FnMut()` is not satisfied
910
};
1011

1112
fn main() {}

tests/ui/traits/const-traits/call.stderr

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ error[E0277]: the trait bound `{closure@$DIR/call.rs:7:14: 7:22}: [const] Fn()`
44
LL | assert!((const || true)());
55
| ^^^^^^^^^^^^^^^^^
66

7-
error: aborting due to 1 previous error
7+
error[E0277]: the trait bound `{closure@$DIR/call.rs:7:14: 7:22}: [const] FnMut()` is not satisfied
8+
--> $DIR/call.rs:7:13
9+
|
10+
LL | assert!((const || true)());
11+
| ^^^^^^^^^^^^^^^^^
12+
|
13+
note: required by a bound in `call`
14+
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
15+
16+
error: aborting due to 2 previous errors
817

918
For more information about this error, try `rustc --explain E0277`.

tests/ui/traits/const-traits/const_closure-const_trait_impl-ice-113381.stderr

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ error[E0277]: the trait bound `{closure@$DIR/const_closure-const_trait_impl-ice-
44
LL | (const || (()).foo())();
55
| ^^^^^^^^^^^^^^^^^^^^^^^
66

7-
error: aborting due to 1 previous error
7+
error[E0277]: the trait bound `{closure@$DIR/const_closure-const_trait_impl-ice-113381.rs:15:6: 15:14}: [const] FnMut()` is not satisfied
8+
--> $DIR/const_closure-const_trait_impl-ice-113381.rs:15:5
9+
|
10+
LL | (const || (()).foo())();
11+
| ^^^^^^^^^^^^^^^^^^^^^^^
12+
|
13+
note: required by a bound in `call`
14+
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
15+
16+
error: aborting due to 2 previous errors
817

918
For more information about this error, try `rustc --explain E0277`.

tests/ui/traits/const-traits/non-const-op-const-closure-non-const-outer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ impl Foo for () {
1212
fn main() {
1313
(const || { (()).foo() })();
1414
//~^ ERROR: }: [const] Fn()` is not satisfied
15+
//~| ERROR: }: [const] FnMut()` is not satisfied
1516
}

tests/ui/traits/const-traits/non-const-op-const-closure-non-const-outer.stderr

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ error[E0277]: the trait bound `{closure@$DIR/non-const-op-const-closure-non-cons
44
LL | (const || { (()).foo() })();
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
66

7-
error: aborting due to 1 previous error
7+
error[E0277]: the trait bound `{closure@$DIR/non-const-op-const-closure-non-const-outer.rs:13:6: 13:14}: [const] FnMut()` is not satisfied
8+
--> $DIR/non-const-op-const-closure-non-const-outer.rs:13:5
9+
|
10+
LL | (const || { (()).foo() })();
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
|
13+
note: required by a bound in `call`
14+
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
15+
16+
error: aborting due to 2 previous errors
817

918
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)