@@ -59,28 +59,17 @@ mod bar {
59
59
type int8_t = i8 ;
60
60
```
61
61
62
- > ** Note:** At some point in the future, the compiler will distinguish between
63
- > language-reserved and user-available attributes. Until then, there is
64
- > effectively no difference between an attribute handled by a loadable syntax
65
- > extension and the compiler.
66
-
67
62
## Crate-only attributes
68
63
69
64
- ` crate_name ` - specify the crate's crate name.
70
65
- ` crate_type ` - see [ linkage] ( linkage.html ) .
71
- - ` feature ` - see [ compiler features] ( #compiler-features ) .
72
66
- ` no_builtins ` - disable optimizing certain code patterns to invocations of
73
67
library functions that are assumed to exist
74
68
- ` no_main ` - disable emitting the ` main ` symbol. Useful when some other
75
69
object being linked to defines ` main ` .
76
70
- ` no_start ` - disable linking to the ` native ` crate, which specifies the
77
71
"start" language item.
78
72
- ` no_std ` - disable linking to the ` std ` crate.
79
- - ` plugin ` - load a list of named crates as compiler plugins, e.g.
80
- ` #![plugin(foo, bar)] ` . Optional arguments for each plugin,
81
- i.e. ` #![plugin(foo(... args ...))] ` , are provided to the plugin's
82
- registrar function. The ` plugin ` feature gate is required to use
83
- this attribute.
84
73
- ` recursion_limit ` - Sets the maximum depth for potentially
85
74
infinitely-recursive compile-time operations like
86
75
auto-dereference or macro expansion. The default is
@@ -107,25 +96,12 @@ type int8_t = i8;
107
96
108
97
- ` main ` - indicates that this function should be passed to the entry point,
109
98
rather than the function in the crate root named ` main ` .
110
- - ` plugin_registrar ` - mark this function as the registration point for
111
- [ compiler plugins] [ plugin ] , such as loadable syntax extensions.
112
- - ` start ` - indicates that this function should be used as the entry point,
113
- overriding the "start" language item. See the "start" [ language
114
- item] ( #language-items ) for more details.
115
99
- ` test ` - indicates that this function is a test function, to only be compiled
116
100
in case of ` --test ` .
117
101
- ` ignore ` - indicates that this test function is disabled.
118
102
- ` should_panic ` - indicates that this test function should panic, inverting the success condition.
119
103
- ` cold ` - The function is unlikely to be executed, so optimize it (and calls
120
104
to it) differently.
121
- - ` naked ` - The function utilizes a custom ABI or custom inline ASM that requires
122
- epilogue and prologue to be skipped.
123
-
124
- ## Static-only attributes
125
-
126
- - ` thread_local ` - on a ` static mut ` , this signals that the value of this
127
- static may change depending on the current thread. The exact consequences of
128
- this are implementation-defined.
129
105
130
106
## FFI attributes
131
107
@@ -171,6 +147,10 @@ On `struct`s:
171
147
remove any padding between fields (note that this is very fragile and may
172
148
break platforms which require aligned access).
173
149
150
+ On ` union ` s:
151
+
152
+ - ` repr ` - Same as per ` struct ` .
153
+
174
154
## Macro-related attributes
175
155
176
156
- ` macro_use ` on a ` mod ` — macros defined in this module will be visible in the
@@ -204,33 +184,7 @@ macro scope.
204
184
object file that this item's contents will be placed into.
205
185
- ` no_mangle ` - on any item, do not apply the standard name mangling. Set the
206
186
symbol for this item to its identifier.
207
- - ` simd ` - on certain tuple structs, derive the arithmetic operators, which
208
- lower to the target's SIMD instructions, if any; the ` simd ` feature gate
209
- is necessary to use this attribute.
210
- - ` unsafe_destructor_blind_to_params ` - on ` Drop::drop ` method, asserts that the
211
- destructor code (and all potential specializations of that code) will
212
- never attempt to read from nor write to any references with lifetimes
213
- that come in via generic parameters. This is a constraint we cannot
214
- currently express via the type system, and therefore we rely on the
215
- programmer to assert that it holds. Adding this to a Drop impl causes
216
- the associated destructor to be considered "uninteresting" by the
217
- Drop-Check rule, and thus it can help sidestep data ordering
218
- constraints that would otherwise be introduced by the Drop-Check
219
- rule. Such sidestepping of the constraints, if done incorrectly, can
220
- lead to undefined behavior (in the form of reading or writing to data
221
- outside of its dynamic extent), and thus this attribute has the word
222
- "unsafe" in its name. To use this, the
223
- ` unsafe_destructor_blind_to_params ` feature gate must be enabled.
224
187
- ` doc ` - Doc comments such as ` /// foo ` are equivalent to ` #[doc = "foo"] ` .
225
- - ` rustc_on_unimplemented ` - Write a custom note to be shown along with the error
226
- when the trait is found to be unimplemented on a type.
227
- You may use format arguments like ` {T} ` , ` {A} ` to correspond to the
228
- types at the point of use corresponding to the type parameters of the
229
- trait of the same name. ` {Self} ` will be replaced with the type that is supposed
230
- to implement the trait but doesn't. You can also use the trait's name which will
231
- be replaced with the full path for the trait, for example for the trait ` Foo ` in
232
- module ` Bar ` , ` {Foo} ` can be used and will show up as ` Bar::Foo ` .
233
- To use this, the ` on_unimplemented ` feature gate must be enabled.
234
188
- ` must_use ` - on structs and enums, will warn if a value of this type isn't used or
235
189
assigned to a variable. You may also include an optional message by using
236
190
` #[must_use = "message"] ` which will be given alongside the warning.
@@ -403,15 +357,6 @@ pub mod m3 {
403
357
}
404
358
```
405
359
406
- ### Language items
407
-
408
- Some primitive Rust operations are defined in Rust code, rather than being
409
- implemented directly in C or assembly language. The definitions of these
410
- operations have to be easy for the compiler to find. The ` lang ` attribute
411
- makes it possible to declare these operations.
412
- The set of language items is currently considered unstable. A complete
413
- list of the built-in language items will be added in the future.
414
-
415
360
### Inline attributes
416
361
417
362
The inline attribute suggests that the compiler should place a copy of
@@ -461,40 +406,6 @@ impl<T: PartialEq> PartialEq for Foo<T> {
461
406
}
462
407
```
463
408
464
- You can implement ` derive ` for your own type through [ procedural
465
- macros] ( procedural-macros.html ) .
466
-
467
- ### Compiler Features
468
-
469
- Certain aspects of Rust may be implemented in the compiler, but they're not
470
- necessarily ready for every-day use. These features are often of "prototype
471
- quality" or "almost production ready", but may not be stable enough to be
472
- considered a full-fledged language feature.
473
-
474
- For this reason, Rust recognizes a special crate-level attribute of the form:
475
-
476
- ``` rust,ignore
477
- #![feature(feature1, feature2, feature3)]
478
- ```
479
-
480
- This directive informs the compiler that the feature list: ` feature1 ` ,
481
- ` feature2 ` , and ` feature3 ` should all be enabled. This is only recognized at a
482
- crate-level, not at a module-level. Without this directive, all features are
483
- considered off, and using the features will result in a compiler error.
484
-
485
- The currently implemented features of the reference compiler are documented in
486
- [ The Unstable Book] .
487
-
488
- If a feature is promoted to a language feature, then all existing programs will
489
- start to receive compilation warnings about ` #![feature] ` directives which enabled
490
- the new feature (because the directive is no longer necessary). However, if a
491
- feature is decided to be removed from the language, errors will be issued (if
492
- there isn't a parser error first). The directive in this case is no longer
493
- necessary, and it's likely that existing code will break if the feature isn't
494
- removed.
495
-
496
- If an unknown feature is found in a directive, it results in a compiler error.
497
- An unknown feature is one which has never been recognized by the compiler.
409
+ You can implement ` derive ` for your own type through [ procedural macros] .
498
410
499
- [ The Unstable Book ] : https://doc.rust-lang.org/nightly/unstable-book/
500
- [ unstable book plugin ] : ../unstable-book/language-features/plugin.html#lint-plugins
411
+ [ procedural macros ] : procedural-macros.html
0 commit comments