【问题标题】:Only show first screenful of compile errors in Rust when building with Cargo?使用 Cargo 构建时,仅在 Rust 中显示第一屏编译错误?
【发布时间】:2019-09-01 10:57:40
【问题描述】:

有没有办法让 rustc 在使用 Cargo 编译时只输出前几个错误,或者更好的是,最后打印最旧的错误?似乎中止编译的默认阈值设置得相当高:

error: aborting due to 25 previous errors

我没有耐心翻阅 6-10 页的文字来找到第一个错误。

通常我会通过在我的编辑器 (vim) 中编译来处理这个问题,但是 rust 附带的 vim 配置似乎没有正确设置 errorformat。

由于某种原因,到寻呼机的管道也失败了:

cargo test | less

【问题讨论】:

  • 哈哈我昨天只是希望得到完全相同的东西。我认为这是不可能的,但在 cargo irc 频道或 repo 上请求它可能不会有什么坏处。
  • 更新:只要你的 vim 在你的 cargo 项目的根目录中运行,似乎 rust 附带的 vim 错误格式就可以工作。
  • cargo test | less - 这可能会失败,因为 rust 会向标准错误报告错误。试试cargo test 2>&1 | less

标签: rust rust-cargo


【解决方案1】:

cargo test 将错误写入stderr,因此您必须将stderr 重定向到stdout,如下所示:

cargo test --color always 2>&1 | less -r

【讨论】:

  • 使用cargo test --color always 2>&1 | less 保留颜色
猜你喜欢
  • 2020-01-15
  • 2020-12-28
  • 2019-12-01
  • 2022-01-20
  • 2015-03-28
  • 2022-11-10
  • 1970-01-01
  • 2015-03-16
  • 2018-10-19
相关资源
最近更新 更多