惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

人人都是产品经理
人人都是产品经理
MongoDB | Blog
MongoDB | Blog
Google DeepMind News
Google DeepMind News
L
LangChain Blog
J
Java Code Geeks
MyScale Blog
MyScale Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
WordPress大学
WordPress大学
小众软件
小众软件
Microsoft Security Blog
Microsoft Security Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
月光博客
月光博客
aimingoo的专栏
aimingoo的专栏
F
Fortinet All Blogs
I
InfoQ
博客园 - 聂微东
量子位
A
About on SuperTechFans
S
SegmentFault 最新的问题
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Apple Machine Learning Research
Apple Machine Learning Research
Hugging Face - Blog
Hugging Face - Blog
云风的 BLOG
云风的 BLOG
H
Help Net Security

Rust Blog

Security Advisory for Cargo (CVE-2026-5223) | Rust Blog Security Advisory for Cargo (CVE-2026-5222) | Rust Blog Project goals update — April 2026 (end of 2025H2) | Rust Blog Rust is participating in Outreachy | Rust Blog Raising the baseline for the `nvptx64-nvidia-cuda` target | Rust Blog Announcing Google Summer of Code 2026 selected projects | Rust Blog Announcing Rust 1.95.0 | Rust Blog docs.rs: building fewer targets by default | Rust Blog Changes to WebAssembly targets and handling undefined symbols | Rust Blog Announcing Rust 1.94.1 | Rust Blog Security advisory for Cargo | Rust Blog What we heard about Rust's challenges | Rust Blog Call for Testing: Build Dir Layout v2 | Rust Blog Announcing rustup 1.29.0 | Rust Blog Announcing Rust 1.94.0 | Rust Blog 2025 State of Rust Survey Results | Rust Blog Rust debugging survey 2026 | Rust Blog Update on the October 15, 2018 incident on crates.io Announcing Rust 1.29.2 Announcing Rust 1.29 Announcing Rust 1.28 What is Rust 2018? Announcing Rust 1.27.2 Announcing Rust 1.27.1 Security Advisory for rustdoc Announcing Rust 1.27 Announcing Rust 1.26.2 Announcing Rust 1.26.1 Rust turns three Announcing Rust 1.26
Formatting the compiler tree | Inside Rust Blog
Mark Rousskov on behalf of the compiler team · 2019-12-23 · via Rust Blog

What happened

We recently landed two PRs which together reformatted essentially all code in the compiler tree.

The first one, #65939, contained the initial formatting infrastructure. We currently use rustfmt directly, pinned to a version specified in src/stage0.txt. We expect to update it as needed, and otherwise once per cycle (coinciding with the bootstrap bump, most likely).

The second one which reformatted the majority of the codebase is #67540.

This change landed with the following rustfmt config. Note that this configuration is subject to change (in particular, merge_derives may be removed in the future), but should be fairly stable. Your editor should automatically pick this configuration up inside the rust-lang/rust repository (it is located in the rustfmt.toml file in the root).

version = "Two"
use_small_heuristics = "Max"
merge_derives = false

How to use formatting

You can reformat the repository with x.py fmt and x.py fmt --check to verify formatting; these commands are unfortunately somewhat slow today. Tidy will also currently run the latter of these two checks (x.py fmt --check) internally, but this may change in the future if we can't improve the speed of formatting the entire codebase.

Resolving conflicts

If you have an ongoing branch, you're likely to have merge conflicts. The following should help you resolve them:

#!/bin/bash

set -xeo pipefail

if [ "$1" = "from-rebase" ] ; then
	git rev-parse HEAD > /tmp/commit
	git rev-parse HEAD >> /tmp/old.shas
	./x.py fmt
	git commit -a --amend --no-edit
	git rev-parse HEAD >> /tmp/new.shas
	git reset --hard $(cat /tmp/commit)
else
	rm -f /tmp/old.shas /tmp/commit /tmp/new.shas
	git rebase 8eb7c58dbb7 --exec '../format.sh from-rebase'
	branch=$(git rev-parse --abbrev-ref HEAD) # get branch name
	git reset --hard 8eb7c58dbb7
	for sha in $(cat /tmp/new.shas); do
		git cherry-pick $sha -Xtheirs
	done
  # put yourself atop the format the world PR
  git rebase -Xtheirs a916ac22b9f7f1f0f7aba0a41a789b3ecd765018
fi

This script should be saved to format.sh in the parent directory of your Rust checkout, and then run git fetch upstream && ../format.sh. upstream should be the name of the rust-lang/rust remote.

Once the script runs, you will be based on the a916ac22b9f7f commit. You likely want to then run git rebase -i upstream/master or so to finish, but the script above gets you past the formatting PR at least.

This should mostly resolve conflicts correctly, but occasionally if you've edited something in imports (a common case I've encountered) or otherwise this will not resolve quite right. Usually though this will solve 99% of the problems and the rest can be fixed up manually afterwards.