Skip to content

Commit d2648cc

Browse files
committed
manual: further attribute clarifications
- Sort attributes lexicographically - Use new attribute syntax consistently - Fix wording describing new attribute syntax - Expand section on `repr`
1 parent a86d6b4 commit d2648cc

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

src/doc/rust.md

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ and may optionally begin with any number of `attributes` that apply to the conta
610610
Attributes on the anonymous crate module define important metadata that influences
611611
the behavior of the compiler.
612612

613-
~~~~
613+
~~~~ {.rust}
614614
// Crate ID
615615
#![crate_id = "projx#2.5"]
616616
@@ -1697,7 +1697,7 @@ as any of:
16971697

16981698
Attributes with a bang ("!") after the hash ("#") apply to the item that the
16991699
attribute is declared within. Attributes that do not have a bang after the
1700-
hash by a semi-colon apply to the next item.
1700+
hash apply to the item that follows the attribute.
17011701

17021702
An example of attributes:
17031703

@@ -1729,53 +1729,54 @@ pub type int8_t = i8;
17291729
17301730
### Crate-only attributes
17311731

1732+
- `crate_id` - specify the this crate's crate ID.
17321733
- `crate_type` - see [linkage](#linkage).
17331734
- `feature` - see [compiler features](#compiler-features).
1735+
- `no_main` - disable emitting the `main` symbol. Useful when some other
1736+
object being linked to defines `main`.
17341737
- `no_start` - disable linking to the `native` crate, which specifies the
17351738
"start" language item.
1736-
- `no_main` - disable emitting the `main` symbol. Useful when some
1737-
other object being linked to defines `main`.
17381739
- `no_std` - disable linking to the `std` crate.
1739-
- `crate_id` - specify the this crate's crate ID.
17401740

17411741
### Module-only attributes
17421742

1743-
- `path` - specifies the file to load the module from. `#[path="foo.rs"] mod
1744-
bar;` is equivalent to `mod bar { /* contents of foo.rs */ }`
17451743
- `macro_escape` - macros defined in this module will be visible in the
17461744
module's parent, after this module has been included.
17471745
- `no_implicit_prelude` - disable injecting `use std::prelude::*` in this
17481746
module.
1747+
- `path` - specifies the file to load the module from. `#[path="foo.rs"] mod
1748+
bar;` is equivalent to `mod bar { /* contents of foo.rs */ }`. The path is
1749+
taken relative to the directory that the current module is in.
17491750

17501751
### Function-only attributes
17511752

1752-
- `start` - indicates that this function should be used as the entry point,
1753-
overriding the "start" language item. See the "start" [language
1754-
item](#language-items) for more details.
1755-
- `main` - indicates that this function should be passed to the entry point,
1756-
rather than the function in the crate root named `main`.
17571753
- `macro_registrar` - when using loadable syntax extensions, mark this
17581754
function as the registration point for the current crate's syntax
17591755
extensions.
1756+
- `main` - indicates that this function should be passed to the entry point,
1757+
rather than the function in the crate root named `main`.
1758+
- `start` - indicates that this function should be used as the entry point,
1759+
overriding the "start" language item. See the "start" [language
1760+
item](#language-items) for more details.
17601761

17611762
### Static-only attributes
17621763

1764+
- `address_insignificant` - references to this static may alias with
1765+
references to other statics, potentially of unrelated type.
17631766
- `thread_local` - on a `static mut`, this signals that the value of this
17641767
static may change depending on the current thread. The exact consequences of
17651768
this are implementation-defined.
1766-
- `address_insignificant` - references to this static may alias with
1767-
references to other statics, potentially of unrelated type.
17681769

17691770
### FFI attributes
17701771

17711772
On an `extern` block, the following attributes are interpreted:
17721773

1773-
- `link` - indicate that a native library should be linked to for the
1774-
declarations in this block to be linked correctly. See [external
1775-
blocks](#external-blocks)
17761774
- `link_args` - specify arguments to the linker, rather than just the library
17771775
name and type. This is feature gated and the exact behavior is
17781776
implementation-defined (due to variety of linker invocation syntax).
1777+
- `link` - indicate that a native library should be linked to for the
1778+
declarations in this block to be linked correctly. See [external
1779+
blocks](#external-blocks)
17791780

17801781
On declarations inside an `extern` block, the following attributes are
17811782
interpreted:
@@ -1787,25 +1788,29 @@ interpreted:
17871788

17881789
### Miscellaneous attributes
17891790

1790-
- `simd` - on certain tuple structs, derive the arithmetic operators, which
1791-
lower to the target's SIMD instructions, if any.
17921791
- `link_section` - on statics and functions, this specifies the section of the
17931792
object file that this item's contents will be placed into.
1794-
- `static_assert` - on statics whose type is `bool`, terminates compilation
1795-
with an error if it is not initialized to `true`.
1796-
- `repr` - on C-like enums, this sets the underlying type used for
1797-
representation. Useful for FFI.
1793+
- `macro_export` - export a macro for cross-crate usage.
17981794
- `no_mangle` - on any item, do not apply the standard name mangling. Set the
17991795
symbol for this item to its identifier.
18001796
- `packed` - on structs or enums, eliminate any padding that would be used to
18011797
align fields.
1798+
- `repr` - on C-like enums, this sets the underlying type used for
1799+
representation. Useful for FFI. Takes one argument, which is the primitive
1800+
type this enum should be represented for, or `C`, which specifies that it
1801+
should be the default `enum` size of the C ABI for that platform. Note that
1802+
enum representation in C is undefined, and this may be incorrect when the C
1803+
code is compiled with certain flags.
1804+
- `simd` - on certain tuple structs, derive the arithmetic operators, which
1805+
lower to the target's SIMD instructions, if any.
1806+
- `static_assert` - on statics whose type is `bool`, terminates compilation
1807+
with an error if it is not initialized to `true`.
18021808
- `unsafe_destructor` - allow implementations of the "drop" language item
18031809
where the type it is implemented for does not implement the "send" language
18041810
item.
18051811
- `unsafe_no_drop_flag` - on structs, remove the flag that prevents
18061812
destructors from being run twice. Destructors might be run multiple times on
18071813
the same object with this attribute.
1808-
- `macro_export` - export a macro for cross-crate usage.
18091814

18101815
### Conditional compilation
18111816

0 commit comments

Comments
 (0)