4 ms·
Maybe this is off topic, but while reading this article it occurred to me that wouldn't it be useful if the ownership transfer is syntax highlighted? e.g. in
by vaibhavkul 11y ago
Maybe this is off topic, but while reading this article it occurred to me that wouldn't it be useful if the ownership transfer is syntax highlighted?
e.g. in
let new_owner = original_owner;
println!("{}", original_owner);
we could have original_owner on the second line have a different color signifying it doesn't own anything.
Or, does such a syntax highlighter already exist?
- kam 11y agoAtom with linter-rust highlights compile errors: http://i.imgur.com/ac7FTpW.png http://i.imgur.com/ac7FTpW.png Or do you have a more specific visualisation for moves/ownership in mind?
- vaibhavkul 11y agoDidn't know about linter-rust. Thanks for sharing. It didn't occur to me that: ownership transfer means variable cannot be used, so if it's used means there's an error, so checking for error itself gives you the information that you cannot use it. So highlighting error can be used instead of the specific ownership transfer. I don't know of any other specific cases where there's no error, but it would be helpful to have a different color for certain ownership semantics.
- kazagistar 11y agoThat syntax highlighter would basically have to be attached to a compiler. If a type is Copy, then it follows move semantics instead of copy semantics. Plus, ownership can be transferred through things like method invocations as well, depending on the type signature of the method.
- nv-vn 11y agoA bunch of languages are moving towards integrating IDE tools into the compiler with some kind of API. This allows for on-the-fly type checking, better syntax highlighting, better autocompletion, automatically generating bits of boilerplate, instantly testing a block of code, etc. For a language with a great example of this, check out Idris's IDE protocol: http://docs.idris-lang.org/en/latest/reference/ide-protocol.html http://docs.idris-lang.org/en/latest/reference/ide-protocol..... The way this works helps create an awesome feedback loop where the editor _is_ the REPL. Something like that would be a great addition to Rust and would definitely help improve the overall tooling for the language.
- kazagistar 11y agoThere is a fairly extensive plan for building out IDE support for Rust: https://www.rust-lang.org/ides.html https://www.rust-lang.org/ides.html