@@ -8,7 +8,6 @@ of programs, we need to tell the compiler to relax its restrictions a bit. For
88this, Rust has a keyword, `unsafe`. Code using `unsafe` has less restrictions
99than normal code does.
1010-->
11-
1211Rustの主たる魅力は、プログラムの動作についての強力で静的な保証です。
1312しかしながら、安全性検査は本来保守的なものです。
1413すなわち、実際には安全なのに、そのことがコンパイラには検証できないプログラムがいくらか存在します。
@@ -20,7 +19,6 @@ Rustの主たる魅力は、プログラムの動作についての強力で静
2019Let’s go over the syntax, and then we’ll talk semantics. `unsafe` is used in
2120four contexts. The first one is to mark a function as unsafe:
2221-->
23-
2422まずシンタックスをみて、それからセマンティクスについて話しましょう。
2523` unsafe ` は4つの場面で使われます。
26241つめは、関数がアンセーフであることを印付ける場合です。
@@ -36,7 +34,6 @@ unsafe fn danger_will_robinson() {
3634All functions called from [FFI][ffi] must be marked as `unsafe`, for example.
3735The second use of `unsafe` is an unsafe block:
3836-->
39-
4037たとえば、[ FFI] [ ffi ] から呼び出されるすべての関数は` unsafe ` で印付けることが必要です。
4138` unsafe ` の2つめの用途は、アンセーフブロックです。
4239
@@ -50,15 +47,13 @@ unsafe {
5047```
5148
5249<!-- The third is for unsafe traits:-->
53-
54503つめは、アンセーフトレイトです。
5551
5652``` rust
5753unsafe trait Scary { }
5854```
5955
6056<!-- And the fourth is for `impl`ementing one of those traits:-->
61-
6257そして、4つめは、そのアンセーフトレイトを実装する場合です。
6358
6459``` rust
@@ -71,7 +66,6 @@ It’s important to be able to explicitly delineate code that may have bugs that
7166cause big problems. If a Rust program segfaults, you can be sure it’s somewhere
7267in the sections marked `unsafe`.
7368-->
74-
7569大きな問題を引き起こすバグがあるかもしれないコードを明示できるのは重要なことです。
7670もしRustのプログラムがセグメンテーション違反を起こしても、バグは ` unsafe ` で印付けられた区間のどこかにあると確信できます。
7771
@@ -83,7 +77,6 @@ Safe, in the context of Rust, means ‘doesn’t do anything unsafe’. It’s a
8377important to know that there are certain behaviors that are probably not
8478desirable in your code, but are expressly _not_ unsafe:
8579-->
86-
8780Rustの文脈で、安全とは「どのようなアンセーフなこともしない」ことを意味します。
8881
8982> 訳注:
@@ -110,7 +103,6 @@ Rust cannot prevent all kinds of software problems. Buggy code can and will be
110103written in Rust. These things aren’t great, but they don’t qualify as `unsafe`
111104specifically.
112105-->
113-
114106Rustはソフトウェアが抱えるすべての種類の問題を防げるわけではありません。
115107Rustでバグのあるコードを書くことはできますし、実際に書かれるでしょう。
116108これらの動作は良いことではありませんが、特にアンセーフだとは見なされません。
@@ -119,7 +111,6 @@ Rustでバグのあるコードを書くことはできますし、実際に書
119111In addition, the following are all undefined behaviors in Rust, and must be
120112avoided, even when writing `unsafe` code:
121113-->
122-
123114さらに、Rustにおいては、次のものは未定義動作で、 ` unsafe ` コード中であっても、避ける必要があります。
124115
125116> 訳注:
@@ -183,15 +174,13 @@ avoided, even when writing `unsafe` code:
183174In both unsafe functions and unsafe blocks, Rust will let you do three things
184175that you normally can not do. Just three. Here they are:
185176-->
186-
187177アンセーフ関数・アンセーフブロックでは、Rustは普段できない3つのことをさせてくれます。たった3つです。それは、
188178
189179<!--
1901801. Access or update a [static mutable variable][static].
1911812. Dereference a raw pointer.
1921823. Call unsafe functions. This is the most powerful ability.
193183-->
194-
1951841 . [ 静的ミュータブル変数] [ static ] のアクセスとアップデート。
1961852 . 生ポインタの参照外し。
1971863 . アンセーフ関数の呼び出し。これが最も強力な能力です。
@@ -202,7 +191,6 @@ borrow checker’. Adding `unsafe` to some random Rust code doesn’t change its
202191semantics, it won’t just start accepting anything. But it will let you write
203192things that _do_ break some of the rules.
204193-->
205-
206194以上です。
207195重要なのは、 ` unsafe ` が、たとえば「借用チェッカをオフにする」といったことを行わないことです。
208196Rustのコードの適当な位置に ` unsafe ` を加えてもセマンティクスは変わらず、何でもただ受理するようになるということにはなりません。
@@ -213,14 +201,12 @@ You will also encounter the `unsafe` keyword when writing bindings to foreign
213201(non-Rust) interfaces. You're encouraged to write a safe, native Rust interface
214202around the methods provided by the library.
215203-->
216-
217204また、` unsafe ` キーワードは、Rust以外の言語とのインターフェースを書くときに遭遇するでしょう。
218205ライブラリの提供するメソッドの周りに、安全な、Rustネイティブのインターフェースを書くことが推奨されています。
219206
220207<!--
221208Let’s go over the basic three abilities listed, in order.
222209-->
223-
224210これから、その基本的な3つの能力を順番に見ていきましょう。
225211
226212## ` static mut ` のアクセスとアップデート。
@@ -231,7 +217,6 @@ Rust has a feature called ‘`static mut`’ which allows for mutable global sta
231217Doing so can cause a data race, and as such is inherently not safe. For more
232218details, see the [static][static] section of the book.
233219-->
234-
235220Rustには「` static mut ` 」という、ミュータブルでグローバルな状態を実現する機能があります。
236221これを使うことはデータレースが起こるおそれがあるので、本質的に安全ではありません。
237222詳細は、この本の[ static] [ static ] セクションを参照してください。
@@ -247,7 +232,6 @@ different memory safety and security issues. In some senses, the ability to
247232dereference an arbitrary pointer is one of the most dangerous things you can
248233do. For more on raw pointers, see [their section of the book][rawpointers].
249234-->
250-
251235生ポインタによって任意のポインタ演算が可能になりますが、いくつもの異なるメモリ安全とセキュリティの問題が起こるおそれがあります。
252236ある意味で、任意のポインタを参照外しする能力は行いうる操作のうち最も危険なもののひとつです。
253237詳細は、[ この本の生ポインタに関するセクション] [ rawpointers ] を参照してください。
@@ -261,7 +245,6 @@ do. For more on raw pointers, see [their section of the book][rawpointers].
261245This last ability works with both aspects of `unsafe`: you can only call
262246functions marked `unsafe` from inside an unsafe block.
263247-->
264-
265248この最後の能力は、` unsafe ` の両面とともに働きます。
266249すなわち、` unsafe ` で印付けられた関数は、アンセーフブロックの内部からのみ呼び出すことができます。
267250
@@ -270,7 +253,6 @@ This ability is powerful and varied. Rust exposes some [compiler
270253intrinsics][intrinsics] as unsafe functions, and some unsafe functions bypass
271254safety checks, trading safety for speed.
272255-->
273-
274256この能力は強力で多彩です。
275257Rustはいくらかの[ compiler intrinsics] [ intrinsics ] をアンセーフ関数として公開しており、また、いくつかのアンセーフ関数は安全性検査を回避することで、安全性とスピードを引き換えています。
276258
@@ -279,7 +261,6 @@ I’ll repeat again: even though you _can_ do arbitrary things in unsafe blocks
279261and functions doesn’t mean you should. The compiler will act as though you’re
280262upholding its invariants, so be careful!
281263-->
282-
283264繰り返しになりますが、アンセーフブロックと関数の内部で任意のことが _ できる_ としても、それをすべきだということを意味しません。コンパイラは、あなたが不変量を守っているかのように動作しますから、注意してください!
284265
285266[ intrinsics ] : intrinsics.html
0 commit comments