4 ms·
Having some understanding of difference between value and reference types types (from c or c++) and reading documentation a bit might be necessary. Error messa
by Karliss 9y ago
Having some understanding of difference between value and reference types types (from c or c++) and reading documentation a bit might be necessary. Error messages sometimes also contain links to documentation in case you have no understanding of the topic. The most common problems I had so for was due to incorrect level of indirection. In such cases the cause is quite clear function returned/expected reference/value/Option<val>/Option<&val> and you tried to assign it to something else. Suggestions help learning how standard library API behaves without opening API reference. In case of unwrapping Option or limiting borrows lifetime the code may get a bit messy. In such case I recommend reading documentation/searching internet as there might language or standard library feature (sometimes even in the link given by error message but not message itself) that helps writing it cleaner without brute forcing the code. Due to type checking it is difficult to mess up worse than making ugly code or moving away object you didn't want(which will be pointed out by compiler if you try to use it afterwards).
- pjmlp 9y ago> value and reference types types (from c or c++) Applies to other languages as well.
- continuational 9y agoMany languages handle this internally; essentially all functional languages and all dynamically typed languages.
- pjmlp 9y agoAnd many others handle this externally, including some functional languages, in case you want a list, I can provide it.
- stevedonovan 9y agoOh yes - there will be some explicit type like std::vec::Vec<&std::string::String> in the error and that all-important '&' gets lost in the verbosity. Definitely necessary to learn to see the needle in that haystack. (Some have proposed simplifying the explicit types if no confusion results, but this could always done by a post-processor. I saved some of my sanity when doing C++ this way)
- bjz_ 9y ago> and that all-important '&' gets lost in the verbosity Perhaps some console colouring could help as well. I'd really like some type diffs on type mismatch errors (I think Dotty has this?). That could be super handy for quickly diagnosing errors - speaking as a reasonably experienced Rust user here.
- stevedonovan 9y agoWell, we already have a christmas tree colour issue. I think rustc could do better here - check whether types differ by only '&' and put out a hint. That is, by adding/removing &, could the error have been resolved?