Skip to content

Commit d4475f3

Browse files
committed
first draft of blog post about NLL transition
1 parent 0c68f94 commit d4475f3

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

posts/2019-10-28-nll-hard-errors.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
---
2+
layout: post
3+
title: "Completing the transition to the new borrow checker"
4+
author: Niko Matsakis
5+
---
6+
7+
For most of 2018, we've been issue warnings about various bugs in the
8+
borrow checker that we plan to fix -- about two months ago, in the
9+
current Rust nightly, those warnings became **hard errors**. In about
10+
two weeks, when the nightly branches to become beta, those hard errors
11+
will be in the beta build, and they will eventually hit stable on
12+
December 19th, as part of Rust 1.40.0. **If you're testing with
13+
Nightly, you should be all set -- but otherwise, you may want to go
14+
and check to make sure your code still builds. If not, we have advice
15+
for fixing common problems below.**
16+
17+
### Background: the non-lexical lifetime transition
18+
19+
When we [released Rust 2018 in Rust 1.31][2018], it included a new
20+
version of the borrow checker, one that implemented ["non-lexical
21+
lifetimes"][nll]. This new borrow checker did a much more precise
22+
analysis than the original, allowing us to eliminate a lot of
23+
unnecessary errors and make Rust easier to use. I think most everyone
24+
who was using Rust 2015 can attest that this shift was a big
25+
improvement.
26+
27+
### The new borrow checker also fixed a lot of bugs
28+
29+
What is perhaps less well understood is that the new borrow checker
30+
implementation *also* fixed a lot of bugs. In other words, the new
31+
borrow checker did not just accept more programs -- **it also rejected
32+
some programs that never should have been accepted in the first
33+
place!**
34+
35+
[2018]: https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html
36+
[nll]: https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html#non-lexical-lifetimes
37+
[MIR]: https://blog.rust-lang.org/2016/04/19/MIR.html
38+
39+
### Until recently, those fixed bugs produced warnings, not errors
40+
41+
As part of our commitment to stability, whenever we find bugs that
42+
impact existing code in a major way, we try to "phase in" those
43+
changes gradually. We usually begin with "Future Compatibility
44+
Warnings", for example, before moving those warnings to hard errors
45+
(sometimes a small bit at a time). Since the bug fixes to the borrow
46+
checker affected a lot of crates, we knew we needed a warning period
47+
before we could make them into hard errors.
48+
49+
To implement this warning period, we kept two copies of the borrow
50+
checker around (this is a trick we use quite frequently, actually).
51+
The new checker ran first. If it found errors, we didn't report them
52+
directly: instead, we ran the old checker in order to see if the crate
53+
*used* to compile before. If so, we reported the errors as Future
54+
Compatibility Warnings, since we were changing something that used to
55+
compile into errors.
56+
57+
### All good things must come to an end; and bad ones, too
58+
59+
Over time we have been slowly transitioning those future compatibility
60+
warnings into errors, a bit at a time. About two months ago, we
61+
decided that the time had come to finish the job. So, over the course
62+
of two PRs, we [converted all remaining warnings to errors][a] and
63+
then [removed the old borrow checker implementation][b].
64+
65+
[a]: https://github.com/rust-lang/rust/pull/63565
66+
[b]: https://github.com/rust-lang/rust/pull/64790
67+
68+
### What this means for you
69+
70+
**If you are testing your package with nightly, then you should be
71+
fine.** In fact, even if you build on stable, we always recommend that
72+
you test your builds in CI with the nightly build, so that you can
73+
identify upcoming issues early and report them to us.
74+
75+
**Otherwise, you may want to check your dependencies.** When we
76+
decided to remove the old borrow checker, we also analyzed which
77+
crates would stop compiling. For anything that seemed to be widely
78+
used, we made sure that there were newer versions of that crate
79+
available that *do* compile (for the most part, this had all already
80+
happened during the warning period). But if you have those older
81+
versions in your `Cargo.lock` file, and you are only using stable
82+
builds, then you may find that your code no longer builds once 1.40.0
83+
is released -- you will have to upgrade the dependency.
84+
85+
The most common crates that were affected are the following:
86+
87+
* `url` version 1.7.0 -- you can upgrade to 1.7.2, though you'd be better off upgrading to 2.1.0
88+
* `nalgebra` version 0.16.13 -- you can upgrade to 0.16.14, though you'd be better off upgrading to 0.19.0
89+
90+
You can find out which crates you rely upon using the [cargo-tree] command. If you find
91+
that you *do* rely (say) on `url` 1.7.0, you can upgrade to 1.7.2 by executing:
92+
93+
```bash
94+
cargo update -p url --vers 1.7.2
95+
```
96+
97+
[cargo-tree]: https://crates.io/crates/cargo-tree
98+
99+
### Want to learn more?
100+
101+
If you'd like to learn more about the kinds of bugs that were fixed --
102+
or if you are seeing errors in your code that you need to fix -- take
103+
a look at this [excellent blog post by Felix Klock][nllpost], which
104+
goes into great detail.
105+
106+
[nllpost]: http://blog.pnkfx.org/blog/2019/06/26/breaking-news-non-lexical-lifetimes-arrives-for-everyone/

0 commit comments

Comments
 (0)