【问题标题】:Unable to get started with diesel.rs and Rust 1.16 nightly无法开始使用diesel.rs 和Rust 1.16 nightly
【发布时间】:2017-06-14 01:11:30
【问题描述】:

我试图通过直接从Diesel GitHub repo 复制examples/getting_started_step_3/ 来跟踪Diesel getting started guide,但我遇到了一些我无法修复的编译错误:

cargo build 
   Compiling diesel_demo_step_3 v0.1.0 (file:///home/stamm/code/rustsome/pkiexpress)
error: macro undefined: 'options!'
 --> src/schema.rs:1:1
  |
1 | infer_schema!("dotenv:DATABASE_URL");
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: this error originates in a macro outside of the current crate

error: macro undefined: 'table_name!'
  --> src/models.rs:12:1
   |
12 | #[table_name="posts"]
   | ^^^^^^^^^^^^^^^^^^^^^

这是我的.env

DATABASE_URL=postgres://postgres:password@localhost/pkiexpress

我正在使用 Rust 1.16.0-nightly (df8debf6d 2017-01-25) 和 Diesel 0.9.0。

【问题讨论】:

  • 您正在使用夜间编译器来处理夜间版本的代码;听起来您应该针对柴油提交错误报告。
  • 或者,尝试使用稳定的 Rust 版本和/或稳定的 Diesel 版本,以排除其他环境因素。
  • 你复制的示例代码是最新版本吗?我只能通过使用旧版本的示例代码来得到你得到的错误。
  • 我使用的是 v0.9.1 版本示例。这已经包括删除语法,破坏与当前稳定的兼容性。这显然将在 2017 年 2 月 2 日被 1.15 取代,这个新的稳定版将使我们免于使用该功能(port_macro)。

标签: rust rust-diesel


【解决方案1】:

您收到的编译错误听起来像是由an issue with the current nightly 引起的。您可以通过从代码中删除 #![feature(proc_macro)] 来修复它(Diesel 使用的功能不再需要它)。对于您链接的示例,这是在 a commit made 17 days ago 中完成的。

在使用 nightly 编译器的示例时,存在很高的损坏风险。对于流行的 crate,示例更新得非常快,因此您应该确保您的编译器和您尝试运行的示例都是最新的。幸运的是,随着 1.15 的发布(不到一周,2017-02-02),Diesel 将与稳定的编译器一起工作,其中损坏的风险要小得多。

如果上述方法不起作用,您可以使用较旧的 nightly(例如 c07a6ae77 2017-01-17 应该可以),只需等待问题解决,或等到 1.15 发布并使用 stable。

【讨论】:

  • 更好的是,下周试用 Rust 1.15 的 beta 版本;这样你就可以帮助测试下一个稳定版本!
  • 好的,它现在适用于测试版:rustup install beta && cargo update && cargo clean && cargo build。我还必须从src/lib.rs 中删除#[feature(port_macro)] 行。
猜你喜欢
  • 2022-12-04
  • 2021-01-08
  • 2010-10-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-08
  • 2013-02-09
相关资源
最近更新 更多