Hacker News new | ask | show | jobs
by sundarurfriend 1115 days ago
I thought working with the lossless syntax tree was the key to Rust's pin-point precise error messages. How does rust-analyzer get and print the specific point of error if it throws away the non-essential information before that stage? I suppose the position information is stored along with the Error nodes, in the original parsing?
1 comments

In general, if you keep the source code positions of every nontrivial token, and you keep the raw source code, then yeah you can print out those pretty specific point error messages regardless of whether you keep your trees lossless. Also, if you want to include filename in your messages (perhaps because unlike Lox your language supports imports), then you'll need more than just lossless trees to store the necessary information.

I'm not sure exactly how Rust and rust-analyzer keep track of the info necessary to their excellent error messages and diagnostics, but I wouldn't be surprised if pinpoint messages were not the primary motivation for rust-analyzer to do lossless parsing.