Skip to content

Commit ecf354f

Browse files
committed
---
yaml --- r: 23471 b: refs/heads/master c: 7669032 h: refs/heads/master i: 23469: f455b08 23467: b2c0049 23463: 42c85f8 23455: 5860b78 v: v3
1 parent 097c718 commit ecf354f

File tree

2 files changed

+6
-82
lines changed

2 files changed

+6
-82
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: d5f0bf922c96054d628bd4bca986726643c799b5
2+
refs/heads/master: 7669032dd377d6207c4d78e52c9e858e2f2d4180
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/doc/rust.md

Lines changed: 5 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -469,14 +469,16 @@ include:
469469
* `include!` : include the Rust expression in the given file
470470
* `include_str!` : include the contents of the given file as a string
471471
* `include_bin!` : include the contents of the given file as a binary blob
472+
* `error!`, `warn!`, `info!`, `debug!` : provide diagnostic information.
472473

473474
All of the above extensions, with the exception of `proto!`, are expressions
474475
with values. `proto!` is an item, defining a new name.
475476

476477
## Macros
477478

478479
User-defined syntax extensions are called "macros", and they can be defined
479-
with the `macro_rules!` syntax extension.
480+
with the `macro_rules!` syntax extension. User-defined macros can currently
481+
only be invoked in expression position.
480482

481483
~~~~ {.ebnf .gram}
482484
expr_macro_rules : "macro_rules" '!' ident '(' macro_rule * ')'
@@ -2325,9 +2327,9 @@ lower levels indicate more-urgent levels of logging. By default, the lowest
23252327
four logging levels (`0_u32 ... 3_u32`) are predefined as the constants
23262328
`error`, `warn`, `info` and `debug` in the `core` library.
23272329

2328-
Additionally, the macros `#error`, `#warn`, `#info` and `#debug` are defined
2330+
Additionally, the macros `error!`, `warn!`, `info!` and `debug!` are defined
23292331
in the default syntax-extension namespace. These expand into calls to the
2330-
logging facility composed with calls to the `#fmt` string formatting
2332+
logging facility composed with calls to the `fmt!` string formatting
23312333
syntax-extension.
23322334

23332335
The following examples all produce the same output, logged at the `error`
@@ -2377,84 +2379,6 @@ use of the knowledge that the condition holds if the program continues to
23772379
execute after the `assert`.
23782380

23792381

2380-
### Syntax extension expressions
2381-
2382-
~~~~~~~~ {.abnf .gram}
2383-
syntax_ext_expr : '#' ident paren_expr_list ? brace_match ? ;
2384-
~~~~~~~~
2385-
2386-
Rust provides a notation for _syntax extension_. The notation for invoking
2387-
a syntax extension is a marked syntactic form that can appear as an expression
2388-
in the body of a Rust program.
2389-
2390-
After parsing, a syntax-extension invocation is expanded into a Rust
2391-
expression. The name of the extension determines the translation performed. In
2392-
future versions of Rust, user-provided syntax extensions aside from macros
2393-
will be provided via external crates.
2394-
2395-
At present, only a set of built-in syntax extensions, as well as macros
2396-
introduced inline in source code using the `macro` extension, may be used. The
2397-
current built-in syntax extensions are:
2398-
2399-
2400-
* `fmt` expands into code to produce a formatted string, similar to
2401-
`printf` from C.
2402-
* `env` expands into a string literal containing the value of that
2403-
environment variable at compile-time.
2404-
* `concat_idents` expands into an identifier which is the
2405-
concatenation of its arguments.
2406-
* `ident_to_str` expands into a string literal containing the name of
2407-
its argument (which must be a literal).
2408-
* `log_syntax` causes the compiler to pretty-print its arguments.
2409-
2410-
2411-
Finally, `macro` is used to define a new macro. A macro can abstract over
2412-
second-class Rust concepts that are present in syntax. The arguments to
2413-
`macro` are pairs (two-element vectors). The pairs consist of an invocation
2414-
and the syntax to expand into. An example:
2415-
2416-
~~~~~~~~{.xfail-test}
2417-
#macro([#apply[fn, [args, ...]], fn(args, ...)]);
2418-
~~~~~~~~
2419-
2420-
In this case, the invocation `apply!(sum, 5, 8, 6)` expands to
2421-
`sum(5,8,6)`. If `...` follows an expression (which need not be as
2422-
simple as a single identifier) in the input syntax, the matcher will expect an
2423-
arbitrary number of occurrences of the thing preceding it, and bind syntax to
2424-
the identifiers it contains. If it follows an expression in the output syntax,
2425-
it will transcribe that expression repeatedly, according to the identifiers
2426-
(bound to syntax) that it contains.
2427-
2428-
The behaviour of `...` is known as Macro By Example. It allows you to
2429-
write a macro with arbitrary repetition by specifying only one case of that
2430-
repetition, and following it by `...`, both where the repeated input is
2431-
matched, and where the repeated output must be transcribed. A more
2432-
sophisticated example:
2433-
2434-
2435-
~~~~~~~~{.xfail-test}
2436-
#macro([#zip_literals[[x, ...], [y, ...]), [[x, y], ...]]);
2437-
#macro([#unzip_literals[[x, y], ...], [[x, ...], [y, ...]]]);
2438-
~~~~~~~~
2439-
2440-
In this case, `zip_literals!([1,2,3], [1,2,3])` expands to
2441-
`[[1,1],[2,2],[3,3]]`, and `unzip_literals!([1,1], [2,2], [3,3])`
2442-
expands to `[[1,2,3],[1,2,3]]`.
2443-
2444-
Macro expansion takes place outside-in: that is,
2445-
`unzip_literals!(zip_literals!([1,2,3],[1,2,3]))` will fail because
2446-
`unzip_literals` expects a list, not a macro invocation, as an argument.
2447-
2448-
The macro system currently has some limitations. It's not possible to
2449-
destructure anything other than vector literals (therefore, the arguments to
2450-
complicated macros will tend to be an ocean of square brackets). Macro
2451-
invocations and `...` can only appear in expression positions. Finally,
2452-
macro expansion is currently unhygienic. That is, name collisions between
2453-
macro-generated and user-written code can cause unintentional capture.
2454-
2455-
Future versions of Rust will address these issues.
2456-
2457-
24582382
# Type system
24592383

24602384
## Types

0 commit comments

Comments
 (0)