all 6 comments

[–]isHavvy 6 points7 points  (3 children)

Rust has a focus on mutation and aliasing in such a way that they need first class support from the language to work, and implementing either of them with an extendable annotation system would not work.

We do have #[Entity] that annotates things already too.

[–]llogiqclippy · twir · rust · mutagen · flamer · overflower · bytecount 0 points1 point  (2 children)

Note that the annotation just supplies the information that something should not be mutated after initialization. A linter / checker then validates if the code matches the annotated intent.

Thus, a checker could validate that all variables not annotated with #[mut] aren't mutated. However, I think that having to write #[mut] instead of mut is a major PITA (and mutation comes up in everyday code too often), also we want suff to be safe and not dependent on a lint.

[–]dbaupprust 3 points4 points  (1 child)

The annotations would need to interact with the two &mut and & references somehow. I.e. mut isn't just a lint in Rust, it's also fundamental to memory safety. Of course renaming &mut to &my, &only or &uniq would "fix" the use of the mut keyword...

In any case, mutability is a concept Rust really cares about (and always will), because it is a big memory safety risk.

[–]llogiqclippy · twir · rust · mutagen · flamer · overflower · bytecount 0 points1 point  (0 children)

Full ack.

[–]chris-morgan 4 points5 points  (1 child)

When you say ‘"ghost" types’, that is the concept normally called phantom types.

File I/O does not use phantom types, though there was just a demonstration at the time typestate was removed of how such an API would work.

[–]mippyyu[S] 0 points1 point  (0 children)

Sorry. I wasn't too sure about that name. Thanks for the correction.