Skip to content

Instantly share code, notes, and snippets.

@sdleffler
Created November 23, 2016 21:46
Show Gist options
  • Save sdleffler/9aa63b4d7064af66ce6fd2347c4559e1 to your computer and use it in GitHub Desktop.
Save sdleffler/9aa63b4d7064af66ce6fd2347c4559e1 to your computer and use it in GitHub Desktop.
...
//! # The DSL
//!
//! Let's take a look at this fairly small example:
//! ```rust
//! # #[macro_use] extern crate type_operators;
//! type_operators! {
//! [A, B, C, D, E]
//!
//! data Nat {
//! P,
//! I(Nat = P),
//! O(Nat = P),
//! }
//! }
//! # fn main() {
//! # // dummy!
//! # }
//! ```
//!
//! There are two essential things to note in this example. The first is the "gensym list" - Rust does
//! not currently have a way to generate unique identifiers, so we have to supply our own. It is on *you*
//! to avoid clashes between these pseudo-gensyms and the names of the structs involved! If we put `P`, `I`, or `O`
//! into the gensym list, things could get really bad! We'd get type errors at compile-time stemming from trait
//! bounds, coming from the definitions of type operators later. Thankfully, the gensym list can be fairly small
//! and usually never uses more than two or three symbols.
...
The errors I get:
Doc-tests type-operators
running 6 tests
test _1 ... FAILED
test _4 ... ignored
test _0 ... FAILED
test _3 ... FAILED
test _2 ... FAILED
test type_operators_0 ... ok
failures:
---- _1 stdout ----
error: unknown start of token: `
--> <anon>:5:96
|
5 | to avoid clashes between these pseudo-gensyms and the names of the structs involved! If we put `P`, `I`, or `O`
| ^
thread '_1' panicked at 'Box<Any>', ../src/libsyntax/parse/lexer/mod.rs:47
note: Run with `RUST_BACKTRACE=1` for a backtrace.
thread '_1' panicked at 'couldn't compile the test', ../src/librustdoc/test.rs:276
---- _0 stdout ----
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `Nat`
--> <anon>:2:6
|
2 | data Nat {
| ^^^
error[E0425]: unresolved name `data`
--> <anon>:2:1
|
2 | data Nat {
| ^^^^ unresolved name
error: aborting due to previous error(s)
I have verified that the macro compiles as it should when on its own and not in a doctest.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment