Skip to content

Commit d8844ea

Browse files
authored
Merge pull request #52 from TonalidadeHidrica/reserving-syntax
「構文の予約」を翻訳
2 parents 73365fa + 1021279 commit d8844ea

File tree

2 files changed

+99
-2
lines changed

2 files changed

+99
-2
lines changed

src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,6 @@
7676
- [配列に対する IntoIterator](rust-2021/IntoIterator-for-arrays.md)
7777
- [Disjoint capture in closures](rust-2021/disjoint-capture-in-closures.md)
7878
- [panic マクロの一貫性](rust-2021/panic-macro-consistency.md)
79-
- [Reserving syntax](rust-2021/reserving-syntax.md)
79+
- [構文の予約](rust-2021/reserving-syntax.md)
8080
- [警告からエラーへの格上げ](rust-2021/warnings-promoted-to-error.md)
8181
- [Or patterns in macro-rules](rust-2021/or-patterns-macro-rules.md)

src/rust-2021/reserving-syntax.md

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,182 @@
1+
<!--
12
# Reserving syntax
3+
-->
24

5+
# 構文の予約
6+
7+
<!--
38
## Summary
9+
-->
10+
11+
## 概要
412

13+
<!--
514
- `any_identifier#`, `any_identifier"..."`, and `any_identifier'...'` are now reserved
615
syntax, and no longer tokenize.
716
- This is mostly relevant to macros. E.g. `quote!{ #a#b }` is no longer accepted.
817
- It doesn't treat keywords specially, so e.g. `match"..." {}` is no longer accepted.
918
- Insert whitespace between the identifier and the subsequent `#`, `"`, or `'`
1019
to avoid errors.
1120
- Edition migrations will help you insert whitespace in such cases.
21+
-->
22+
23+
- `shikibetsushi#`, `shikibetsushi"..."`, `shikibetsushi'...'` の3つの構文が新たに予約され、トークン分割されなくなりました。
24+
- 主に影響を受けるのはマクロです。例えば、`quote!{ #a#b }` と書くことはできなくなりました。
25+
- キーワードが特別扱いされることもないので、例えば `match"..." {}` と書くこともできなくなりました。
26+
- 識別子と後続の `#`, `"`, `'` の間に空白文字を挿入することで、エラーを回避できます。
27+
- エディション移行ツールは、必要な場所に空白を挿入してくれます。
1228

29+
<!--
1330
## Details
31+
-->
1432

33+
## 詳細
34+
35+
<!--
1536
To make space for new syntax in the future,
1637
we've decided to reserve syntax for prefixed identifiers and literals:
1738
`prefix#identifier`, `prefix"string"`, `prefix'c'`, and `prefix#123`,
1839
where `prefix` can be any identifier.
1940
(Except those prefixes that already have a meaning, such as `b'...'` (byte
2041
strings) and `r"..."` (raw strings).)
42+
-->
43+
44+
私達は、将来新しい構文を導入する余地を残すため、接頭辞付きの識別子とリテラルの構文を予約することにしました。
45+
予約されたのは、任意の識別子 `prefix` を用いて `prefix#identifier`, `prefix"string"`, `prefix'c'`, `prefix#123` のいずれかの形で書かれるものです。
46+
(ただし、`b'...'`(バイト文字列)や`r"..."`(生文字列)のように、すでに意味が割り当てられているものを除きます。)
2147

48+
<!--
2249
This provides syntax we can expand into in the future without requiring an
2350
edition boundary. We may use this for temporary syntax until the next edition,
2451
or for permanent syntax if appropriate.
52+
-->
53+
54+
これにより、将来エディションをまたくごとなく構文を拡張できるようになります。
55+
これを、次のエディションまでの一時的な構文のために使ったり、もし適切なら、恒久的な構文のために使ったりするでしょう。
2556

57+
<!--
2658
Without an edition, this would be a breaking change, since macros can currently
2759
accept syntax such as `hello"world"`, which they will see as two separate
2860
tokens: `hello` and `"world"`. The (automatic) fix is simple though: just
2961
insert a space: `hello "world"`. Likewise, `prefix#ident` should become
3062
`prefix #ident`. Edition migrations will help with this fix.
63+
-->
3164

65+
エディションの区切りがないと、これは破壊的変更に当たります。
66+
なぜなら、現在のマクロは、例えば `hello"world"` という構文を、 `hello``"world"` の2つのトークンとして受け入れるからです。
67+
もっとも、(自動)修正はシンプルで、`hello "world"` のように空白を入れるだけです。
68+
同様に、`prefix#ident``prefix #ident` とする必要があります。
69+
エディション移行ツールは、そのように修正してくれます。
70+
71+
<!--
3272
Other than turning these into a tokenization error,
3373
[the RFC][10] does not attach a meaning to any prefix yet.
3474
Assigning meaning to specific prefixes is left to future proposals,
3575
which will now&mdash;thanks to reserving these prefixes&mdash;not be breaking changes.
76+
-->
77+
78+
[これが提案された RFC][10] は、このような書き方をトークン分割エラーにすると決めているだけで、
79+
特定の接頭辞に意味を持たせることはまだしていません。
80+
接頭辞に何らかの役割を割り当てるのは、将来の提案にその余地が残されています。
81+
接頭辞が予約されたおかげで、今後は破壊的変更なく新しい構文を導入できます。
3682

83+
<!--
3784
Some new prefixes you might potentially see in the future (though we haven't
3885
committed to any of them yet):
86+
-->
87+
88+
例えば、以下のような接頭辞が使えるようになるかもしれません(ただし、いずれもまだ提案が固まったわけではありません):
3989

90+
<!--
4091
- `k#keyword` to allow writing keywords that don't exist yet in the current edition.
4192
For example, while `async` is not a keyword in edition 2015,
4293
this prefix would've allowed us to accept `k#async` in edition 2015
4394
without having to wait for edition 2018 to reserve `async` as a keyword.
95+
-->
4496

97+
- `k#keyword` で、現在のエディションにまだ導入されていないキーワードを書けるようにする。
98+
たとえば、2015 エディションでは `async` はキーワードではありませんが、
99+
このような接頭辞が使えたのならば、2018 エディションで `async` が予約語になるのを待たずに、2015 エディションでも `k#async` が使えたということになります。
100+
101+
<!--
45102
- `f""` as a short-hand for a format string.
46103
For example, `f"hello {name}"` as a short-hand for the equivalent `format!()` invocation.
104+
-->
105+
106+
- `f""` で、フォーマット文字列の略記とする。
107+
例えば、`f"hello {name}"` と書いたら、それと等価な `format!()` の呼び出しと見なす。
47108

109+
<!--
48110
- `s""` for `String` literals.
111+
-->
49112

113+
- `s""``String` リテラルを表す。
114+
115+
<!--
50116
- `c""` or `z""` for null-terminated C strings.
117+
-->
118+
119+
- `c""``z""` で、ヌル終端のC言語の文字列を表す。
51120

52121
[10]: https://github.com/rust-lang/rfcs/pull/3101
53122

54123

124+
<!--
55125
## Migration
126+
-->
127+
128+
## 移行
56129

130+
<!--
57131
As a part of the 2021 edition a migration lint, `rust_2021_prefixes_incompatible_syntax`, has been added in order to aid in automatic migration of Rust 2018 codebases to Rust 2021.
132+
-->
58133

134+
Rust 2018 のコードベースから Rust 2021 への自動移行の支援のため、2021 エディションには、移行用のリント`rust_2021_prefixes_incompatible_syntax` が追加されています。
135+
136+
<!--
59137
In order to have `rustfix` migrate your code to be Rust 2021 Edition compatible, run:
138+
-->
139+
140+
`rustfix` でコードを Rust 2021 エディションに適合させるためには、次のように実行します。
60141

61142
```sh
62143
cargo fix --edition
63144
```
64145

146+
<!--
65147
Should you want or need to manually migrate your code, migration is fairly straight-forward.
148+
-->
66149

150+
コード移行を手で行いたいか、行う必要があっても、移行は非常に簡単です。
151+
152+
<!--
67153
Let's say you have a macro that is defined like so:
154+
-->
155+
156+
例えば、次のように定義されたマクロがあったとしましょう:
68157

69158
```rust
70159
macro_rules! my_macro {
71160
($a:tt $b:tt) => {};
72161
}
73162
```
74163

164+
<!--
75165
In Rust 2015 and 2018 it's legal for this macro to be called like so with no space between the first token tree and the second:
166+
-->
167+
168+
Rust 2015 と 2018 では、以下のように、1つ目と2つ目のトークンの間に空白を入れることなくマクロを呼び出しても問題ありませんでした:
76169

77170
```rust,ignore
78171
my_macro!(z"hey");
79172
```
80173

174+
<!--
81175
This `z` prefix is no longer allowed in Rust 2021, so in order to call this macro, you must add a space after the prefix like so:
176+
-->
177+
178+
Rust 2021 では `z` という接頭辞は許されないので、このマクロを呼び出すためには、以下のように接頭辞の後にスペースを入れる必要があります:
82179

83180
```rust,ignore
84181
my_macro!(z "hey");
85-
```
182+
```

0 commit comments

Comments
 (0)