@@ -1271,15 +1271,16 @@ guaranteed to refer to the same memory address.
1271
1271
1272
1272
Constant values must not have destructors, and otherwise permit most forms of
1273
1273
data. Constants may refer to the address of other constants, in which case the
1274
- address will have the ` static ` lifetime. The compiler is, however, still at
1274
+ address will have the ` static ` lifetime. (See below on [ static lifetime
1275
+ elision] ( #static-lifetime-elision ) .) The compiler is, however, still at
1275
1276
liberty to translate the constant many times, so the address referred to may not
1276
1277
be stable.
1277
1278
1278
1279
Constants must be explicitly typed. The type may be ` bool ` , ` char ` , a number, or
1279
1280
a type derived from those primitive types. The derived types are references with
1280
1281
the ` static ` lifetime, fixed-size arrays, tuples, enum variants, and structs.
1281
1282
1282
- ```
1283
+ ``` rust
1283
1284
const BIT1 : u32 = 1 << 0 ;
1284
1285
const BIT2 : u32 = 1 << 1 ;
1285
1286
@@ -1331,7 +1332,7 @@ running in the same process.
1331
1332
Mutable statics are still very useful, however. They can be used with C
1332
1333
libraries and can also be bound from C libraries (in an ` extern ` block).
1333
1334
1334
- ```
1335
+ ``` rust
1335
1336
# fn atomic_add (_ : & mut u32 , _ : u32 ) -> u32 { 2 }
1336
1337
1337
1338
static mut LEVELS : u32 = 0 ;
@@ -1355,6 +1356,31 @@ unsafe fn bump_levels_unsafe2() -> u32 {
1355
1356
Mutable statics have the same restrictions as normal statics, except that the
1356
1357
type of the value is not required to ascribe to ` Sync ` .
1357
1358
1359
+ #### ` 'static ` lifetime elision
1360
+
1361
+ Both constant and static declarations of reference types have * implicit*
1362
+ ` 'static ` lifetimes unless an explicit lifetime is specified. As such, the
1363
+ constant declarations involving ` 'static ` above may be written without the
1364
+ lifetimes. Returning to our previous example:
1365
+
1366
+ ``` rust
1367
+ const BIT1 : u32 = 1 << 0 ;
1368
+ const BIT2 : u32 = 1 << 1 ;
1369
+
1370
+ const BITS : [u32 ; 2 ] = [BIT1 , BIT2 ];
1371
+ const STRING : & str = " bitstring" ;
1372
+
1373
+ struct BitsNStrings <'a > {
1374
+ mybits : [u32 ; 2 ],
1375
+ mystring : & 'a str ,
1376
+ }
1377
+
1378
+ const BITS_N_STRINGS : BitsNStrings = BitsNStrings {
1379
+ mybits : BITS ,
1380
+ mystring : STRING ,
1381
+ };
1382
+ ```
1383
+
1358
1384
### Traits
1359
1385
1360
1386
A _ trait_ describes an abstract interface that types can
@@ -2458,9 +2484,6 @@ The currently implemented features of the reference compiler are:
2458
2484
into a Rust program. This capability, especially the signature for the
2459
2485
annotated function, is subject to change.
2460
2486
2461
- * ` static_in_const ` - Enables lifetime elision with a ` 'static ` default for
2462
- ` const ` and ` static ` item declarations.
2463
-
2464
2487
* ` thread_local ` - The usage of the ` #[thread_local] ` attribute is experimental
2465
2488
and should be seen as unstable. This attribute is used to
2466
2489
declare a ` static ` as being unique per-thread leveraging
0 commit comments