rust - "expected crate directive"使用rust 错误

标签 rust rust-obsolete

Editor's note: This question was asked before Rust 1.0 was released and the syntax, error messages, and even how crates are bundled have changed since then.

我写了一个 Rust 示例程序。 代码是这样的:

use std;
import std::io;
fn main() {
    io::println("hello world");
}

我尝试编译它,但 rustc 编译告诉我一些错误消息。

hello.rc:4:0: 4:2 error: expected crate directive
hello.rc:4 fn main() {
       ^~

我的 rustc 版本是

macmatoMacBook-Air:test kula$ rustc -v
rustc 0.1.1 (a0f0a70 2012-03-10 00:35:02 -0800)
host: x86_64-apple-darwin

我的操作系统是 mac osx 10.7

有人知道怎么回事吗?我认为我的 Rust 代码没有问题。

最佳答案

编译器试图变得聪明,并且对 .rs(源)和 .rc(crate)文件表现不同。

使用 .rs 文件扩展名再试一次! :)

关于rust - "expected crate directive"使用rust 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9645595/

相关文章:

struct - 使用 envy 时如何用匹配结果填充结构体实例?

rust - 更改静态字符串值

rust - 向量借用和所有权

rust - 如何为我不拥有的类型实现我不拥有的特征?

string - 我如何在 Rust 中将 &str 转换为 ~str?

vector - 通过消耗两个向量来创建新向量的好方法是什么?

rust - 什么是类型状态?

rust - 如何将字符转换为字符串?

使用rust "error: moving out of immutable field"

rust - 在单独的模块中使用时使用未声明的类型或模块 `std`