You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/doc/unstable-book/src/language-features/macro-metavar-expr-concat.md
+4-23
Original file line number
Diff line number
Diff line change
@@ -7,32 +7,15 @@ The tracking issue for this feature is: [#124225]
7
7
In stable Rust, there is no way to create new identifiers by joining identifiers to literals or other identifiers without using procedural macros such as [`paste`].
8
8
`#![feature(macro_metavar_expr_concat)]` introduces a way to do this, using the concat metavariable expression.
9
9
10
-
> This feature is not to be confused with [`macro_metavar_expr`] or [`concat_idents`].
10
+
> This feature uses the syntax from [`macro_metavar_expr`] but is otherwise
11
+
> independent. It replaces the old unstable feature [`concat_idents`].
11
12
12
13
> This is an experimental feature; it and its syntax will require a RFC before stabilization.
13
14
14
15
15
16
### Overview
16
17
17
-
At this time, [declarative macros] cannot create new identifiers.
18
-
A common use case is the need to create names for structs or functions. The following cannot be done on stable Rust[^1]:
19
-
20
-
```rust,compile_fail
21
-
macro_rules! create_some_structs {
22
-
($name:ident) => {
23
-
// Invalid syntax
24
-
pub struct First$name;
25
-
// Also invalid syntax
26
-
pub struct Second($name);
27
-
// Macros are not allowed in this position
28
-
// (This restriction is what makes `concat_idents!` useless)
29
-
pub struct concat_idents!(Third, $name);
30
-
}
31
-
}
32
-
# create_some_structs!(Thing);
33
-
```
34
-
35
-
`#![feature(macro_metavar_expr_concat)]` provides the `concat` metavariable to concatenate idents:
18
+
`#![feature(macro_metavar_expr_concat)]` provides the `concat` metavariable expression for creating new identifiers:
36
19
37
20
```rust
38
21
#![feature(macro_metavar_expr_concat)]
@@ -59,7 +42,7 @@ pub struct ThirdThing;
59
42
### Syntax
60
43
61
44
This feature builds upon the metavariable expression syntax `${ .. }` as specified in [RFC 3086] ([`macro_metavar_expr`]).
62
-
`concat` is available like `${ concat(items) }`, where `items` is a comma separated sequence of idents and/or string literals.
45
+
`concat` is available like `${ concat(items) }`, where `items` is a comma separated sequence of idents and/or literals.
63
46
64
47
### Examples
65
48
@@ -141,8 +124,6 @@ test test_u64_subtraction ... ok
141
124
test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
0 commit comments