The const_mut_refs feature is stable now and no longer required

This commit is contained in:
Philipp Oppermann
2025-01-15 19:40:20 +01:00
parent 4de9527ef8
commit 69a498c6a3
2 changed files with 2 additions and 6 deletions

View File

@@ -511,7 +511,7 @@ impl ListNode {
}
```
この型は`new`という単純なコンストラクタ関数を持ち、表現する領域の開始・終端アドレスを計算するメソッドを持っています。`new`関数は[const関数][const function]としていますが、これは後で静的な連結リストアロケータを作る際に必要になるためです。const関数においては、あらゆる可変参照の使用`next`フィールドを`None`にすることも含めはunstableであることに注意してください。コンパイルを通すためには、`#![feature(const_mut_refs)]``lib.rs`の最初に追加する必要があります。
この型は`new`という単純なコンストラクタ関数を持ち、表現する領域の開始・終端アドレスを計算するメソッドを持っています。`new`関数は[const関数][const function]としていますが、これは後で静的な連結リストアロケータを作る際に必要になるためです。
[const function]: https://doc.rust-lang.org/reference/items/functions.html#const-functions
@@ -968,8 +968,6 @@ impl FixedSizeBlockAllocator {
[`empty`]: https://docs.rs/linked_list_allocator/0.9.0/linked_list_allocator/struct.Heap.html#method.empty
もし`LinkedListAllocator`を実装するときにまだやっていないのなら、 **`#![feature(const_mut_refs)]`** を`lib.rs`の最初に追記しないといけません。const関数内におけるあらゆる可変参照型の使用はまだunstableで、それには`list_heads`フィールドの配列要素の型である`Option<&'static mut ListNode>`も(その値を`None`にしているにもかかわらず)含まれるからです。
このunsafeな`init`関数は`fallback_allocator`の[`init`]関数を呼ぶだけで、`list_heads`配列の初期化などは行いません。これらの配列の初期化は、`alloc``dealloc`呼び出しが行われたときに初めて行います。
[`init`]: https://docs.rs/linked_list_allocator/0.9.0/linked_list_allocator/struct.Heap.html#method.init