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

推荐订阅源

K
Kaspersky official blog
Engineering at Meta
Engineering at Meta
D
DataBreaches.Net
Stack Overflow Blog
Stack Overflow Blog
Microsoft Security Blog
Microsoft Security Blog
Y
Y Combinator Blog
B
Blog RSS Feed
GbyAI
GbyAI
P
Proofpoint News Feed
aimingoo的专栏
aimingoo的专栏
MyScale Blog
MyScale Blog
D
Docker
阮一峰的网络日志
阮一峰的网络日志
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recorded Future
Recorded Future
美团技术团队
The Register - Security
The Register - Security
V
Visual Studio Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Tailwind CSS Blog
爱范儿
爱范儿
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
The Blog of Author Tim Ferriss
博客园 - 司徒正美
量子位
B
Blog
F
Fortinet All Blogs
Martin Fowler
Martin Fowler
博客园 - 【当耐特】
MongoDB | Blog
MongoDB | Blog
A
About on SuperTechFans
I
InfoQ
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
有赞技术团队
有赞技术团队
雷峰网
雷峰网
大猫的无限游戏
大猫的无限游戏
J
Java Code Geeks
L
LangChain Blog
Latest news
Latest news
S
SegmentFault 最新的问题
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Blog — PlanetScale
Blog — PlanetScale
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Cisco Talos Blog
Cisco Talos Blog
F
Full Disclosure
C
Cisco Blogs
D
Darknet – Hacking Tools, Hacker News & Cyber Security
W
WeLiveSecurity
T
Tenable Blog
T
Tor Project blog

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 Launching the 2018 State of Rust Survey 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 The Rust Team All Hands in Berlin: a Recap Increasing Rust’s Reach 2018 Announcing Rust 1.25 Rust's 2018 roadmap Announcing Rust 1.24.1 Announcing Rust 1.24 The 2018 Rust Event Lineup Announcing Rust 1.23 New Year's Rust: A Call for Community Blogposts Rust in 2017: what we achieved Announcing Rust 1.22 (and 1.22.1) Fearless Concurrency in Firefox Quantum Announcing Rust 1.21 impl Future for Rust Rust 2017 Survey Results Announcing Rust 1.20 Announcing Rust 1.19 The 2017 Rust Conference Lineup Rust's 2017 roadmap, six months in Increasing Rust’s Reach Announcing Rust 1.18 Two years of Rust The Rust Libz Blitz Launching the 2017 State of Rust Survey Announcing Rust 1.17 Announcing Rust 1.16 Rust's language ergonomics initiative Announcing Rust 1.15.1 Rust's 2017 roadmap Announcing Rust 1.15 Announcing Rust 1.14 Announcing the First Underhanded Rust Contest Announcing Rust 1.13 Announcing Rust 1.12.1 Announcing Rust 1.12 Incremental Compilation Announcing Rust 1.11 The 2016 Rust Conference Lineup Announcing Rust 1.10 State of Rust Survey 2016 Announcing Rust 1.9 One year of Rust Taking Rust everywhere with rustup Launching the 2016 State of Rust Survey Cargo: predictable dependency management Introducing MIR Announcing Rust 1.8 Announcing Rust 1.7 Announcing Rust 1.6 Announcing Rust 1.5 Announcing Rust 1.4 Announcing Rust 1.3 Rust in 2016 Announcing Rust 1.2 Rust 1.1 stable, the Community Subteam, and RustCamp Announcing Rust 1.0 Abstraction without overhead: traits in Rust Rust Once, Run Everywhere Mixing matching, mutation, and moves in Rust Fearless Concurrency with Rust Announcing Rust 1.0 Beta Announcing Rust 1.0.0.alpha.2 Rust 1.0: status report and final timeline Announcing Rust 1.0 Alpha Rust 1.0: Scheduling the trains Yehuda Katz and Steve Klabnik are joining the Rust Core Team Cargo: Rust's community crate host Stability as a Deliverable Road to Rust 1.0
Shape of errors to come
Sophia June Turner · 2016-08-10 · via Rust Blog

There are changes afoot in the Rust world. If you've tried out the latest nightly, you'll notice something is a little different. For the past few months we've been working on new way of reporting errors that's easier to read and understand. This is part of an on-going campaign to improve Rust's usability across the board. We mentioned ways to help us make the transition to the new errors, and already many people have jumped in (and thank you to those volunteers!)

Let's dive in and see what's changed. We'll start with a simple example:

fn borrow_same_field_twice_mut_mut() {
    let mut foo = make_foo();
    let bar1 = &mut foo.bar1;
    let _bar2 = &mut foo.bar1;
    *bar1;
}

Here we make the error of mutably borrowing the same value twice. This is a classic error in Rust. Sure enough, the error the previous compiler gave us says pretty much that:

Picture of old error style

The problem though is that it takes a few seconds to look at the message, orient yourself, and find the critical pieces. This time loss adds up. What if, instead, we cleared away everything that slows down how you read the error message?

This is the new error format. It's designed around the fundamental observation that errors should focus on the code you wrote. By doing so, you can much more easily see the context of what is going on.

Design

The key insight is putting your source code front and center - everything you see in the output builds on your code. By using the code you wrote as the context, we give you an easy way to know at a glance where the issue is occurring.

Picture of new constant eval error

Constant evaluation errors

Next, once we know the location, we need to explain what is going wrong. We do this by labeling points of interest in the code that helped explain the error. The most obvious place to begin labeling is where the error has occurred. It's the "what" of the error.

In this example, you can see how we use these primary labels. With them, your eyes can see both the problematic code, and a few words about the problem. Since this is the most important place to see first, we give them a bold red look with a characteristic ^^^ underline. You'll notice in the example that the combination allows you to quickly spot the error and understand what's going wrong.

Picture of new trait mismatch

Mismatch with trait requirement error

The source of the error is not the only point of interest. There are often other points of interest that help describe "why" an error is occurring. By reading these secondary labels, you can understand better what is going wrong. These labels are shown in the same order they appear in your code, again, to ensure you're always able to, at a glance, understand where you are.

In this example, secondary labels show the original requirement from the trait, so you can see it at the same time and compare the requirement and implementation for yourself.

Primary and secondary labels work together to tell a story about what went wrong. With Rust's big focus on the borrow-checker and memory safety, users may see unfamiliar concepts when they encounter one of these errors. These labels help to walk them through how even unfamiliar errors, like borrow errors, occur.

Picture of new type name not found

Name not in scope, with suggestions

Sometimes there's too much information to fit on a label, so the new format also supports attaching additional notes. Just like the previous error format, the new format supports warnings, suggestions, hints, and more.

Extended error messages

Once we updated the error message format, we looked for other areas we could apply the lessons we'd learned. The clear winner here were the --explain messages. As the name implies, the --explain feature allows developers to explore unfamiliar error messages with longer, more verbose, explanations.

Today, when you can call --explain, you pass an error code. The compiler then prints out an extended message that goes into more detail about how errors of that form occur:

$ rustc --explain E0200

Unsafe traits must have unsafe implementations. This error occurs when an
implementation for an unsafe trait isn't marked as unsafe. This may be resolved
by marking the unsafe implementation as unsafe.

struct Foo;

unsafe trait Bar { }

// this won't compile because Bar is unsafe and impl isn't unsafe
impl Bar for Foo { }
// this will compile
unsafe impl Bar for Foo { }

This has been a great way to help bridge between an error and learning an unfamiliar concept in Rust.

While this message is helpful, it uses a general example that may not be related to your code. Taking a page from the error message work, we'll be updating the explain messages to focus on your code. For example, taking the borrow-checker error we started with, we might have an extended error message that looks like:

error[E0499]: cannot borrow `foo.bar1` as mutable more than once at a time
  --> src/test/compile-fail/borrowck/borrowck-borrow-from-owned-ptr.rs:29:22

The borrow checker detected that `foo.bar1` was borrowed multiple
times as a mutable value. In Rust, this can not be done safely because
there may be multiple owners of the value who may write to it at the
same time. If this happens in parallel, the resulting value may be in
an unknown state.

Because this is unsafe, Rust disallows having multiple owners of the
same mutable value.

This is the first time `foo.bar1` is borrowed mutably.

28 |     let bar1 = &mut foo.bar1;
   |                     --------

And this is the second time `foo.bar1` is borrowed mutably. This is
where the error occurs.

29 |     let _bar2 = &mut foo.bar1;
   |                      ^^^^^^^^

Note that the first borrow of `foo.bar1` continues until the borrow
is released. During this time, no additional borrows can occur. This
first borrow ends here:

31 | }
   | -

After the first borrow has ended you are able to borrow it again. To
fix this issue, if you need to borrow a value as mutable more than
once, ensure that the span of time they are borrowed do not overlap.

In the above, you see a possible output from this new templated-style. Those of you familiar with the Elm style may recognize that the updated --explain messages draw heavy inspiration from the Elm approach.

Currently, this format is still under design and development. If you'd like to help us shape what extended errors looks like, come jump into the #rust-cli channel on irc.mozilla.org.

I want to help!

Great! We love the enthusiasm. There's a lot to do, and a lot of skills that could help us in different ways. Whether you're good at unit tests, writing docs, writing code, or working on designs, there are places to jump in.

Conclusion

Improving Rust is an on-going activity. With the importance of addressing Rust's learning curve a key theme in the Rust survey we're as motivated as ever to find any confusing or distracting part of the Rust experience and give it a healthy amount of polish. Errors are one area where we're applying that polish helps us improve the learning curve bit by bit, and we're looking forward to seeing how far we can go.