Skip to content

Commit d7e0bf5

Browse files
author
Keegan McAllister
committed
---
yaml --- r: 193115 b: refs/heads/beta c: 848a7e6 h: refs/heads/master i: 193113: 9de1b9d 193111: 87e2279 v: v3
1 parent 1726e7d commit d7e0bf5

File tree

5 files changed

+40
-24
lines changed

5 files changed

+40
-24
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ refs/heads/automation-fail: 1bf06495443584539b958873e04cc2f864ab10e4
3131
refs/heads/issue-18208-method-dispatch-3-quick-reject: 2009f85b9f99dedcec4404418eda9ddba90258a2
3232
refs/heads/batch: b7fd822592a4fb577552d93010c4a4e14f314346
3333
refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
34-
refs/heads/beta: df0865754e56d3d804df3b2bb15d405e344e2015
34+
refs/heads/beta: 848a7e692102643d99bb208b5a64199b6d6d87a1
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3636
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
3737
refs/heads/tmp: de8a23bbc3a7b9cbd7574b5b91a34af59bf030e6

branches/beta/src/doc/reference.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -731,15 +731,20 @@ Rust syntax is restricted in two ways:
731731
pairs when they occur at the beginning of, or immediately after, a `$(...)*`;
732732
requiring a distinctive token in front can solve the problem.
733733

734-
## Syntax extensions useful for the macro author
734+
## Syntax extensions useful in macros
735735

736-
* `log_syntax!` : print out the arguments at compile time
737-
* `trace_macros!` : supply `true` or `false` to enable or disable macro expansion logging
738736
* `stringify!` : turn the identifier argument into a string literal
739737
* `concat!` : concatenates a comma-separated list of literals
740-
* `concat_idents!` : create a new identifier by concatenating the arguments
741738

742-
The following attributes are used for quasiquoting in procedural macros:
739+
## Syntax extensions for macro debugging
740+
741+
* `log_syntax!` : print out the arguments at compile time
742+
* `trace_macros!` : supply `true` or `false` to enable or disable macro expansion logging
743+
744+
## Quasiquoting
745+
746+
The following syntax extensions are used for quasiquoting Rust syntax trees,
747+
usually in [procedural macros](book/plugins.html#syntax-extensions):
743748

744749
* `quote_expr!`
745750
* `quote_item!`
@@ -748,6 +753,8 @@ The following attributes are used for quasiquoting in procedural macros:
748753
* `quote_tokens!`
749754
* `quote_ty!`
750755

756+
Documentation is very limited at the moment.
757+
751758
# Crates and source files
752759

753760
Rust is a *compiled* language. Its semantics obey a *phase distinction*

branches/beta/src/doc/trpl/advanced-macros.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,19 +239,11 @@ fn main() {
239239
Exercise: use macros to reduce duplication in the above definition of the
240240
`bct!` macro.
241241

242-
# A final note
243-
244-
Macros, as currently implemented, are not for the faint of heart. Even
245-
ordinary syntax errors can be more difficult to debug when they occur inside a
246-
macro, and errors caused by parse problems in generated code can be very
247-
tricky. Invoking the `log_syntax!` macro can help elucidate intermediate
248-
states, invoking `trace_macros!(true)` will automatically print those
249-
intermediate states out, and passing the flag `--pretty expanded` as a
250-
command-line argument to the compiler will show the result of expansion.
242+
# Procedural macros
251243

252244
If Rust's macro system can't do what you need, you may want to write a
253245
[compiler plugin](plugins.html) instead. Compared to `macro_rules!`
254246
macros, this is significantly more work, the interfaces are much less stable,
255-
and the warnings about debugging apply ten-fold. In exchange you get the
247+
and bugs can be much harder to track down. In exchange you get the
256248
flexibility of running arbitrary Rust code within the compiler. Syntax
257249
extension plugins are sometimes called *procedural macros* for this reason.

branches/beta/src/doc/trpl/macros.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,25 @@ fn main() {
405405
}
406406
```
407407

408+
# Debugging macro code
409+
410+
To see the results of expanding macros, run `rustc --pretty expanded`. The
411+
output represents a whole crate, so you can also feed it back in to `rustc`,
412+
which will sometimes produce better error messages than the original
413+
compilation. Note that the `--pretty expanded` output may have a different
414+
meaning if multiple variables of the same name (but different syntax contexts)
415+
are in play in the same scope. In this case `--pretty expanded,hygiene` will
416+
tell you about the syntax contexts.
417+
418+
`rustc` provides two syntax extensions that help with macro debugging. For now,
419+
they are unstable and require feature gates.
420+
421+
* `log_syntax!(...)` will print its arguments to standard output, at compile
422+
time, and "expand" to nothing.
423+
424+
* `trace_macros!(true)` will enable a compiler message every time a macro is
425+
expanded. Use `trace_macros!(false)` later in expansion to turn it off.
426+
408427
# Further reading
409428

410429
The [advanced macros chapter][] goes into more detail about macro syntax. It

branches/beta/src/doc/trpl/plugins.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,7 @@ a more involved macro example, see
146146

147147
## Tips and tricks
148148

149-
To see the results of expanding syntax extensions, run
150-
`rustc --pretty expanded`. The output represents a whole crate, so you
151-
can also feed it back in to `rustc`, which will sometimes produce better
152-
error messages than the original compilation. Note that the
153-
`--pretty expanded` output may have a different meaning if multiple
154-
variables of the same name (but different syntax contexts) are in play
155-
in the same scope. In this case `--pretty expanded,hygiene` will tell
156-
you about the syntax contexts.
149+
Some of the [macro debugging tips](macros.html#debugging-macro-code) are applicable.
157150

158151
You can use [`syntax::parse`](../syntax/parse/index.html) to turn token trees into
159152
higher-level syntax elements like expressions:
@@ -184,6 +177,11 @@ and return
184177
[`DummyResult`](../syntax/ext/base/struct.DummyResult.html),
185178
so that the compiler can continue and find further errors.
186179

180+
To print syntax fragments for debugging, you can use
181+
[`span_note`](../syntax/ext/base/struct.ExtCtxt.html#method.span_note) together
182+
with
183+
[`syntax::print::pprust::*_to_string`](http://doc.rust-lang.org/syntax/print/pprust/index.html#functions).
184+
187185
The example above produced an integer literal using
188186
[`AstBuilder::expr_uint`](../syntax/ext/build/trait.AstBuilder.html#tymethod.expr_uint).
189187
As an alternative to the `AstBuilder` trait, `libsyntax` provides a set of

0 commit comments

Comments
 (0)