为什么构建失败时 cargo build 的输出包含不可读的字符?

Why does the output of cargo build contain unreadable characters when the build fails?

我正在尝试构建一个简单的 guessing-game,如文档中所述。

use std::io;
//use rand::Rng; is not included 

fn main() {
     println!("Guess the number!");
     let secret_number = rand::thread_rng().gen_range(1, 101);
     println!("The secret number is: {}", secret_number);
     println!("Please input your guess.");
     let mut guess = String::new();
     io::stdin().read_line(&mut guess)
          .expect("Failed to read line");
     println!("You guessed: {}", guess);
}

由于缺少 rand::Rng 库(注释注释),上述代码将无法编译。

问题是 cargo build 命令的结果包含不可读的字符:

我使用的是 CentOS 7、Rust 版本 1.32.0 和 Cargo 版本 1.32.0。我能够验证 运行 cargo-build 之前和之后的终端编码并且它没有改变。

有人可以解释一下这种行为吗?

您可以使用 cargo build --color=never 来不使用颜色。


为了帮助您在保持颜色的同时解决问题,我们需要更多信息。例如。你使用什么终端模拟器,你的语言环境是什么等等