Description
Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=a6f4c87ca812c201bfb57ef861c4d919
struct Thing;
fn main() {
let mut stuff: Vec<Thing> = Vec::new();
stuff.append(Thing);
}
The current output is:
error[E0308]: mismatched types
--> src/main.rs:6:18
|
6 | stuff.append(Thing);
| ^^^^^ expected `&mut Vec<Thing>`, found struct `Thing`
|
= note: expected mutable reference `&mut Vec<Thing>`
found struct `Thing`
Ideally the output should look like:
error[E0308]: mismatched types
--> src/main.rs:6:18
|
6 | stuff.append(Thing);
| ^^^^^
| |
| expected `&mut Vec<Thing>`, found struct `Thing`
| help: use `push` to add a single element
|
= note: expected mutable reference `&mut Vec<Thing>`
found struct `Thing`
There should be some kind of suggestion to use push
when a value T
is incorrectly append
-ed onto a Vec<T>
. This likely only trips up newcomers to rust, but I know a fair number of python users who had this as their first error message. There are likely some some other collections this could apply to, but Vec
would definitely constitute most of these mistakes.
If nobody is immediately opposed to this change, I would like to try to implement this. I would need some help with where to make this change, but this seems like a fair introduction into editing compiler output.
It may also be helpful to just add a section mentioning push
to the append
function docs.