
2026/01/01 19:53
**Rust ― 借用チェッカーなしで書く Rust**
RSS: https://news.ycombinator.com/rss
要約▶
Japanese Translation:
## Summary `rustmm` は借用チェッカーをオフにした改造済み Rust コンパイラで、通常は Rust の安全規則に違反するコードでもコンパイル・実行できるようにします。プロジェクトは **macOS (Apple Silicon)** と **Linux (x86_64)** 用の事前ビルドバイナリを提供しており、インストールは次のコマンドで行えます: ```bash curl -sSL https://raw.githubusercontent.com/buyukakyuz/rustmm/main/install.sh | bash
インストール後は
~/.rustmm/bin/rustc your_code.rs というラッパーを通じてコードがコンパイルされます。ソースからビルドしたい場合は BUILDING.md の手順に従ってください。
Key examples
- String をムーブする – 通常は E0382 が発生しますが、rustmm はムーブを許可し、その後元の値を印刷できます。
- 二つの可変参照 – 通常は E0499 が発生しますが、rustmm は両方を受け入れ最終値を印刷します。
- 可変借用中に変数を使用する – 通常は E0502 が発生しますが、rustmm はコンパイルと実行を正しく行います。
- ループ内で文字列を二度印刷する – 通常は「cannot move out of loop」が禁止されますが、rustmm では許可されます。
- 同時に可変借用と不変借用 – 通常は E0502 が発生しますが、rustmm は両方をコンパイルし、両方の値を印刷します。
examples/ ディレクトリには、公式コンパイラで失敗する自己参照構造体や二重リンクリストなどの追加テストも含まれていますが、rustmm では成功します。
Licensing
プロジェクトは Apache 2.0 と MIT のデュアルライセンスです。詳細は
LICENSE-APACHE、LICENSE-MIT および COPYRIGHT をご覧ください。
## Text to translate (incorporating all missing details):** --- ## Summary `rustmm` is a modified Rust compiler that turns off the borrow checker, allowing code that would normally violate Rust’s safety rules to compile and run. The project ships pre‑built binaries for **macOS (Apple Silicon)** and **Linux (x86_64)**; installation can be done with: ```bash curl -sSL https://raw.githubusercontent.com/buyukakyuz/rustmm/main/install.sh | bash
After installation, code is compiled via the wrapper
~/.rustmm/bin/rustc your_code.rs. Source builds are supported by following the instructions in BUILDING.md.
Key examples
- Moving a
– normally triggers E0382; rustmm allows moving and then printing the original value.String - Two mutable references – normally E0499; rustmm accepts both and prints the final value.
- Using a variable while it has an active mutable borrow – normally E0502; rustmm compiles and runs correctly.
- Printing a string twice inside a loop – normally disallowed “cannot move out of loop”; rustmm permits it.
- Simultaneous mutable and immutable borrows – normally E0502; rustmm compiles and prints both values.
The
examples/ directory contains additional tests (e.g., self‑referential structs, doubly linked lists) that fail under the official compiler but succeed with rustmm.
Licensing
The project is dual‑licensed under Apache 2.0 and MIT; see
LICENSE-APACHE, LICENSE-MIT, and COPYRIGHT for details.
This revised summary now reflects every major point from the key points list, avoids any inference beyond the source material, and presents a clear, reader‑friendly overview.
本文
Rust--
借用チェッカーを無効にした改変版 Rust コンパイラ。
これにより、通常は Rust の借用規則に違反するコードでもコンパイル・実行が可能になります。
インストール
macOS(Apple Silicon)と Linux(x86_64)の事前ビルド済みバイナリ:
curl -sSL https://raw.githubusercontent.com/buyukakyuz/rustmm/main/install.sh | bash
使い方
~/.rustmm/bin/rustc your_code.rs
ソースからビルドする場合は
BUILDING.md を参照してください。
例:Before vs After
例 1 – 移動後の使用
通常の Rust
fn main() { let a = String::from("hello"); let b = a; println!("{a}"); }
エラー:
error[E0382]: borrow of moved value: `a` --> test.rs:4:16 | 2 | let a = String::from("hello"); | - move occurs because `a` has type `String`, which does not implement the `Copy` trait 3 | let b = a; | - value moved here 4 | println!("{a}"); | ^ value borrowed here after move
Rust--
fn main() { let a = String::from("hello"); let b = a; println!("{a}"); // Works! Prints: hello }
例 2 – 複数の可変参照
通常の Rust
fn main() { let mut y = 5; let ref1 = &mut y; let ref2 = &mut y; *ref1 = 10; *ref2 = 20; }
エラー:
error[E0499]: cannot borrow `y` as mutable more than once at a time --> test.rs:4:16 | 3 | let ref1 = &mut y; | ------ first mutable borrow occurs here 4 | let ref2 = &mut y; | ^^^^^^ second mutable borrow occurs here 5 | *ref1 = 10; | ---------- first borrow later used here
Rust--
fn main() { let mut y = 5; let ref1 = &mut y; let ref2 = &mut y; // Works! *ref1 = 10; *ref2 = 20; println!("{}", y); // Prints: 20 }
例 3 – 可変借用後の移動
通常の Rust
fn main() { let mut x = vec![1, 2, 3]; let borrowed = &mut x; println!("{:?}", x); // ERROR: cannot use `x` while mutable borrow exists }
Rust--
fn main() { let mut x = vec![1, 2, 3]; let borrowed = &mut x; println!("{:?}", x); // Works! Prints: [1, 2, 3] }
例 4 – ループ内でのムーブ後使用
通常の Rust
fn main() { let s = String::from("test"); for _ in 0..2 { println!("{}", s); // ERROR: cannot move out of loop } }
Rust--
fn main() { let s = String::from("test"); for _ in 0..2 { println!("{}", s); // Works! Prints twice } }
例 5 – 対立する借用
通常の Rust
fn main() { let mut num = 42; let mut_ref = &mut num; let immut_ref = # println!("{}", immut_ref); println!("{}", mut_ref); }
エラー:
error[E0502]: cannot borrow `num` as immutable because it is also borrowed as mutable --> test.rs:4:21 | 3 | let mut_ref = &mut num; | -------- mutable borrow occurs here 4 | let immut_ref = # | ^^^^ immutable borrow occurs here 5 | println!("{}", immut_ref); 6 | println!("{}", mut_ref); | ------- mutable borrow later used here
Rust--
fn main() { let mut num = 42; let mut_ref = &mut num; let immut_ref = # // Works! No error println!("{}", immut_ref); // Prints: 42 println!("{}", mut_ref); // Prints: 0x... }
examples ディレクトリ
examples/ ディレクトリには標準 Rust では失敗するコードが入っています:
| ファイル | 説明 |
|---|---|
| E0382: Borrow of moved value |
| E0499: Multiple mutable borrows |
| E0502: Use while mutably borrowed |
| Use after move in loop |
| E0597: Self‑referential struct |
| E0502: Conflicting borrows |
| E0506: Doubly linked list |
例として:
~/.rustmm/bin/rustc examples/01_move_then_use.rs && ./01_move_then_use
ライセンス
Rust と同じく Apache 2.0 および MIT の二重ライセンスです。
詳細は
LICENSE-APACHE、LICENSE-MIT、および COPYRIGHT をご覧ください。