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

标签 rust

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/

相关文章:

iterator - 如何在 String 中使用 contains() 和 retain()?

rust - 无法根据文档示例打开文件

rust - 如何检查命令行参数的第二个元素?

rust - 如何对 float 的 Vec 进行二分查找?

rust - 一个数组如何包含对同一对象的多个可变引用?

Docker 忽略 `--platform` 中的 `Dockerfile` 标志

rust - 在Rust中挣扎着悬而未决的引用和静态生命周期建议

Rust 通过空格分割线 : No method collect found for type &str

scope - 修剪字符串后未找到类型 `push_str` 的名为 `&str` 的方法

rust - 在 macro_rules 内匹配 - 不能使用 '_'