Stream: t-compiler

Topic: Rust's error message improvements over time


XAMPPRocky (Apr 27 2020 at 18:13, on Zulip):

Hey, I was writing a post about how Rust has improved over time, and one thing I wanted to show how much the error messages have improved. I was wondering if anyone had good specific examples of common mistakes that used to emit a confusing error message, and is now is much more clear?

LeSeulArtichaut (Apr 27 2020 at 18:14, on Zulip):

You could probably navigate through the closed D-* labeled issues?

XAMPPRocky (Apr 27 2020 at 18:19, on Zulip):

Ah, there's literally a confusing category, thanks!

Bastian Kauschke (Apr 27 2020 at 18:28, on Zulip):

one of the big improvements is the formatting IMO

fn main() {
    let mut a = String::new();
    let _a = &mut a;
    let _b = a;
    std::mem::drop(_a);
}

current nightly: (missing colors here)

error[E0505]: cannot move out of `a` because it is borrowed
 --> src/main.rs:4:14
  |
3 |     let _a = &mut a;
  |              ------ borrow of `a` occurs here
4 |     let _b = a;
  |              ^ move out of `a` occurs here
5 |     std::mem::drop(_a);
  |                    -- borrow later used here

error: aborting due to previous error

1.0.0:

src/main.rs:4:9: 4:11 error: cannot move out of `a` because it is borrowed
src/main.rs:4     let _b = a;
                      ^~
src/main.rs:3:19: 3:20 note: borrow of `a` occurs here
src/main.rs:3     let _a = &mut a;
                                ^
error: aborting due to previous error
Jake Goulding (Apr 27 2020 at 18:39, on Zulip):

This seems like the kind of thing you could ask on URLO and get tons of people responding with their favorite changes.

simulacrum (Apr 27 2020 at 18:42, on Zulip):

@XAMPPRocky yeah, I'd recommend a URLO post -- there's also a blog post from 2016 or 2017 I think about the new diagnostic format that @Bastian Kauschke references

simulacrum (Apr 27 2020 at 18:42, on Zulip):

the D-* label is very recent, circa early 2020 I think

Esteban Küber (Apr 27 2020 at 18:45, on Zulip):

How far back do you want to go?

Esteban Küber (Apr 27 2020 at 18:45, on Zulip):

Anything pre 18 is not as well categorized, but A-diagnostics existed

Bastian Kauschke (Apr 27 2020 at 18:45, on Zulip):

~T

Esteban Küber (Apr 27 2020 at 18:46, on Zulip):

Also look at my PRs I would say :sweat_smile:

Esteban Küber (Apr 27 2020 at 18:48, on Zulip):

One thing that I haven't had the time to do is use rustup to get every stable rustc, run all the UI test suite and pipe the output to save it as colorized html

Esteban Küber (Apr 27 2020 at 18:49, on Zulip):

That way you can make the progression of changes for code we accept today over time

Jake Goulding (Apr 27 2020 at 18:50, on Zulip):

And rub some magic animated GIF on that ;-) (there's also a powerpoint transition that does that...)

XAMPPRocky (Apr 27 2020 at 18:50, on Zulip):

@Esteban Küber 1.0.0

Esteban Küber (Apr 27 2020 at 18:52, on Zulip):

estebank.github.io/rust has a slide only for e0308 if you go right enough and then down

Esteban Küber (Apr 27 2020 at 18:52, on Zulip):

But I did that by hand

XAMPPRocky (Apr 27 2020 at 18:52, on Zulip):

I found a pretty good one.

use std::io::Write;

fn trait_obj(w: &Write) {
    generic(w);
}

fn generic<W: Write>(_w: &W) {}

1.2.0 error message

1.43.0 error message

Esteban Küber (Apr 27 2020 at 18:53, on Zulip):

If you wait a week it should be even better (I have some bounds improvements waiting review)

Jake Goulding (Apr 27 2020 at 18:54, on Zulip):

Anything that added help is likely to be a good start. Also, I know that the borrow checker errors improved a lot, and that's a combo of display and content improvements.

Esteban Küber (Apr 27 2020 at 18:56, on Zulip):

I would look around the UI test stdout files that look nice now and try them on older compilers if you don't want to look at PRs or closed tickets

Esteban Küber (Apr 27 2020 at 18:59, on Zulip):

This is a good example as well, I think https://godbolt.org/z/wieST7

XAMPPRocky (Apr 27 2020 at 19:01, on Zulip):

Definitely Screenshot-2020-04-27-at-21.01.08.png

Bastian Kauschke (Apr 27 2020 at 19:03, on Zulip):

snice

Sebastian Malton (Apr 27 2020 at 19:19, on Zulip):

My recent PR to add an error that says that fn main() cannot be async landed recently. Before that it only said that main can only return types that implement Termination

marmeladema (Apr 27 2020 at 21:04, on Zulip):

For me its nll error messages about lifetimes that is a game changer.

Last update: Jun 04 2020 at 17:40UTC