为什么`cargo build`没有在我的代码中显示所有错误?

yas*_*sin 3 rust

此代码无法编译:

extern crate iron;
#[marco_use] //misspelled here
extern crate mime;

use iron::prelude::*;
use iron::status;

fn main() {
    let mut response = Response::new();
    response.set_mut(mime!(Text/Html; Charset=Utf8));
}
Run Code Online (Sandbox Code Playgroud)

表明:

error: cannot find macro `mime!` in this scope
  --> src/main.rs:10:22
   |
10 |     response.set_mut(mime!(Text/Html; Charset=Utf8));
   |                      ^^^^
Run Code Online (Sandbox Code Playgroud)

如果我添加extern crate hyper; use hyper::mime::*;,则显示:

error: The attribute `marco_use` is currently unknown to the compiler and 
may have meaning added to it in the future (see issue #29642)
 --> src\main.rs:2:1
  |
2 | #[marco_use] extern crate mime;
  | ^^^^^^^^^^^^
Run Code Online (Sandbox Code Playgroud)

如果我早些时候能看到这个,它会帮助我解决这个错误......

我猜Cargo只显示一个错误?我在网上找不到任何有关此行为的信息.我怎么能看到所有错误?

lje*_*drz 7

编译过程分为几个阶段,如果在其中一个阶段出现错误而导致构建,则不会进一步处理以下阶段.这不是特定于货物,但rustc也是(例如:何时将数字文字分配给默认类型?).

我还没有看到它正式记录,但日本人已经描述了高级过程:

在此输入图像描述

  • @yassin为什么?这不是解析错误.对于编译器而言,"mime!"和"#[marco_use]"都是拼写错误,而不是语法错误.只是在属性之前扩展宏,因为它们可以扩展*到*属性.由于无法扩展宏,编译器会停止. (2认同)