about summary refs log tree commit diff
path: root/src/doc
diff options
context:
space:
mode:
authorDan Aloni <alonid@gmail.com>2018-04-10 02:08:47 +0300
committerDan Aloni <alonid@gmail.com>2018-05-13 19:17:02 +0300
commit37ed2ab91038567bafe3fd2e545c7d1631ff2ab0 (patch)
tree27b8125e37ecd34720f6cee3286e821c6a6df96d /src/doc
parent3e955a058108fcadf0a8222de5868b0c905534d5 (diff)
downloadrust-37ed2ab91038567bafe3fd2e545c7d1631ff2ab0.tar.gz
rust-37ed2ab91038567bafe3fd2e545c7d1631ff2ab0.zip
Macros: Add a 'literal' fragment specifier
Implements RFC 1576.

See: https://github.com/rust-lang/rfcs/blob/master/text/1576-macros-literal-matcher.md

Changes are mostly in libsyntax, docs, and tests. Feature gate is
enabled for 1.27.0.

Many thanks to Vadim Petrochenkov for following through code reviews
and suggestions.

Example:

````rust

macro_rules! test_literal {
    ($l:literal) => {
        println!("literal: {}", $l);
    };
    ($e:expr) => {
        println!("expr: {}", $e);
    };
}

fn main() {
    let a = 1;
    test_literal!(a);
    test_literal!(2);
    test_literal!(-3);
}
```

Output:

```
expr: 1
literal: 2
literal: -3
```
Diffstat (limited to 'src/doc')
-rw-r--r--src/doc/unstable-book/src/language-features/macro-literal-matcher.md17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/doc/unstable-book/src/language-features/macro-literal-matcher.md b/src/doc/unstable-book/src/language-features/macro-literal-matcher.md
new file mode 100644
index 00000000000..7e3638fd1cf
--- /dev/null
+++ b/src/doc/unstable-book/src/language-features/macro-literal-matcher.md
@@ -0,0 +1,17 @@
+# `macro_literal_matcher`
+
+The tracking issue for this feature is: [#35625]
+
+The RFC is: [rfc#1576].
+
+With this feature gate enabled, the [list of fragment specifiers][frags] gains one more entry:
+
+* `literal`: a literal. Examples: 2, "string", 'c'
+
+A `literal` may be followed by anything, similarly to the `ident` specifier.
+
+[rfc#1576]: http://rust-lang.github.io/rfcs/1576-macros-literal-matcher.html
+[#35625]: https://github.com/rust-lang/rust/issues/35625
+[frags]: ../book/first-edition/macros.html#syntactic-requirements
+
+------------------------