@@ -611,7 +611,7 @@ Attributes on the anonymous crate module define important metadata that influenc
611
611
the behavior of the compiler.
612
612
613
613
~~~~
614
- // Package ID
614
+ // Crate ID
615
615
#[ crate_id = "projx#2.5" ];
616
616
617
617
// Additional metadata attributes
@@ -792,7 +792,7 @@ extern crate std; // equivalent to: extern crate std = "std";
792
792
793
793
extern crate ruststd = "std"; // linking to 'std' under another name
794
794
795
- extern crate foo = "some/where/rust-foo#foo:1.0"; // a full package ID for external tools
795
+ extern crate foo = "some/where/rust-foo#foo:1.0"; // a full crate ID for external tools
796
796
~~~~
797
797
798
798
##### Use declarations
@@ -1505,11 +1505,9 @@ specified name.
1505
1505
extern { }
1506
1506
~~~~
1507
1507
1508
- The type of a function
1509
- declared in an extern block
1510
- is ` extern "abi" fn(A1, ..., An) -> R ` ,
1511
- where ` A1...An ` are the declared types of its arguments
1512
- and ` R ` is the decalred return type.
1508
+ The type of a function declared in an extern block is `extern "abi" fn(A1,
1509
+ ..., An) -> R` , where ` A1...An` are the declared types of its arguments and
1510
+ ` R ` is the declared return type.
1513
1511
1514
1512
## Visibility and Privacy
1515
1513
@@ -1680,41 +1678,43 @@ import public items from their destination, not private items.
1680
1678
## Attributes
1681
1679
1682
1680
~~~~ {.notrust .ebnf .gram}
1683
- attribute : '#' '[' attr_list ']' ;
1684
- attr_list : attr [ ',' attr_list ]* ;
1681
+ attribute : '#' '!' ? ' [' attr_list ']'
1682
+ attr_list : attr [ ',' attr_list ]*
1685
1683
attr : ident [ '=' literal
1686
- | '(' attr_list ')' ] ? ;
1684
+ | '(' attr_list ')' ] ?
1687
1685
~~~~
1688
1686
1689
1687
Static entities in Rust -- crates, modules and items -- may have _ attributes_
1690
- applied to them. ^ [ Attributes in Rust are modeled on Attributes in ECMA-335,
1691
- C# ]
1692
- An attribute is a general, free-form metadatum that is interpreted according to name, convention, and language and compiler version.
1693
- Attributes may appear as any of
1688
+ applied to them. Attributes in Rust are modeled on Attributes in ECMA-335, C#.
1689
+ An attribute is a general, free-form metadatum that is interpreted according
1690
+ to name, convention, and language and compiler version. Attributes may appear
1691
+ as any of:
1694
1692
1695
1693
* A single identifier, the attribute name
1696
- * An identifier followed by the equals sign '=' and a literal, providing a key/value pair
1694
+ * An identifier followed by the equals sign '=' and a literal, providing a
1695
+ key/value pair
1697
1696
* An identifier followed by a parenthesized list of sub-attribute arguments
1698
1697
1699
- Attributes terminated by a semi-colon apply to the entity that the attribute is declared
1700
- within. Attributes that are not terminated by a semi-colon apply to the next entity.
1698
+ Attributes with a bang ("!") after the hash ("#") apply to the item that the
1699
+ attribute is declared within. Attributes that do not have a bang after the
1700
+ hash by a semi-colon apply to the next item.
1701
1701
1702
1702
An example of attributes:
1703
1703
1704
- ~~~~ {.ignore}
1704
+ ~~~~
1705
1705
// General metadata applied to the enclosing module or crate.
1706
- #[license = "BSD"];
1706
+ #! [license = "BSD"]
1707
1707
1708
1708
// A function marked as a unit test
1709
1709
#[test]
1710
1710
fn test_foo() {
1711
- ...
1711
+ /* ... */
1712
1712
}
1713
1713
1714
1714
// A conditionally-compiled module
1715
1715
#[cfg(target_os="linux")]
1716
1716
mod bar {
1717
- ...
1717
+ /* ... */
1718
1718
}
1719
1719
1720
1720
// A lint attribute used to suppress a warning/error
@@ -1727,29 +1727,85 @@ pub type int8_t = i8;
1727
1727
> effectively no difference between an attribute handled by a loadable syntax
1728
1728
> extension and the compiler.
1729
1729
1730
- Some significant attributes include:
1731
-
1732
- * The ` doc ` attribute, for documenting code in-place.
1733
- * The ` cfg ` attribute, for conditional-compilation by build-configuration (see
1734
- [ Conditional compilation] ( #conditional-compilation ) ).
1735
- * The ` crate_id ` attribute, for describing the package ID of a crate.
1736
- * The ` lang ` attribute, for custom definitions of traits and functions that are
1737
- known to the Rust compiler (see [ Language items] ( #language-items ) ).
1738
- * The ` link ` attribute, for describing linkage metadata for a extern blocks.
1739
- * The ` test ` attribute, for marking functions as unit tests.
1740
- * The ` allow ` , ` warn ` , ` forbid ` , and ` deny ` attributes, for
1741
- controlling lint checks (see [ Lint check attributes] ( #lint-check-attributes ) ).
1742
- * The ` deriving ` attribute, for automatically generating implementations of
1743
- certain traits.
1744
- * The ` inline ` attribute, for expanding functions at caller location (see
1745
- [ Inline attributes] ( #inline-attributes ) ).
1746
- * The ` static_assert ` attribute, for asserting that a static bool is true at
1747
- compiletime.
1748
- * The ` thread_local ` attribute, for defining a ` static mut ` as a thread-local.
1749
- Note that this is only a low-level building block, and is not local to a
1750
- * task* , nor does it provide safety.
1751
-
1752
- Other attributes may be added or removed during development of the language.
1730
+ ### Crate-only attributes
1731
+
1732
+ - ` crate_type ` - see [ linkage] ( #linkage ) .
1733
+ - ` feature ` - see [ compiler features] ( #compiler-features ) .
1734
+ - ` no_start ` - disable linking to the ` native ` crate, which specifies the
1735
+ "start" language item.
1736
+ - ` no_main ` - disable emitting the ` main ` symbol. Useful when some
1737
+ other object being linked to defines ` main ` .
1738
+ - ` no_std ` - disable linking to the ` std ` crate.
1739
+ - ` crate_id ` - specify the this crate's crate ID.
1740
+
1741
+ ### Module-only attributes
1742
+
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 * / }`
1745
+ - ` macro_escape ` - macros defined in this module will be visible in the
1746
+ module's parent, after this module has been included.
1747
+ - ` no_implicit_prelude ` - disable injecting ` use std::prelude::* ` in this
1748
+ module.
1749
+
1750
+ ### Function-only attributes
1751
+
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 ` .
1757
+ - ` macro_registrar ` - when using loadable syntax extensions, mark this
1758
+ function as the registration point for the current crate's syntax
1759
+ extensions.
1760
+
1761
+ ### Static-only attributes
1762
+
1763
+ - ` thread_local ` - on a ` static mut ` , this signals that the value of this
1764
+ static may change depending on the current thread. The exact consequences of
1765
+ this are implementation-defined.
1766
+ - ` address_insignificant ` - references to this static may alias with
1767
+ references to other statics, potentially of unrelated type.
1768
+
1769
+ ### FFI attributes
1770
+
1771
+ On an ` extern ` block, the following attributes are interpreted:
1772
+
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 )
1776
+ - ` link_args ` - specify arguments to the linker, rather than just the library
1777
+ name and type. This is feature gated and the exact behavior is
1778
+ implementation-defined (due to variety of linker invocation syntax).
1779
+
1780
+ On declarations inside an ` extern ` block, the following attributes are
1781
+ interpreted:
1782
+
1783
+ - ` link_name ` - the name of the symbol that this function or static should be
1784
+ imported as.
1785
+ - ` linkage ` - on a static, this specifies the [ linkage
1786
+ type] ( http://llvm.org/docs/LangRef.html#linkage-types ) .
1787
+
1788
+ ### Miscellaneous attributes
1789
+
1790
+ - ` simd ` - on certain tuple structs, derive the arithmetic operators, which
1791
+ lower to the target's SIMD instructions, if any.
1792
+ - ` link_section ` - on statics and functions, this specifies the section of the
1793
+ 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.
1798
+ - ` no_mangle ` - on any item, do not apply the standard name mangling. Set the
1799
+ symbol for this item to its identifier.
1800
+ - ` packed ` - on structs or enums, eliminate any padding that would be used to
1801
+ align fields.
1802
+ - ` unsafe_destructor ` - allow implementations of the "drop" language item
1803
+ where the type it is implemented for does not implement the "send" language
1804
+ item.
1805
+ - ` unsafe_no_drop_flag ` - on structs, remove the flag that prevents
1806
+ destructors from being run twice. Destructors might be run multiple times on
1807
+ the same object with this attribute.
1808
+ - ` macro_export ` - export a macro for cross-crate usage.
1753
1809
1754
1810
### Conditional compilation
1755
1811
@@ -1791,9 +1847,7 @@ one of `foo` and `bar` to be defined (this resembles in the disjunctive normal
1791
1847
form). Additionally, one can reverse a condition by enclosing it in a
1792
1848
` not(...) ` , like e. g. ` #[cfg(not(target_os = "win32"))] ` .
1793
1849
1794
- To pass a configuration option which triggers a ` #[cfg(identifier)] ` one can use
1795
- ` rustc --cfg identifier ` . In addition to that, the following configurations are
1796
- pre-defined by the compiler:
1850
+ The following configurations must be defined by the implementation:
1797
1851
1798
1852
* ` target_arch = "..." ` . Target CPU architecture, such as ` "x86" ` , ` "x86_64" `
1799
1853
` "mips" ` , or ` "arm" ` .
@@ -1805,8 +1859,8 @@ pre-defined by the compiler:
1805
1859
* ` target_os = "..." ` . Operating system of the target, examples include
1806
1860
` "win32" ` , ` "macos" ` , ` "linux" ` , ` "android" ` or ` "freebsd" ` .
1807
1861
* ` target_word_size = "..." ` . Target word size in bits. This is set to ` "32" `
1808
- for 32-bit CPU targets , and likewise set to ` "64" ` for 64-bit CPU targets.
1809
- * ` test ` . Only set in test builds ( ` rustc --test ` ) .
1862
+ for targets with 32-bit pointers , and likewise set to ` "64" ` for 64-bit
1863
+ pointers .
1810
1864
* ` unix ` . See ` target_family ` .
1811
1865
* ` windows ` . See ` target_family ` .
1812
1866
@@ -1823,7 +1877,7 @@ For any lint check `C`:
1823
1877
* ` allow(C) ` overrides the check for ` C ` so that violations will go
1824
1878
unreported,
1825
1879
* ` forbid(C) ` is the same as ` deny(C) ` , but also forbids uses of
1826
- ` allow(C) ` within the entity .
1880
+ ` allow(C) ` within the attribute .
1827
1881
1828
1882
The lint checks supported by the compiler can be found via ` rustc -W help ` ,
1829
1883
along with their default settings.
@@ -1881,11 +1935,11 @@ mod m3 {
1881
1935
1882
1936
### Language items
1883
1937
1884
- Some primitive Rust operations are defined in Rust code,
1885
- rather than being implemented directly in C or assembly language.
1886
- The definitions of these operations have to be easy for the compiler to find.
1887
- The ` lang ` attribute makes it possible to declare these operations.
1888
- For example, the ` str ` module in the Rust standard library defines the string equality function:
1938
+ Some primitive Rust operations are defined in Rust code, rather than being
1939
+ implemented directly in C or assembly language. The definitions of these
1940
+ operations have to be easy for the compiler to find. The ` lang ` attribute
1941
+ makes it possible to declare these operations. For example, the ` str ` module
1942
+ in the Rust standard library defines the string equality function:
1889
1943
1890
1944
~~~~ {.ignore}
1891
1945
#[lang="str_eq"]
@@ -1900,16 +1954,23 @@ when generating calls to the string equality function.
1900
1954
1901
1955
A complete list of the built-in language items follows:
1902
1956
1903
- #### Traits
1957
+ #### Built-in Traits
1904
1958
1905
- ` const `
1906
- : Cannot be mutated.
1907
- ` owned `
1908
- : Are uniquely owned.
1909
- ` durable `
1910
- : Contain references.
1959
+ ` send `
1960
+ : Able to be sent across task boundaries.
1961
+ ` sized `
1962
+ : Has a size known at compile time.
1963
+ ` copy `
1964
+ : Types that do not move ownership when used by-value.
1965
+ ` share `
1966
+ : Able to be safely shared between tasks when aliased.
1911
1967
` drop `
1912
- : Have finalizers.
1968
+ : Have destructors.
1969
+
1970
+ #### Operators
1971
+
1972
+ These language items are traits:
1973
+
1913
1974
` add `
1914
1975
: Elements can be added (for example, integers and floats).
1915
1976
` sub `
@@ -1940,17 +2001,54 @@ A complete list of the built-in language items follows:
1940
2001
: Elements can be compared for equality.
1941
2002
` ord `
1942
2003
: Elements have a partial ordering.
2004
+ ` deref `
2005
+ : ` * ` can be applied, yielding a reference to another type
2006
+ ` deref_mut `
2007
+ : ` * ` can be applied, yielding a mutable reference to another type
1943
2008
1944
- #### Operations
2009
+
2010
+ These are functions:
1945
2011
1946
2012
` str_eq `
1947
- : Compare two strings for equality.
2013
+ : Compare two strings ( ` &str ` ) for equality.
1948
2014
` uniq_str_eq `
1949
- : Compare two owned strings for equality.
1950
- ` annihilate `
1951
- : Destroy a box before freeing it.
1952
- ` log_type `
1953
- : Generically print a string representation of any type.
2015
+ : Compare two owned strings (` ~str ` ) for equality.
2016
+ ` strdup_uniq `
2017
+ : Return a new unique string
2018
+ containing a copy of the contents of a unique string.
2019
+
2020
+ #### Types
2021
+
2022
+ ` unsafe `
2023
+ : A type whose contents can be mutated through an immutable reference
2024
+ ` type_id `
2025
+ : The type returned by the ` type_id ` intrinsic.
2026
+
2027
+ #### Marker types
2028
+
2029
+ These types help drive the compiler's analysis
2030
+
2031
+ ` covariant_type `
2032
+ : The type parameter should be considered covariant
2033
+ ` contravariant_type `
2034
+ : The type parameter should be considered contravariant
2035
+ ` invariant_type `
2036
+ : The type parameter should be considered invariant
2037
+ ` covariant_lifetime `
2038
+ : The lifetime parameter should be considered covariant
2039
+ ` contravariant_lifetime `
2040
+ : The lifetime parameter should be considered contravariant
2041
+ ` invariant_lifetime `
2042
+ : The lifetime parameter should be considered invariant
2043
+ ` no_send_bound `
2044
+ : This type does not implement "send", even if eligible
2045
+ ` no_copy_bound `
2046
+ : This type does not implement "copy", even if eligible
2047
+ ` no_share_bound `
2048
+ : This type does not implement "share", even if eligible
2049
+ ` managed_bound `
2050
+ : This type implements "managed"
2051
+
1954
2052
` fail_ `
1955
2053
: Abort the program with an error.
1956
2054
` fail_bounds_check `
@@ -1963,15 +2061,6 @@ A complete list of the built-in language items follows:
1963
2061
: Allocate memory on the managed heap.
1964
2062
` free `
1965
2063
: Free memory that was allocated on the managed heap.
1966
- ` borrow_as_imm `
1967
- : Create an immutable reference to a mutable value.
1968
- ` return_to_mut `
1969
- : Release a reference created with ` return_to_mut `
1970
- ` check_not_borrowed `
1971
- : Fail if a value has existing references to it.
1972
- ` strdup_uniq `
1973
- : Return a new unique string
1974
- containing a copy of the contents of a unique string.
1975
2064
1976
2065
> ** Note:** This list is likely to become out of date. We should auto-generate it
1977
2066
> from ` librustc/middle/lang_items.rs ` .
@@ -2039,6 +2128,7 @@ Supported traits for `deriving` are:
2039
2128
* ` Show ` , to format a value using the ` {} ` formatter.
2040
2129
2041
2130
### Stability
2131
+
2042
2132
One can indicate the stability of an API using the following attributes:
2043
2133
2044
2134
* ` deprecated ` : This item should no longer be used, e.g. it has been
@@ -2101,18 +2191,18 @@ necessarily ready for every-day use. These features are often of "prototype
2101
2191
quality" or "almost production ready", but may not be stable enough to be
2102
2192
considered a full-fleged language feature.
2103
2193
2104
- For this reason, rust recognizes a special crate-level attribute of the form:
2194
+ For this reason, Rust recognizes a special crate-level attribute of the form:
2105
2195
2106
2196
~~~~ {.ignore}
2107
- #[feature(feature1, feature2, feature3)]
2197
+ #! [feature(feature1, feature2, feature3)]
2108
2198
~~~~
2109
2199
2110
2200
This directive informs the compiler that the feature list: ` feature1 ` ,
2111
2201
` feature2 ` , and ` feature3 ` should all be enabled. This is only recognized at a
2112
2202
crate-level, not at a module-level. Without this directive, all features are
2113
2203
considered off, and using the features will result in a compiler error.
2114
2204
2115
- The currently implemented features of the compiler are:
2205
+ The currently implemented features of the reference compiler are:
2116
2206
2117
2207
* ` macro_rules ` - The definition of new macros. This does not encompass
2118
2208
macro-invocation, that is always enabled by default, this only
0 commit comments