rust-osdev / linked-list-allocator

Apache License 2.0
219 stars 53 forks source link

Compilation failed with nightly-2021-08-20 #56

Closed haowqs closed 2 years ago

haowqs commented 2 years ago

rust-toolchain nightly-2021-08-20 Cargo.toml

[dependencies]
linked_list_allocator = "0.9.1"

src/main.rs

use linked_list_allocator::LockedHeap;

#[global_allocator]
static ALLOCATOR: LockedHeap = LockedHeap::empty();

pub fn init_heap() {
    let heap_start = 0;
    let heap_end = 1024;
    let heap_size = heap_end - heap_start;
    unsafe {
        ALLOCATOR.lock().init(heap_start, heap_size);
    }
}

fn main() {
    println!("Hello, world!");
}

Cargo build

$ cargo build
   Compiling scopeguard v1.1.0
   Compiling lock_api v0.4.7
   Compiling spinning_top v0.2.4
   Compiling linked_list_allocator v0.9.1
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
   --> /home/test/.cargo/registry/src/github.com-1ecc6299db9ec823/linked_list_allocator-0.9.1/src/lib.rs:224:20
    |
224 |         LockedHeap(Spinlock::new(Heap::empty()))
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0015`.
error: could not compile `linked_list_allocator` due to previous error

I lowered the lock_api in cargo.lock from 0.4.7 to 0.4.6, and the compilation was successful

phil-opp commented 2 years ago

See https://github.com/Amanieu/parking_lot/issues/335. Try updating to the latest nightly.

phil-opp commented 2 years ago

I think this is solved, right?

haowqs commented 2 years ago

yes, I upgrade the rust version, it's ok