Skip to content

Commit fd8a537

Browse files
committed
fix(bind): wrap Default::default in a closure when passing to BindDefiner::init
Work-around for [rust-lang/rust#104155][1]. [1]: rust-lang/rust#104155
1 parent fc9d5c0 commit fd8a537

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

doc/toolchain_limitations.md

+14
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,20 @@ const fn identity<C: ~const Fn()>(x: C) -> C { x }
205205
const _: () = { identity(|| {}); };
206206
```
207207

208+
209+
### `[tag:passing_non_const_trait_fn_in_const_cx]` Passing a non-`const` trait function item to a `const fn` is disallowed in a constant context
210+
211+
*Upstream issue:* [rust-lang/rust#104155](https://github.com/rust-lang/rust/issues/104155)
212+
213+
```rust,compile_fail,E0277
214+
use core::mem::forget;
215+
pub const fn f<T: Default>() {
216+
// error[E0277]: the trait bound `T: Default` is not satisfied
217+
forget(T::default);
218+
forget(|| T::default());
219+
}
220+
```
221+
208222
### `[tag:false_unconstrained_generic_const_on_type_alias]` An unrelated generic parameter causes "unconstrained generic constant" when using a type alias including a generic constant
209223

210224
*Upstream issue:* [rust-lang/rust#89421](https://github.com/rust-lang/rust/issues/89421) (possibly related)

src/r3/src/bind/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -233,5 +233,7 @@ where
233233
T: Default + 'static,
234234
C: ~const cfg::CfgStatic,
235235
{
236-
Bind::define().init(Default::default).finish(cfg)
236+
// Passing a closure instead of `Default::default` due to
237+
// [ref:passing_non_const_trait_fn_in_const_cx]
238+
Bind::define().init(|| Default::default()).finish(cfg)
237239
}

0 commit comments

Comments
 (0)