Where is the Rust language specification?

How this language don't have a spec even 1.0 is released few years age.

so everything in Rust in undefined. then Rust has more undefined behavior than C.

Here's the specification Introduction - The Rust Reference

1 Like

The Rust reference is explicitly not a spec, but it describes most of the behavior of the compiler as it stands today, so it's the closest thing there is at the moment.

For the most part though, rustc itself is the spec.

so everything in Rust in undefined. then Rust has more undefined behavior than C.

That's not what 'undefined behavior' means - that term has a very specific meaning in the context of C and Rust!

Undefined behaviour is when the result of doing something is explicitly stated to be undefined by the compiler developers. This allows the compiler to then rely on the fact that it will never occur (e.g. in order to carry out optimizations).

For example, if you use unsafe and raw pointers to break the pointer aliasing rules, the compiler is free to completely miscompile your code if it feels like it, because you have done something which is stated to cause undefined behaviour.

A better way to put it would be to say that Rust's behaviour is unspecified - but given the existence of the reference, I'm not sure I'd agree with that. Just because there's not an official spec, doesn't mean that the behaviour of the compiler isn't predictable/consistent/well-documented.


It's also worth noting that the sort of specification C has exists in order to ensure portability between different compiler implementations. Rust currently only has one implementation, so it isn't felt that there is a need for such a specification. Before the C specifications, the K&R book was the main reference for C, but that is written in a more informal style than what you would expect of a specification, and aimed at programmers more than at compiler writers. Rust has plenty of documentation in that more informal style, particularly the Rust book and standard library documentation.


Some more resources: The Sealed Rust project is working on a formal specification of a subset of Rust. Stacked Borrows is a formal model of Rust’s aliasing rules. And the UCG working group is actively working on other documentation that will eventually become part of the language specification.


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.