Skip to content

Commit 3abc5b3

Browse files
committed
auto merge of #6417 : pcwalton/rust/exprs-in-patterns, r=pcwalton
r? @graydon
2 parents 1b88336 + 26a28da commit 3abc5b3

Some content is hidden

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

66 files changed

+935
-824
lines changed

doc/rust.md

+40-41
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

doc/tutorial-ffi.md

+2-1
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
~~~~

src/libcore/cell.rs

+6-6
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.

src/libcore/num/strconv.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -486,11 +486,11 @@ pub fn from_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Copy+Div<T,T>+
486486
}
487487
}
488488

489-
let (start, accum_positive) = match buf[0] {
490-
'-' as u8 if !negative => return None,
491-
'-' as u8 => (1u, false),
492-
'+' as u8 => (1u, true),
493-
_ => (0u, true)
489+
let (start, accum_positive) = match buf[0] as char {
490+
'-' if !negative => return None,
491+
'-' => (1u, false),
492+
'+' => (1u, true),
493+
_ => (0u, true)
494494
};
495495

496496
// Initialize accumulator with signed zero for floating point parsing to

src/libcore/old_iter.rs

+43-37
Original file line numberDiff line numberDiff line change
@@ -116,66 +116,72 @@ pub trait Buildable<A> {
116116
}
117117

118118
#[inline(always)]
119-
pub fn _eachi<A,IA:BaseIter<A>>(self: &IA, blk: &fn(uint, &A) -> bool) -> bool {
119+
pub fn _eachi<A,IA:BaseIter<A>>(this: &IA, blk: &fn(uint, &A) -> bool) -> bool {
120120
let mut i = 0;
121-
for self.each |a| {
122-
if !blk(i, a) { return false; }
121+
for this.each |a| {
122+
if !blk(i, a) {
123+
return false;
124+
}
123125
i += 1;
124126
}
125127
return true;
126128
}
127129

128130
#[cfg(stage0)]
129-
pub fn eachi<A,IA:BaseIter<A>>(self: &IA, blk: &fn(uint, &A) -> bool) {
130-
_eachi(self, blk);
131+
pub fn eachi<A,IA:BaseIter<A>>(this: &IA, blk: &fn(uint, &A) -> bool) {
132+
_eachi(this, blk);
131133
}
132134
#[cfg(not(stage0))]
133-
pub fn eachi<A,IA:BaseIter<A>>(self: &IA, blk: &fn(uint, &A) -> bool) -> bool {
134-
_eachi(self, blk)
135+
pub fn eachi<A,IA:BaseIter<A>>(this: &IA, blk: &fn(uint, &A) -> bool) -> bool {
136+
_eachi(this, blk)
135137
}
136138

137139
#[inline(always)]
138-
pub fn all<A,IA:BaseIter<A>>(self: &IA, blk: &fn(&A) -> bool) -> bool {
139-
for self.each |a| {
140-
if !blk(a) { return false; }
140+
pub fn all<A,IA:BaseIter<A>>(this: &IA, blk: &fn(&A) -> bool) -> bool {
141+
for this.each |a| {
142+
if !blk(a) {
143+
return false;
144+
}
141145
}
142146
return true;
143147
}
144148

145149
#[inline(always)]
146-
pub fn any<A,IA:BaseIter<A>>(self: &IA, blk: &fn(&A) -> bool) -> bool {
147-
for self.each |a| {
148-
if blk(a) { return true; }
150+
pub fn any<A,IA:BaseIter<A>>(this: &IA, blk: &fn(&A) -> bool) -> bool {
151+
for this.each |a| {
152+
if blk(a) {
153+
return true;
154+
}
149155
}
150156
return false;
151157
}
152158

153159
#[inline(always)]
154-
pub fn filter_to_vec<A:Copy,IA:BaseIter<A>>(self: &IA,
160+
pub fn filter_to_vec<A:Copy,IA:BaseIter<A>>(this: &IA,
155161
prd: &fn(&A) -> bool)
156162
-> ~[A] {
157-
do vec::build_sized_opt(self.size_hint()) |push| {
158-
for self.each |a| {
163+
do vec::build_sized_opt(this.size_hint()) |push| {
164+
for this.each |a| {
159165
if prd(a) { push(*a); }
160166
}
161167
}
162168
}
163169

164170
#[inline(always)]
165-
pub fn map_to_vec<A,B,IA:BaseIter<A>>(self: &IA, op: &fn(&A) -> B) -> ~[B] {
166-
do vec::build_sized_opt(self.size_hint()) |push| {
167-
for self.each |a| {
171+
pub fn map_to_vec<A,B,IA:BaseIter<A>>(this: &IA, op: &fn(&A) -> B) -> ~[B] {
172+
do vec::build_sized_opt(this.size_hint()) |push| {
173+
for this.each |a| {
168174
push(op(a));
169175
}
170176
}
171177
}
172178

173179
#[inline(always)]
174-
pub fn flat_map_to_vec<A,B,IA:BaseIter<A>,IB:BaseIter<B>>(self: &IA,
180+
pub fn flat_map_to_vec<A,B,IA:BaseIter<A>,IB:BaseIter<B>>(this: &IA,
175181
op: &fn(&A) -> IB)
176182
-> ~[B] {
177183
do vec::build |push| {
178-
for self.each |a| {
184+
for this.each |a| {
179185
for op(a).each |&b| {
180186
push(b);
181187
}
@@ -184,31 +190,31 @@ pub fn flat_map_to_vec<A,B,IA:BaseIter<A>,IB:BaseIter<B>>(self: &IA,
184190
}
185191

186192
#[inline(always)]
187-
pub fn foldl<A,B,IA:BaseIter<A>>(self: &IA, b0: B, blk: &fn(&B, &A) -> B)
193+
pub fn foldl<A,B,IA:BaseIter<A>>(this: &IA, b0: B, blk: &fn(&B, &A) -> B)
188194
-> B {
189195
let mut b = b0;
190-
for self.each |a| {
196+
for this.each |a| {
191197
b = blk(&b, a);
192198
}
193199
b
194200
}
195201

196202
#[inline(always)]
197-
pub fn to_vec<A:Copy,IA:BaseIter<A>>(self: &IA) -> ~[A] {
198-
map_to_vec(self, |&x| x)
203+
pub fn to_vec<A:Copy,IA:BaseIter<A>>(this: &IA) -> ~[A] {
204+
map_to_vec(this, |&x| x)
199205
}
200206

201207
#[inline(always)]
202-
pub fn contains<A:Eq,IA:BaseIter<A>>(self: &IA, x: &A) -> bool {
203-
for self.each |a| {
208+
pub fn contains<A:Eq,IA:BaseIter<A>>(this: &IA, x: &A) -> bool {
209+
for this.each |a| {
204210
if *a == *x { return true; }
205211
}
206212
return false;
207213
}
208214

209215
#[inline(always)]
210-
pub fn count<A:Eq,IA:BaseIter<A>>(self: &IA, x: &A) -> uint {
211-
do foldl(self, 0) |count, value| {
216+
pub fn count<A:Eq,IA:BaseIter<A>>(this: &IA, x: &A) -> uint {
217+
do foldl(this, 0) |count, value| {
212218
if *value == *x {
213219
*count + 1
214220
} else {
@@ -218,10 +224,10 @@ pub fn count<A:Eq,IA:BaseIter<A>>(self: &IA, x: &A) -> uint {
218224
}
219225

220226
#[inline(always)]
221-
pub fn position<A,IA:BaseIter<A>>(self: &IA, f: &fn(&A) -> bool)
227+
pub fn position<A,IA:BaseIter<A>>(this: &IA, f: &fn(&A) -> bool)
222228
-> Option<uint> {
223229
let mut i = 0;
224-
for self.each |a| {
230+
for this.each |a| {
225231
if f(a) { return Some(i); }
226232
i += 1;
227233
}
@@ -253,8 +259,8 @@ pub fn repeat(times: uint, blk: &fn() -> bool) -> bool {
253259
}
254260

255261
#[inline(always)]
256-
pub fn min<A:Copy + Ord,IA:BaseIter<A>>(self: &IA) -> A {
257-
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
262+
pub fn min<A:Copy + Ord,IA:BaseIter<A>>(this: &IA) -> A {
263+
match do foldl::<A,Option<A>,IA>(this, None) |a, b| {
258264
match a {
259265
&Some(ref a_) if *a_ < *b => {
260266
*(a)
@@ -268,8 +274,8 @@ pub fn min<A:Copy + Ord,IA:BaseIter<A>>(self: &IA) -> A {
268274
}
269275
270276
#[inline(always)]
271-
pub fn max<A:Copy + Ord,IA:BaseIter<A>>(self: &IA) -> A {
272-
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
277+
pub fn max<A:Copy + Ord,IA:BaseIter<A>>(this: &IA) -> A {
278+
match do foldl::<A,Option<A>,IA>(this, None) |a, b| {
273279
match a {
274280
&Some(ref a_) if *a_ > *b => {
275281
*(a)
@@ -283,9 +289,9 @@ pub fn max<A:Copy + Ord,IA:BaseIter<A>>(self: &IA) -> A {
283289
}
284290

285291
#[inline(always)]
286-
pub fn find<A:Copy,IA:BaseIter<A>>(self: &IA, f: &fn(&A) -> bool)
292+
pub fn find<A:Copy,IA:BaseIter<A>>(this: &IA, f: &fn(&A) -> bool)
287293
-> Option<A> {
288-
for self.each |i| {
294+
for this.each |i| {
289295
if f(i) { return Some(*i) }
290296
}
291297
return None;

0 commit comments

Comments
 (0)