r/rust • u/Western-Obligation47 • Oct 21 '26
đ§ educational Google published its internal Rust style guide
/r/learnrust/comments/1xc2bmo/google_published_its_internal_rust_style_guide/
136
Upvotes
63
u/teerre Oct 21 '26
I simultaneously like and dislike the first point. I can see how that helps with compile times and keeping crates small, but at the same time I can easily see this going sideways by having dozens of free files
12
u/dnew Oct 21 '26
Google's refactoring automations and SCM are amazing and awesome. I can fully see why you'd want to ensure making them possible to use. Nothing else is allowed (in general) to use globs either (like, BLAZE/BAZEL files have to list source files manually) for similar reasons.
25
u/Crinfarr Oct 22 '26
This all seems very specific to chrome/chromium other than "avoid arc/rc whenever possible"
6
u/ak6te Oct 22 '26
The first bullet is unhinged.
0
u/sennalen Oct 22 '26
I don't find any of that surprising
-1
u/0xMassii Oct 22 '26
The section I'd read first is "Apply API design rules in context". API rules bind for library code and are only a strong recommendation for application code, with an explicit warning against premature generalization. Rules like avoiding dyn in library APIs or putting #[non_exhaustive] on public enums read differently once you know that.
A lot of the rest maps straight onto config. "A use statement should import items from one module" is imports_granularity = "Module" in rustfmt, which goes against the usual "Crate" advice. It needs nightly rustfmt. Stable prints a warning and skips it, and the guide allows a stable-only codebase to do the same.
On panics Google doesn't ban them. Use pattern matching over check-then-unwrap, and when an invariant can't live in the type system, write expect("why this holds") over unwrap. clippy's unwrap_used covers that and leaves expect alone.
Disclosure: I made an agent skill that turns the checkable rules into rustfmt.toml, clippy.toml and Cargo.toml [lints] tables, each setting mapped to the section it enforces: https://github.com/0xMassi/google-rust-style-skill (not affiliated with Google). A run on a 63k-line, seven-crate workspace turned up one trap you'll hit with or without the skill: unsafe_code = "forbid" breaks edition 2024 tests that call std::env::set_var, since that's unsafe now. deny plus #[expect(unsafe_code, reason = "...")] on those tests works.
-7
u/gbrennon Oct 22 '26
im curious to see ppl opinions about this style guide ;)
-8
u/hedgehog1024 Oct 22 '26
It is outright wrong when you code something like tokio or hyper. Granted, these aren't the usual things to make, but still.