Skip to content

Commit 85c978a

Browse files
committed
---
yaml --- r: 140782 b: refs/heads/try2 c: 84745b4 h: refs/heads/master v: v3
1 parent fe4d9c8 commit 85c978a

File tree

124 files changed

+1805
-1454
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+1805
-1454
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 3515b4996ae5c151459222601306d538eebdc3b3
8+
refs/heads/try2: 84745b483f322671f894b9e8d0a462c46275a9d3
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/doc/rust.md

Lines changed: 83 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ each of which may have some number of [attributes](#attributes) attached to it.
618618

619619
~~~~~~~~ {.ebnf .gram}
620620
item : mod_item | fn_item | type_item | struct_item | enum_item
621-
| static_item | trait_item | impl_item | foreign_mod_item ;
621+
| static_item | trait_item | impl_item | extern_block ;
622622
~~~~~~~~
623623

624624
An _item_ is a component of a crate; some module items can be defined in crate
@@ -752,10 +752,11 @@ link_attr : ident '=' literal ;
752752
~~~~~~~~
753753

754754
An _`extern mod` declaration_ specifies a dependency on an external crate.
755-
The external crate is then bound into the declaring scope as the `ident` provided in the `extern_mod_decl`.
755+
The external crate is then bound into the declaring scope
756+
as the `ident` provided in the `extern_mod_decl`.
756757

757-
The external crate is resolved to a specific `soname` at compile time, and a
758-
runtime linkage requirement to that `soname` is passed to the linker for
758+
The external crate is resolved to a specific `soname` at compile time,
759+
and a runtime linkage requirement to that `soname` is passed to the linker for
759760
loading at runtime. The `soname` is resolved at compile time by scanning the
760761
compiler's library path and matching the `link_attrs` provided in the
761762
`use_decl` against any `#link` attributes that were declared on the external
@@ -992,10 +993,10 @@ Thus the return type on `f` only needs to reflect the `if` branch of the conditi
992993
#### Extern functions
993994

994995
Extern functions are part of Rust's foreign function interface,
995-
providing the opposite functionality to [foreign modules](#foreign-modules).
996-
Whereas foreign modules allow Rust code to call foreign code,
997-
extern functions with bodies defined in Rust code _can be called by foreign code_.
998-
They are defined in the same way as any other Rust function,
996+
providing the opposite functionality to [external blocks](#external-blocks).
997+
Whereas external blocks allow Rust code to call foreign code,
998+
extern functions with bodies defined in Rust code _can be called by foreign
999+
code_. They are defined in the same way as any other Rust function,
9991000
except that they have the `extern` modifier.
10001001

10011002
~~~
@@ -1011,7 +1012,8 @@ let fptr: *u8 = new_vec;
10111012
~~~
10121013

10131014
The primary motivation for extern functions is
1014-
to create callbacks for foreign functions that expect to receive function pointers.
1015+
to create callbacks for foreign functions that expect to receive function
1016+
pointers.
10151017

10161018
### Type definitions
10171019

@@ -1308,64 +1310,61 @@ impl Seq<bool> for u32 {
13081310
}
13091311
~~~~
13101312

1311-
### Foreign modules
1313+
### External blocks
13121314

13131315
~~~ {.ebnf .gram}
1314-
foreign_mod_item : "extern mod" ident '{' foreign_mod '} ;
1315-
foreign_mod : [ foreign_fn ] * ;
1316+
extern_block_item : "extern" '{' extern_block '} ;
1317+
extern_block : [ foreign_fn ] * ;
13161318
~~~
13171319

1318-
Foreign modules form the basis for Rust's foreign function interface. A
1319-
foreign module describes functions in external, non-Rust
1320-
libraries.
1321-
Functions within foreign modules are declared in the same way as other Rust functions,
1322-
with the exception that they may not have a body and are instead terminated by a semicolon.
1320+
External blocks form the basis for Rust's foreign function interface.
1321+
Declarations in an external block describe symbols
1322+
in external, non-Rust libraries.
1323+
1324+
Functions within external blocks
1325+
are declared in the same way as other Rust functions,
1326+
with the exception that they may not have a body
1327+
and are instead terminated by a semicolon.
13231328

13241329
~~~
13251330
# use core::libc::{c_char, FILE};
13261331
# #[nolink]
13271332
1328-
extern mod c {
1333+
extern {
13291334
fn fopen(filename: *c_char, mode: *c_char) -> *FILE;
13301335
}
13311336
~~~
13321337

1333-
Functions within foreign modules may be called by Rust code, just like functions defined in Rust.
1334-
The Rust compiler automatically translates between the Rust ABI and the foreign ABI.
1335-
1336-
The name of the foreign module has special meaning to the Rust compiler in
1337-
that it will treat the module name as the name of a library to link to,
1338-
performing the linking as appropriate for the target platform. The name
1339-
given for the foreign module will be transformed in a platform-specific way
1340-
to determine the name of the library. For example, on Linux the name of the
1341-
foreign module is prefixed with 'lib' and suffixed with '.so', so the
1342-
foreign mod 'rustrt' would be linked to a library named 'librustrt.so'.
1338+
Functions within external blocks may be called by Rust code,
1339+
just like functions defined in Rust.
1340+
The Rust compiler automatically translates
1341+
between the Rust ABI and the foreign ABI.
13431342

1344-
A number of [attributes](#attributes) control the behavior of foreign
1345-
modules.
1343+
A number of [attributes](#attributes) control the behavior of external
1344+
blocks.
13461345

1347-
By default foreign modules assume that the library they are calling use the
1348-
standard C "cdecl" ABI. Other ABIs may be specified using the `abi`
1349-
attribute as in
1346+
By default external blocks assume
1347+
that the library they are calling uses the standard C "cdecl" ABI.
1348+
Other ABIs may be specified using the `abi` attribute as in
13501349

13511350
~~~{.xfail-test}
13521351
// Interface to the Windows API
13531352
#[abi = "stdcall"]
1354-
extern mod kernel32 { }
1353+
extern { }
13551354
~~~
13561355

1357-
The `link_name` attribute allows the default library naming behavior to
1358-
be overridden by explicitly specifying the name of the library.
1356+
The `link_name` attribute allows the name of the library to be specified.
13591357

13601358
~~~{.xfail-test}
13611359
#[link_name = "crypto"]
1362-
extern mod mycrypto { }
1360+
extern { }
13631361
~~~
13641362

1365-
The `nolink` attribute tells the Rust compiler not to do any linking for the foreign module.
1366-
This is particularly useful for creating foreign
1367-
modules for libc, which tends to not follow standard library naming
1368-
conventions and is linked to all Rust programs anyway.
1363+
The `nolink` attribute tells the Rust compiler
1364+
not to do any linking for the external block.
1365+
This is particularly useful for creating external blocks for libc,
1366+
which tends to not follow standard library naming conventions
1367+
and is linked to all Rust programs anyway.
13691368

13701369
## Attributes
13711370

@@ -1425,6 +1424,8 @@ names are effectively reserved. Some significant attributes include:
14251424
* The `test` attribute, for marking functions as unit tests.
14261425
* The `allow`, `warn`, `forbid`, and `deny` attributes, for controlling lint checks. Lint checks supported
14271426
by the compiler can be found via `rustc -W help`.
1427+
* The `deriving` attribute, for automatically generating
1428+
implementations of certain traits.
14281429

14291430
Other attributes may be added or removed during development of the language.
14301431

@@ -1526,6 +1527,47 @@ A complete list of the built-in language items follows:
15261527
> **Note:** This list is likely to become out of date. We should auto-generate it
15271528
> from `librustc/middle/lang_items.rs`.
15281529
1530+
### Deriving
1531+
1532+
The `deriving` attribute allows certain traits to be automatically
1533+
implemented for data structures. For example, the following will
1534+
create an `impl` for the `Eq` and `Clone` traits for `Foo`, the type
1535+
parameter `T` will be given the `Eq` or `Clone` constraints for the
1536+
appropriate `impl`:
1537+
1538+
~~~
1539+
#[deriving(Eq, Clone)]
1540+
struct Foo<T> {
1541+
a: int,
1542+
b: T
1543+
}
1544+
~~~
1545+
1546+
The generated `impl` for `Eq` is equivalent to
1547+
1548+
~~~
1549+
# struct Foo<T> { a: int, b: T }
1550+
impl<T: Eq> Eq for Foo<T> {
1551+
fn eq(&self, other: &Foo<T>) -> bool {
1552+
self.a == other.a && self.b == other.b
1553+
}
1554+
1555+
fn ne(&self, other: &Foo<T>) -> bool {
1556+
self.a != other.a || self.b != other.b
1557+
}
1558+
}
1559+
~~~
1560+
1561+
Supported traits for `deriving` are:
1562+
1563+
* Comparison traits: `Eq`, `TotalEq`, `Ord`, `TotalOrd`.
1564+
* Serialization: `Encodable`, `Decodable`. These require `std`.
1565+
* `Clone`, to perform deep copies.
1566+
* `IterBytes`, to iterate over the bytes in a data type.
1567+
* `Rand`, to create a random instance of a data type.
1568+
* `ToStr`, to convert to a string. For a type with this instance,
1569+
`obj.to_str()` has the same output as `fmt!("%?", obj)`.
1570+
15291571
# Statements and expressions
15301572

15311573
Rust is _primarily_ an expression language. This means that most forms of

branches/try2/doc/tutorial-ffi.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ convention to use:
237237
~~~~
238238
#[cfg(target_os = "win32")]
239239
#[abi = "stdcall"]
240-
extern mod kernel32 {
240+
#[link_name = "kernel32"]
241+
extern {
241242
fn SetEnvironmentVariableA(n: *u8, v: *u8) -> int;
242243
}
243244
~~~~

branches/try2/doc/tutorial.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,6 +2290,27 @@ let nonsense = mycircle.radius() * mycircle.area();
22902290

22912291
> ***Note:*** Trait inheritance does not actually work with objects yet
22922292
2293+
## Deriving implementations for traits
2294+
2295+
A small number of traits in `core` and `std` can have implementations
2296+
that can be automatically derived. These instances are specified by
2297+
placing the `deriving` attribute on a data type declaration. For
2298+
example, the following will mean that `Circle` has an implementation
2299+
for `Eq` and can be used with the equality operators, and that a value
2300+
of type `ABC` can be randomly generated and converted to a string:
2301+
2302+
~~~
2303+
#[deriving(Eq)]
2304+
struct Circle { radius: float }
2305+
2306+
#[deriving(Rand, ToStr)]
2307+
enum ABC { A, B, C }
2308+
~~~
2309+
2310+
The full list of derivable traits is `Eq`, `TotalEq`, `Ord`,
2311+
`TotalOrd`, `Encodable` `Decodable`, `Clone`, `IterBytes`, `Rand` and
2312+
`ToStr`.
2313+
22932314
# Modules and crates
22942315

22952316
The Rust namespace is arranged in a hierarchy of modules. Each source

branches/try2/mk/tools.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ $$(TLIB$(1)_T_$(4)_H_$(3))/$(CFG_LIBRUST_$(4)): \
111111
$$(TSREQ$(1)_T_$(4)_H_$(3)) \
112112
$$(TLIB$(1)_T_$(4)_H_$(3))/$(CFG_CORELIB_$(4)) \
113113
$$(TLIB$(1)_T_$(4)_H_$(3))/$(CFG_STDLIB_$(4)) \
114+
$$(TLIB$(1)_T_$(4)_H_$(3))/$(CFG_LIBRUSTPKG_$(4)) \
115+
$$(TLIB$(1)_T_$(4)_H_$(3))/$(CFG_LIBRUSTI_$(4)) \
116+
$$(TLIB$(1)_T_$(4)_H_$(3))/$(CFG_LIBRUSTDOC_$(4)) \
114117
$$(TLIB$(1)_T_$(4)_H_$(3))/$(CFG_LIBRUSTC_$(4))
115118
@$$(call E, compile_and_link: $$@)
116119
$$(STAGE$(1)_T_$(4)_H_$(3)) -o $$@ $$< && touch $$@

branches/try2/src/driver/driver.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[no_core];
12-
extern mod core(vers = "0.7-pre");
13-
1411
#[cfg(rustpkg)]
1512
extern mod this(name = "rustpkg", vers = "0.7-pre");
1613

branches/try2/src/libcore/at_vec.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
//! Managed vectors
1212
1313
use cast::transmute;
14+
use container::Container;
1415
use kinds::Copy;
1516
use old_iter;
17+
use old_iter::BaseIter;
1618
use option::Option;
1719
use sys;
1820
use uint;

branches/try2/src/libcore/cell.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,21 @@ pub fn empty_cell<T>() -> Cell<T> {
4444
pub impl<T> Cell<T> {
4545
/// Yields the value, failing if the cell is empty.
4646
fn take(&self) -> T {
47-
let self = unsafe { transmute_mut(self) };
48-
if self.is_empty() {
47+
let this = unsafe { transmute_mut(self) };
48+
if this.is_empty() {
4949
fail!(~"attempt to take an empty cell");
5050
}
5151
52-
replace(&mut self.value, None).unwrap()
52+
replace(&mut this.value, None).unwrap()
5353
}
5454
5555
/// Returns the value, failing if the cell is full.
5656
fn put_back(&self, value: T) {
57-
let self = unsafe { transmute_mut(self) };
58-
if !self.is_empty() {
57+
let this = unsafe { transmute_mut(self) };
58+
if !this.is_empty() {
5959
fail!(~"attempt to put a value back into a full cell");
6060
}
61-
self.value = Some(value);
61+
this.value = Some(value);
6262
}
6363

6464
/// Returns true if the cell is empty and false if the cell is full.

branches/try2/src/libcore/comm.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ Message passing
1313
*/
1414

1515
use cast::{transmute, transmute_mut};
16+
use container::Container;
1617
use either::{Either, Left, Right};
1718
use kinds::Owned;
1819
use option::{Option, Some, None};
1920
use uint;
20-
use unstable;
2121
use vec;
22-
use unstable::Exclusive;
22+
use vec::OwnedVector;
2323
use util::replace;
24+
use unstable::sync::{Exclusive, exclusive};
2425

2526
use pipes::{recv, try_recv, wait_many, peek, PacketHeader};
2627

@@ -304,7 +305,7 @@ pub struct SharedChan<T> {
304305
impl<T: Owned> SharedChan<T> {
305306
/// Converts a `chan` into a `shared_chan`.
306307
pub fn new(c: Chan<T>) -> SharedChan<T> {
307-
SharedChan { ch: unstable::exclusive(c) }
308+
SharedChan { ch: exclusive(c) }
308309
}
309310
}
310311
@@ -577,7 +578,7 @@ impl<T:Owned,
577578
#[cfg(test)]
578579
mod test {
579580
use either::Right;
580-
use super::{Chan, Port, oneshot, recv_one, stream};
581+
use super::{Chan, Port, oneshot, stream};
581582
582583
#[test]
583584
fn test_select2() {

branches/try2/src/libcore/core.rc

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -68,48 +68,6 @@ they contained the following prologue:
6868
#[cfg(test)] pub use ops = realcore::ops;
6969
#[cfg(test)] pub use cmp = realcore::cmp;
7070

71-
/* Reexported core operators */
72-
73-
pub use kinds::{Const, Copy, Owned};
74-
pub use ops::{Drop};
75-
pub use ops::{Add, Sub, Mul, Div, Rem, Neg, Not};
76-
pub use ops::{BitAnd, BitOr, BitXor};
77-
pub use ops::{Shl, Shr, Index};
78-
79-
80-
/* Reexported types and traits */
81-
82-
pub use option::{Option, Some, None};
83-
pub use result::{Result, Ok, Err};
84-
85-
pub use path::Path;
86-
pub use path::GenericPath;
87-
pub use path::WindowsPath;
88-
pub use path::PosixPath;
89-
90-
pub use tuple::{CopyableTuple, ImmutableTuple, ExtendedTupleOps};
91-
pub use str::{StrSlice};
92-
pub use container::{Container, Mutable};
93-
pub use vec::{CopyableVector, ImmutableVector};
94-
pub use vec::{ImmutableEqVector, ImmutableCopyableVector};
95-
pub use vec::{OwnedVector, OwnedCopyableVector, MutableVector};
96-
pub use old_iter::{BaseIter, ExtendedIter, EqIter, CopyableIter};
97-
pub use old_iter::{CopyableOrderedIter, CopyableNonstrictIter};
98-
pub use old_iter::{ExtendedMutableIter};
99-
pub use iter::Times;
100-
101-
pub use num::{Num, NumCast};
102-
pub use num::{Orderable, Signed, Unsigned, Round};
103-
pub use num::{Algebraic, Trigonometric, Exponential, Hyperbolic};
104-
pub use num::{Integer, Fractional, Real, RealExt};
105-
pub use num::{Bitwise, BitCount, Bounded};
106-
pub use num::{Primitive, Int, Float};
107-
108-
pub use ptr::Ptr;
109-
pub use from_str::FromStr;
110-
pub use to_str::ToStr;
111-
pub use clone::Clone;
112-
11371
// On Linux, link to the runtime with -lrt.
11472
#[cfg(target_os = "linux")]
11573
#[doc(hidden)]
@@ -238,6 +196,7 @@ pub mod util;
238196
/* Unsupported interfaces */
239197

240198
// Private APIs
199+
#[path = "unstable/mod.rs"]
241200
pub mod unstable;
242201

243202
/* For internal use, not exported */

0 commit comments

Comments
 (0)