Reputation: 48048
If you cannot use unstable modules with a stable compiler, how does Rust compile its std
? For example, std::Vec
uses alloc::raw_vec
, an unstable feature.
Upvotes: 13
Views: 5877
Reputation: 430673
No, you cannot use unstable features on stable Rust. That's the entire point of unstable features:
There are three problems with allowing unstable features on the stable release.
First, as the web has shown numerous times, merely advertising instability doesn’t work. Once features are in wide use it is very hard to change them – and once features are available at all, it is very hard to prevent them from being used. Mechanisms like “vendor prefixes” on the web that were meant to support experimentation instead led to de facto standardization.
Second, unstable features are by definition work in progress. But the beta/stable snapshots freeze the feature at scheduled points in time, while library authors will want to work with the latest version of the feature.
Finally, we simply cannot deliver stability for Rust unless we enforce it. Our promise is that, if you are using the stable release of Rust, you will never dread upgrading to the next release. If libraries could opt in to instability, then we could only keep this promise if all library authors guaranteed the same thing by supporting all three release channels simultaneously.
How does Rust compile its
std
?
There's no guarantee that Rust is built by a stable compiler, or that it is built by the same stable compiler that is offered for download. It would be pretty straight-forward to have a special compiler that is used to bootstrap the official compiler. See Reflections on Trusting Trust for ways this could be done nefariously.
Indeed, Rust previously used a special bootstrapping compiler, but nowadays it doesn't. Instead, there's a magic configuration value that allows unstable features to be used with the stable compiler. This was done so that Linux distributions could choose to build their own versions of Rust with their own toolchains.
I don't feel it appropriate to publicly share the exact details out of respect. The effort of finding the answer should be enough to dissuade most people from using it without a good reason. It doesn't seem ideal if theres a one-line answer that anyone can trivially find using a search engine without thinking about the consequences. If one cares enough, they can research the Rust source code and build system, which is of course open.
Use a nightly version of Rust if you need to use unstable features. This is the most honest method.
Upvotes: 14