Skip to content

Commit 16ad7b9

Browse files
committed
Formatting and apply feedback
1 parent e21e973 commit 16ad7b9

File tree

2 files changed

+31
-33
lines changed

2 files changed

+31
-33
lines changed

src/doc/unstable-book/src/language-features/macro-metavar-expr-concat.md

+30-32
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ The tracking issue for this feature is: [#124225]
44

55
------------------------
66

7-
8-
`#![feature(macro_metavar_expr_concat)]` provides a more powerful alternative to [`concat_idents!`].
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+
`#![feature(macro_metavar_expr_concat)]` introduces a way to do this, using the concat metavariable expression.
99

1010
> This feature is not to be confused with [`macro_metavar_expr`] or [`concat_idents`].
1111
@@ -14,36 +14,35 @@ The tracking issue for this feature is: [#124225]
1414

1515
### Overview
1616

17-
`macro_rules!` macros cannot create new identifiers and use them in ident positions.
18-
A common use case is the need to create new structs or functions. The following cannot be done[^1]:
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]:
1919

2020
```rust,compile_fail
2121
macro_rules! create_some_structs {
22-
($name:ident) => {
23-
// Invalid syntax
24-
struct First_$name;
25-
// Also invalid syntax
26-
struct Second_($name);
27-
// Macros are not allowed in this position
28-
// (This restriction is what makes `concat_idents!` useless)
29-
struct concat_idents!(Third_, $name);
30-
}
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+
}
3131
}
3232
# create_some_structs!(Thing);
3333
```
3434

35-
`#![feature(macro_metavar_expr_concat)]` provides the `concat` metavariable to concatenate idents in ident position:
35+
`#![feature(macro_metavar_expr_concat)]` provides the `concat` metavariable to concatenate idents:
3636

3737
```rust
3838
#![feature(macro_metavar_expr_concat)]
39-
# #![allow(non_camel_case_types, dead_code)]
4039

4140
macro_rules! create_some_structs {
42-
($name:ident) => {
43-
struct ${ concat(First_, $name) };
44-
struct ${ concat(Second_, $name) };
45-
struct ${ concat(Third_, $name) };
46-
}
41+
($name:ident) => {
42+
pub struct ${ concat(First, $name) };
43+
pub struct ${ concat(Second, $name) };
44+
pub struct ${ concat(Third, $name) };
45+
}
4746
}
4847

4948
create_some_structs!(Thing);
@@ -52,10 +51,9 @@ create_some_structs!(Thing);
5251
This macro invocation expands to:
5352

5453
```rust
55-
# #![allow(non_camel_case_types, dead_code)]
56-
struct First_Thing;
57-
struct Second_Thing;
58-
struct Third_Thing;
54+
pub struct FirstThing;
55+
pub struct SecondThing;
56+
pub struct ThirdThing;
5957
```
6058

6159
### Syntax
@@ -69,16 +67,15 @@ This feature builds upon the metavariable expression syntax `${ .. }` as specifi
6967

7068
```rust
7169
#![feature(macro_metavar_expr_concat)]
72-
# #![allow(non_camel_case_types, dead_code)]
7370

7471
macro_rules! make_getter {
75-
($name:ident, $field: ident, $ret:ty) => {
76-
impl $name {
77-
pub fn ${ concat(get_, $field) }(&self) -> &$ret {
78-
&self.$field
79-
}
80-
}
81-
}
72+
($name:ident, $field: ident, $ret:ty) => {
73+
impl $name {
74+
pub fn ${ concat(get_, $field) }(&self) -> &$ret {
75+
&self.$field
76+
}
77+
}
78+
}
8279
}
8380

8481
pub struct Thing {
@@ -152,3 +149,4 @@ test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; fini
152149
[`macro_metavar_expr`]: ../language-features/macro-metavar-expr.md
153150
[`concat_idents`]: ../library-features/concat-idents.md
154151
[#124225]: https://github.com/rust-lang/rust/issues/124225
152+
[declarative macros]: https://doc.rust-lang.org/stable/reference/macros-by-example.html

src/doc/unstable-book/src/library-features/concat-idents.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The tracking issue for this feature is: [#29599]
66

77
------------------------
88

9-
> This feature is expected to be removed in favor of [`macro_metavar_expr_concat`](../language-features/macro-metavar-expr-concat.md).
9+
> This feature is expected to be superseded by [`macro_metavar_expr_concat`](../language-features/macro-metavar-expr-concat.md).
1010
1111
The `concat_idents` feature adds a macro for concatenating multiple identifiers
1212
into one identifier.

0 commit comments

Comments
 (0)