Skip to content

Commit e484ef6

Browse files
authored
Unrolled build for #147939
Rollup merge of #147939 - theemathas:add-const-supertrait, r=oli-obk Make `const BorrowMut` require `const Borrow` and make `const Fn` require `const FnMut` This makes it consistent with other const traits in the standard library with supertraits. I am currently unsure if `const FnMut` should require `const FnOnce` or not. See [zulip discussion](https://rust-lang.zulipchat.com/#narrow/channel/146212-t-compiler.2Fconst-eval/topic/.5Bconst.5D.20implied.20bounds.20for.20implicit.20trait.20bounds/near/546152748).
2 parents 31010ca + 28819e0 commit e484ef6

File tree

8 files changed

+34
-7
lines changed

8 files changed

+34
-7
lines changed

library/core/src/borrow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ pub const trait Borrow<Borrowed: ?Sized> {
187187
#[stable(feature = "rust1", since = "1.0.0")]
188188
#[rustc_diagnostic_item = "BorrowMut"]
189189
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
190-
pub const trait BorrowMut<Borrowed: ?Sized>: Borrow<Borrowed> {
190+
pub const trait BorrowMut<Borrowed: ?Sized>: [const] Borrow<Borrowed> {
191191
/// Mutably borrows from an owned value.
192192
///
193193
/// # Examples

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
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.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,4 @@ impl Foo for () {
1313

1414
fn main() {
1515
(const || (()).foo())();
16-
// ^ ERROR: cannot call non-const method `<() as Foo>::foo` in constant functions
17-
// FIXME(const_trait_impl) this should probably say constant closures
1816
}

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)