This document lists Rust-related build errors that are noteworthy in the context of Chromium builds.
Chromium builds disallow unsafe Rust by default. Unexpected unsafe Rust can cause build errors below:
error: usage of an `unsafe` block error: declaration of an `unsafe` function error: implementation of an `unsafe` trait error: implementation of an `unsafe` method ... note: requested on the command line with `-F unsafe-code`
unsafe Rust is disallowed by default to:
unsafe Rust code//third_party/rust crates with allow_unsafe = false can get a bit less scrutiny).To fix the errors above you can either:
slice[i] or slice.get(i) rather than slice.get_unchecked(i), unless disassembly results show that the compiler cannot elide the checks and/or performance measurements show significant runtime difference)unsafe code in the given crate (ideally only for a small, easy-to-reason-about crate that encapsulates the unsafety behind a safe public API).BUILD.gn files (e.g. in first-party code) you can set allow_unsafe = true in rust_static_librarygnrt-generated BUILD.gn files you can set extra_kv.allow_unsafe property to true in third_party/rust/chromium_crates_io/gnrt_config.toml (and then regenerate BUILD.gn with tools/crates/run_gnrt.py gen).Chromium builds require an explicit opt-in to use unstable Rust features (see the policy in //tools/rust/unstable_rust_feature_usage.md). Unexpected usage of unstable Rust features can cause build errors below:
error[E0725]: the feature `feature_name` is not in the list of allowed features error[E0658]: use of unstable library feature `feature_name` ... note: see issue #XXXXX <https://github.com/rust-lang/rust/issues/XXXXX> for more information help: add `#![feature(feature_name)]` to the crate attributes to enable
To opt into allowing certain unstable features, you need to:
BUILD.gn of a Rust crate (justifying edits to the policy in //tools/rust/unstable_rust_feature_usage.md as needed)BUILD.gn files (e.g. in first-party code) you can set the following properties of rust_static_library:rustflags = [ "-Zallow-features=feature_name" ]configs -= [ "//build/config/compiler:disallow_unstable_features" ]gnrt-generated BUILD.gn files you can set extra_kv.allow_unstable_features property in third_party/rust/chromium_crates_io/gnrt_config.toml to the list of allowed feature names (and then regenerate BUILD.gn with tools/crates/run_gnrt.py gen).#![feature(feature_name)] to lib.rs.  See also:feature attribute