gpt4 book ai didi

rust - 为什么我不能调用Global.alloc_zeroed()

转载 作者:行者123 更新时间:2023-12-03 11:33:38 24 4
gpt4 key购买 nike

std::alloc::Global类型应该具有AllocRef特征,该特征具有alloc_zeroed(布局)pub方法。但是我不能使用它....我运行“每晚改写覆盖”以每晚使用一次。似乎AllocRef特性无法在此处使用,但我不知道如何使其可见...请帮助!
谢谢!我运行了“每晚设置的rustup替代设置”,但是“rustup show”的输出未更改,仍然无法编译。.最后添加了“rustup show”的输出。
PS。
运行“每晚将rustup覆盖设置为2020-01-09-x86_64-apple-darwin”并添加“use std::alloc::Alloc”后,我看到它已编译!当我运行“rustup overset set nightly-x86_64-apple-darwin”时,它没有编译。
我的代码:

#![feature(allocator_api)]
use std::alloc::{Layout,Global,Alloc}; // added "Alloc"
fn main() {
unsafe {
let layout = Layout::new::<i32>();
println!("{:?}", Global.alloc_zeroed(layout));
}
}
编译错误:
error[E0599]: no method named `alloc_zeroed` found for struct `std::alloc::Global` in the 
current scope
--> src/main.rs:6:26
|
6 | println!("{:?}", Global.alloc_zeroed(layout));
| ^^^^^^^^^^^^ method not found in `std::alloc::Global`
error: aborting due to previous error
rustup显示:
Default host: x86_64-apple-darwin
rustup home: /Users/user1/.rustup

installed toolchains
--------------------

stable-x86_64-apple-darwin (default)
nightly-2020-01-09-x86_64-apple-darwin
nightly-x86_64-apple-darwin

active toolchain
----------------

nightly-x86_64-apple-darwin (directory override for '/Users/user1/as/rust22')
rustc 1.51.0-nightly (1d0d76f8d 2021-01-24)

最佳答案

Alloc特性已重命名为Allocator,并且alloc_zeroed已重命名为allocate_zeroed
Link to nightly docs
Link to playground

关于rust - 为什么我不能调用Global.alloc_zeroed(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65913172/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com