5 ms·
It's pretty amazing how detailed and helpful Rust's error messages are. rust_dangling.rs:6:5: 6:6 error: cannot borrow `v` as mutable because it is also bo
by rudolf0 12y ago
It's pretty amazing how detailed and helpful Rust's error messages are.
rust_dangling.rs:6:5: 6:6 error: cannot borrow `v` as mutable because it is also borrowed as immutable
rust_dangling.rs:6 v.push(6);
^
rust_dangling.rs:4:14: 4:15 note: previous borrow of `v` occurs here; the immutable borrow prevents subsequent moves or mutable borrows of `v` until the borrow ends
rust_dangling.rs:4 let x = &v[0];
^
rust_dangling.rs:8:2: 8:2 note: previous borrow ends here
- aikah 12y agoyou got that right, I wish all languages did that,and why not, even suggest modifications to the code in order for it to compile or run... Errors should be an opportunity for programmers to learn, it shouldn't feel like a punishment. But we'll get there eventually.
- stormbrew 12y agoObviously not so much for the kind of memory errors the GP is talking about, but clang/clang++ do provide similarly detailed error messages, including suggestions for name-related errors as to what you might have meant (either because a different variable provides the member you specified or becuase of a similarly spelled name).
- frik 12y agoOlder Visual C++ and older gcc gpp had nasty error messages.
- stormbrew 12y agoOlder? They still do. That's why I was specifically talking about clang/clang++.
- pcwalton 12y agoclang was what I based the current Rust compiler's error messages on. Matching its quality was a design goal from the start, since I think that one of the biggest reasons for clang's success was the quality of its error messages. Diagnostics are the UX of a compiler, and so they're deserving of the exact same care that is put into mobile app or Web design.
- stormbrew 12y agoYes, absolutely. I have a theory that a big part of the reason clang leapfrogged g++ so quickly on these things is because it was (initially aiming to) dogfood itself, So getting better error messages than g++ could give was an early and high priority task to its first users.
- evincarofautumn 12y agoI write compilers as a hobby. Providing good error messages is incredibly difficult—the compiler has a ton of information at hand, but it’s hard to know what’s actually useful to present, largely because you can only guess at the programmer’s actual intent.
- amelius 12y ago> It's pretty amazing how detailed and helpful Rust's error messages are. The quality of the error messages is a property of the compiler, not of the language. But of course, a well-designed language also provides the abstractions that ultimately can lead to good error messages.
- lelandbatey 12y agoI really love Rust's error messages, but I do wish I could get some more arbitrary code inspection prior to the compilation step. For example, sometimes you may declare something with some odd syntax and Rust effectively say "I was expecting type `A`, but this is type `B`." Frequently, I want to have a little more insight into what's going on, but the inability to maybe write some code that will print out information about something causing a compile error is problematic. That's the thing about Rust: because the burden of debugging is so shifted to the compilation step, Rust absolutely HAS to have good error messages because that's all you have to work with. However, I feel this shift in workflow can be overcome with different tooling, and I suspect this is mostly a symptom of being new to the language.
- bjz_ 12y agoYeah, I could imagine some kind of lifetime visualization tool that could be added to an IDE. Would be very useful.
- kvark 12y agoAgreed! I believe this can be accomplished by a third-party library using lint plugins: https://doc.rust-lang.org/book/plugins.html#lint-plugins https://doc.rust-lang.org/book/plugins.html#lint-plugins