在基本程序中未解析的名称`thread :: scoped`

时间:2015-03-28 13:04:24

标签: rust

为什么在这个基本程序中出现编译失败?

use std::thread;

fn main() {
    for i in 1..10 {
        let _ = thread::scoped( move || {
            println!("hello from thread {}", i);
        });
    }
}

我尝试构建程序,然后得到:

src/main.rs:5:17: 5:36 error: unresolved name `thread::scoped`
src/main.rs:5         let _ = thread::scoped( move || {
                              ^~~~~~~~~~~~~~~

为什么?

我使用的Rust版本:

$ rustc --version
rustc 1.0.0-nightly (170c4399e 2015-01-14 00:41:55 +0000)

1 个答案:

答案 0 :(得分:2)

确实问题出在了rustc的版本上。 升级后程序已成功编译:

   Compiling examples v0.0.1 (file:///home/igor/rust/projects/examples)
src/main.rs:1:5: 1:16 warning: unused import, #[warn(unused_imports)] on by default
src/main.rs:1 use std::thread;
                  ^~~~~~~~~~~

删除 use 后,警告消失了:

fn main() {
    for i in 1..10 {
        let _ = thread::scoped( move || {
            println!("hello from thread {}", i);
        });
    }
}

(谢谢, huon-dbaupp Dogbert ,为您提供帮助)。