You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `#[stable(feature = "foo", since = "1.420.69")]` attribute explicitly
52
-
marks an item as stabilized. Note that stable functions may use unstable things in their body.
59
+
marks an item as stabilized.
60
+
Note that stable functions may use unstable things in their body.
53
61
54
62
## rustc_const_unstable
55
63
56
64
The `#[rustc_const_unstable(feature = "foo", issue = "1234", reason = "lorem
57
-
ipsum")]` has the same interface as the `unstable` attribute. It is used to mark
58
-
`const fn` as having their constness be unstable. This is only needed in rare cases:
65
+
ipsum")]` has the same interface as the `unstable` attribute.
66
+
It is used to mark `const fn` as having their constness be unstable.
67
+
This is only needed in rare cases:
59
68
- If a `const fn` makes use of unstable language features or intrinsics.
60
69
(The compiler will tell you to add the attribute if you run into this.)
61
70
- If a `const fn` is `#[stable]` but not yet intended to be const-stable.
62
71
- To change the feature gate that is required to call a const-unstable intrinsic.
63
72
64
73
Const-stability differs from regular stability in that it is *recursive*: a
65
-
`#[rustc_const_unstable(...)]` function cannot even be indirectly called from stable code. This is
74
+
`#[rustc_const_unstable(...)]` function cannot even be indirectly called from stable code.
75
+
This is
66
76
to avoid accidentally leaking unstable compiler implementation artifacts to stable code or locking
67
-
us into the accidental quirks of an incomplete implementation. See the rustc_const_stable_indirect
77
+
us into the accidental quirks of an incomplete implementation.
78
+
See the rustc_const_stable_indirect
68
79
and rustc_allow_const_fn_unstable attributes below for how to fine-tune this check.
69
80
70
81
## rustc_const_stable
@@ -75,7 +86,8 @@ a `const fn` as having its constness be `stable`.
75
86
## rustc_const_stable_indirect
76
87
77
88
The `#[rustc_const_stable_indirect]` attribute can be added to a `#[rustc_const_unstable(...)]`
78
-
function to make it callable from `#[rustc_const_stable(...)]` functions. This indicates that the
89
+
function to make it callable from `#[rustc_const_stable(...)]` functions.
90
+
This indicates that the
79
91
function is ready for stable in terms of its implementation (i.e., it doesn't use any unstable
80
92
compiler features); the only reason it is not const-stable yet are API concerns.
81
93
@@ -105,7 +117,8 @@ To stabilize a feature, follow these steps:
105
117
1. Ask a **@T-libs-api** member to start an FCP on the tracking issue and wait for
106
118
the FCP to complete (with `disposition-merge`).
107
119
2. Change `#[unstable(...)]` to `#[stable(since = "CURRENT_RUSTC_VERSION")]`.
108
-
3. Remove `#![feature(...)]` from any test or doc-test for this API. If the feature is used in the
120
+
3. Remove `#![feature(...)]` from any test or doc-test for this API.
121
+
If the feature is used in the
109
122
compiler or tools, remove it from there as well.
110
123
4. If this is a `const fn`, add `#[rustc_const_stable(since = "CURRENT_RUSTC_VERSION")]`.
111
124
Alternatively, if this is not supposed to be const-stabilized yet,
@@ -121,14 +134,15 @@ and the associated
121
134
122
135
## allow_internal_unstable
123
136
124
-
Macros and compiler desugarings expose their bodies to the call
125
-
site. To work around not being able to use unstable things in the standard
137
+
Macros and compiler desugarings expose their bodies to the call site.
138
+
To work around not being able to use unstable things in the standard
126
139
library's macros, there's the `#[allow_internal_unstable(feature1, feature2)]`
127
140
attribute that allows the given features to be used in stable macros.
128
141
129
142
Note that if a macro is used in const context and generates a call to a
130
143
`#[rustc_const_unstable(...)]` function, that will *still* be rejected even with
131
-
`allow_internal_unstable`. Add `#[rustc_const_stable_indirect]` to the function to ensure the macro
144
+
`allow_internal_unstable`.
145
+
Add `#[rustc_const_stable_indirect]` to the function to ensure the macro
132
146
cannot accidentally bypass the recursive const stability checks.
133
147
134
148
## rustc_allow_const_fn_unstable
@@ -138,12 +152,14 @@ indirectly.
138
152
139
153
However, sometimes we do know that a feature will get stabilized, just not when, or there is a
140
154
stable (but e.g. runtime-slow) workaround, so we could always fall back to some stable version if we
141
-
scrapped the unstable feature. In those cases, the `[rustc_allow_const_fn_unstable(feature1,
155
+
scrapped the unstable feature.
156
+
In those cases, the `[rustc_allow_const_fn_unstable(feature1,
142
157
feature2)]` attribute can be used to allow some unstable features in the body of a stable (or
143
158
indirectly stable) `const fn`.
144
159
145
160
You also need to take care to uphold the `const fn` invariant that calling it at runtime and
146
-
compile-time needs to behave the same (see also [this blog post][blog]). This means that you
161
+
compile-time needs to behave the same (see also [this blog post][blog]).
162
+
This means that you
147
163
may not create a `const fn` that e.g. transmutes a memory address to an integer,
148
164
because the addresses of things are nondeterministic and often unknown at
149
165
compile-time.
@@ -159,7 +175,8 @@ Any crate that uses the `stable` or `unstable` attributes must include the
159
175
## deprecated
160
176
161
177
Deprecations in the standard library are nearly identical to deprecations in
162
-
user code. When `#[deprecated]` is used on an item, it must also have a `stable`
178
+
user code.
179
+
When `#[deprecated]` is used on an item, it must also have a `stable`
163
180
or `unstable `attribute.
164
181
165
182
`deprecated` has the following form:
@@ -172,28 +189,35 @@ or `unstable `attribute.
172
189
)]
173
190
```
174
191
175
-
The `suggestion` field is optional. If given, it should be a string that can be
176
-
used as a machine-applicable suggestion to correct the warning. This is
192
+
The `suggestion` field is optional.
193
+
If given, it should be a string that can be
194
+
used as a machine-applicable suggestion to correct the warning.
195
+
This is
177
196
typically used when the identifier is renamed, but no other significant changes
178
-
are necessary. When the `suggestion` field is used, you need to have
197
+
are necessary.
198
+
When the `suggestion` field is used, you need to have
179
199
`#![feature(deprecated_suggestion)]` at the crate root.
180
200
181
201
Another difference from user code is that the `since` field is actually checked
182
-
against the current version of `rustc`. If `since` is in a future version, then
202
+
against the current version of `rustc`.
203
+
If `since` is in a future version, then
183
204
the `deprecated_in_future` lint is triggered which is default `allow`, but most
184
205
of the standard library raises it to a warning with
185
206
`#![warn(deprecated_in_future)]`.
186
207
187
208
## unstable_feature_bound
188
-
The `#[unstable_feature_bound(foo)]` attribute can be used together with `#[unstable]` attribute to mark an `impl` of stable type and stable trait as unstable. In std/core, an item annotated with `#[unstable_feature_bound(foo)]` can only be used by another item that is also annotated with `#[unstable_feature_bound(foo)]`. Outside of std/core, using an item with `#[unstable_feature_bound(foo)]` requires the feature to be enabled with `#![feature(foo)]` attribute on the crate.
209
+
The `#[unstable_feature_bound(foo)]` attribute can be used together with `#[unstable]` attribute to mark an `impl` of stable type and stable trait as unstable.
210
+
In std/core, an item annotated with `#[unstable_feature_bound(foo)]` can only be used by another item that is also annotated with `#[unstable_feature_bound(foo)]`.
211
+
Outside of std/core, using an item with `#[unstable_feature_bound(foo)]` requires the feature to be enabled with `#![feature(foo)]` attribute on the crate.
189
212
190
213
Currently, the items that can be annotated with `#[unstable_feature_bound]` are:
191
214
-`impl`
192
215
- free function
193
216
- trait
194
217
195
218
## renamed and removed features
196
-
Unstable features can get renamed and removed. If you rename a feature, you can add `old_name = "old_name"` to the `#[unstable]` attribute.
219
+
Unstable features can get renamed and removed.
220
+
If you rename a feature, you can add `old_name = "old_name"` to the `#[unstable]` attribute.
197
221
If you remove a feature, the `#!unstable_removed(feature = "foo", reason = "brief description", link = "link", since = "1.90.0")`
198
222
attribute should be used to produce a good error message for users of the removed feature.
0 commit comments