OpenSource-Hub

rust

その他

rust-lang/rust

Rust 言語のメインリポジトリ。コンパイラ、標準ライブラリ、ドキュメントを含む。

概要

Rust プログラミング言語の公式ソースコードリポジトリであり、rustc コンパイラ、標準ライブラリ、ドキュメントを含む。Rust はパフォーマンスとメモリ安全性を重視し、ガベージコレクションなしでスレッドセーフを保証する。また、Cargo パッケージマネージャー、rustfmt フォーマットツール、Clippy 静的解析などの完全なツールチェーンを提供する。

README プレビュー

\n  \n    \n    \n    \n  \n\n[Website][Rust] | [Getting started] | [Learn] | [Documentation] | [Contributing]\n\n\nThis is the main source code repository for [Rust]. It contains the compiler,\nstandard library, and documentation.\n\n[Rust]: https://www.rust-lang.org/\n[Getting Started]: https://www.rust-lang.org/learn/get-started\n[Learn]: https://www.rust-lang.org/learn\n[Documentation]: https://www.rust-lang.org/learn#learn-use\n[Contributing]: CONTRIBUTING.md\n\n## Why Rust?\n\n- **Performance:** Fast and memory-efficient, suitable for critical services, embedded devices, and easily integrated with other languages.\n\n- **Reliability:** Our rich type system and ownership model ensure memory and thread safety, reducing bugs at compile-time.\n\n- **Productivity:** Comprehensive documentation, a compiler committed to providing great diagnostics, and advanced tooling including package manager and build tool ([Cargo]), auto-formatter ([rustfmt]), linter ([Clippy]) and editor support ([rust-analyzer]).\n\n[Cargo]: https://github.com/rust-lang/cargo\n[rustfmt]: https://github.com/rust-lang/rustfmt\n[Clippy]: https://github.com/rust-lang/rust-clippy\n[rust-analyzer]: https://github.com/rust-lang/rust-analyzer\n\n## Quick Start\n\nRead ["Installation"] from [The Book].\n\n["Installation"]: https://doc.rust-lang.org/book/ch01-01-installation.html\n[The Book]: https://doc.rust-lang.org/book/index.html\n\n## Installing from Source\n\nIf you really want to install from source (though this is not recommended), see\n[INSTALL.md](INSTALL.md).\n\n## Getting Help\n\nSee https://www.rust-lang.org/community for a list of chat platforms and forums.\n\n## Contributing\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md).\n\nFor a detailed explanation of the compiler's architecture and how to begin contributing, see the [rustc-dev-guide](https://rustc-dev-guide.rust-lang.org/).\n\n## License\n\nRust is primarily distributed under the terms of both the MIT license and the\nApache License (Versio

FAQ (5)

トラブル対応
Rust のエラー 'internal compiler error: encountered incremental compilation error with evaluate_obligation' を修正する方法

これはコードのバグではなく、インクリメンタルコンパイルキャッシュの破損によるICEです。インクリメンタルキャッシュをクリアすることで修正できます:

1. cargo clean -p <crate_name> を実行して(例:cargo clean -p jmap)、影響を受けるクレートのみをクリアするか、完全な cargo clean を実行してすべてのビルド成果物を消去してください。
2. cargo build で再コンパイルしてください。

エラーが繰り返し発生する場合は、環境変数 CARGO_INCREMENTAL=0 を設定するか、.cargo/config.toml に [build] incremental = false を追加して、インクリメンタルコンパイルを完全に無効にしてください。

これはコンパイラのバグであるため、最小限の再現コード(理想的には、変更前のコードと、リビルド時にICEを引き起こすパッチ)と、rustc --version の出力、およびエラーに含まれるフィンガープリントハッシュを添えて、https://github.com/rust-lang/rust/issues にも報告してください。

参照 Issue #164475
トラブル対応
なぜ私のRustプログラムはchecked_div().unwrap_unchecked()を使用するとopt-level 1以上でSIGFPE(ゼロ除算)によりクラッシュするのですか?また、それを回避するにはどうすればよいですか?

これはrustc/LLVMの既知の誤コンパイルバグです(rust-lang/rust #164431、約1.87から少なくともnightly 1.101までのバージョンに影響)。オプティマイザは checked_div(...).unwrap_unchecked() を生の div 命令にloweringし、その結果、関数間インライン化後にゼロの除数が渡される可能性があり、-C opt-level=1 以上でSIGFPE(終了コード136)が発生します。一方、-C opt-level=0 およびMiriでは問題なく動作します。バグが修正されるまでの回避策: 1) checked_div(...).unwrap_unchecked() を wrapping_div(...) に置き換える — クラッシュが発生しなくなります。2) 呼び出し元にインライン化される関数に #[inline(never)] を追加する — これにより、バグを引き起こす関数間インライン化がブロックされます。3) 最終手段として -C opt-level=0 でコンパイルする。なお、このバグはアドレスレイアウトにも敏感です: デフォルトのPIEビルドでは再現しますが、非PIEビルドでは確実には再現しません。

参照 Issue #164431
トラブル対応
riscv64 で libc クレートをコンパイルする際に発生する 'cannot find type c_char in this scope' エラーを修正するにはどうすればよいですか?

このE0425エラーは、古いバージョンのlibc(例:0.2.43)にはc_charのような基本的なC型に対するriscv64ターゲットの定義が含まれていないために発生します。libcを0.2.190以降にアップグレードすることで修正できます。依存関係のCargo.lockによってlibcのバージョンが固定されている場合(cargotestで使用されているxsvクレートなど)、影響を受けるクレートのディレクトリ内でcargo update -p libcを実行するか、Cargo.lock/Cargo.toml内のlibcのバージョンを手動で引き上げてから、再ビルドしてください。std::ffi::c_charをインポートするというコンパイラの提案には従わないでください。この定義の欠落はインポートの問題ではなく、バージョンの問題です。

参照 Issue #164339
トラブル対応
inherent_associated_types を使用した際の Rust ICE "item_bounds called on DefId" の修正方法

この内部コンパイラエラーは、rustc 1.98.0-nightly (485ec3fbc 2026-06-10) において、-Znext-solver=globally -Zassumptions-on-binders フラグを指定して再帰的な inherent associated types(例: type Assoc = &'a Foo<'a>::Assoc;)をコンパイルした際に発生します。修正方法: rustup update nightly で nightly 1.99.0 (ba28ff76f 2026-08-13) 以降に更新してください。そのバージョンでは問題は再現しなくなります。なお、inherent_associated_types は不完全な unstable 機能であり、コンパイラのクラッシュを引き起こすことが知られています。stable/beta では使用を避けてください。また、トリガーとなるコード自体も無効です(自己参照する関連型は E0271 の型不一致エラーを引き起こします)。そのため、関連型を自己参照しないように書き換えることで、影響を受けるバージョンでも解決できます。

参照 Issue #157774
トラブル対応
Rust 1.99 beta にアップグレードした後に発生する 'type annotations needed' エラーの修正方法

これはRust 1.99 betaにおける既知の型推論のリグレッションであり(bisectによりPR #158447と特定済み、issue #161913の重複)、ジェネリックコンストラクタに渡されたクロージャ(例:Foo::new(&1u8, |input| *input))で以前は型推論が機能していたコードに影響します。修正方法:このリグレッションが再現しなくなったRust 1.100.0-beta.7以降にアップグレードしてください。rustup updateを実行するか、rustup default stableでチャンネルを切り替えます。1.99 betaに留まらなければならない場合の回避策:クロージャの引数またはジェネリック引数に明示的な型注釈を追加する(例:|input: &u8| *input)か、let x: Foo<&u8, u8> = ...のようにバインディングに完全な型を指定してください。

参照 Issue #162109