Skip to content

Commit 0a6943d

Browse files
committed
Merge pull request #2684 from mozilla/incoming
Incoming
2 parents 8395305 + f331cd9 commit 0a6943d

File tree

128 files changed

+639
-892
lines changed

Some content is hidden

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

128 files changed

+639
-892
lines changed

doc/rust.md

Lines changed: 16 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -330,24 +330,32 @@ An _integer literal_ has one of three forms:
330330
* A _binary literal_ starts with the character sequence `U+0030` `U+0062`
331331
(`0b`) and continues as any mixture binary digits and underscores.
332332

333-
By default, an integer literal is of type `int`. An integer literal may be
334-
followed (immediately, without any spaces) by an _integer suffix_, which
335-
changes the type of the literal. There are two kinds of integer literal
336-
suffix:
333+
An integer literal may be followed (immediately, without any spaces) by an
334+
_integer suffix_, which changes the type of the literal. There are two kinds
335+
of integer literal suffix:
337336

338-
* The `u` suffix gives the literal type `uint`.
337+
* The `i` and `u` suffixes give the literal type `int` or `uint`,
338+
respectively.
339339
* Each of the signed and unsigned machine types `u8`, `i8`,
340340
`u16`, `i16`, `u32`, `i32`, `u64` and `i64`
341341
give the literal the corresponding machine type.
342342

343+
The type of an _unsuffixed_ integer literal is determined by type inference.
344+
If a integer type can be _uniquely_ determined from the surrounding program
345+
context, the unsuffixed integer literal has that type. If the program context
346+
underconstrains the type, the unsuffixed integer literal's type is `int`; if
347+
the program context overconstrains the type, it is considered a static type
348+
error.
343349

344350
Examples of integer literals of various forms:
345351

346352
~~~~
347-
123; // type int
353+
123; 0xff00; // type determined by program context;
354+
// defaults to int in absence of type
355+
// information
356+
348357
123u; // type uint
349358
123_u; // type uint
350-
0xff00; // type int
351359
0xff_u8; // type u8
352360
0b1111_1111_1001_0000_i32; // type i32
353361
~~~~
@@ -980,7 +988,7 @@ fn pure_foldl<T, U: copy>(ls: list<T>, u: U, f: fn(&&T, &&U) -> U) -> U {
980988
pure fn pure_length<T>(ls: list<T>) -> uint {
981989
fn count<T>(_t: T, &&u: uint) -> uint { u + 1u }
982990
unchecked {
983-
pure_foldl(ls, 0u, count(_, _))
991+
pure_foldl(ls, 0u, count)
984992
}
985993
}
986994
~~~~
@@ -1941,49 +1949,6 @@ An example of a call expression:
19411949
let x: int = add(1, 2);
19421950
~~~~
19431951

1944-
1945-
### Bind expressions
1946-
1947-
A _bind expression_ constructs a new function from an existing function.^[The
1948-
`bind` expression is analogous to the `bind` expression in the Sather
1949-
language.] The new function has zero or more of its arguments *bound* into a
1950-
new, hidden boxed tuple that holds the bindings. For each concrete argument
1951-
passed in the `bind` expression, the corresponding parameter in the existing
1952-
function is *omitted* as a parameter of the new function. For each argument
1953-
passed the placeholder symbol `_` in the `bind` expression, the corresponding
1954-
parameter of the existing function is *retained* as a parameter of the new
1955-
function.
1956-
1957-
Any subsequent invocation of the new function with residual arguments causes
1958-
invocation of the existing function with the combination of bound arguments
1959-
and residual arguments that was specified during the binding.
1960-
1961-
An example of a `bind` expression:
1962-
1963-
~~~~{.xfail-test}
1964-
fn add(x: int, y: int) -> int {
1965-
ret x + y;
1966-
}
1967-
type single_param_fn = fn(int) -> int;
1968-
1969-
let add4: single_param_fn = bind add(4, _);
1970-
1971-
let add5: single_param_fn = bind add(_, 5);
1972-
1973-
assert (add(4,5) == add4(5));
1974-
assert (add(4,5) == add5(4));
1975-
1976-
~~~~
1977-
1978-
A `bind` expression generally stores a copy of the bound arguments in a
1979-
hidden, boxed tuple, owned by the resulting first-class function. For each
1980-
bound slot in the bound function's signature, space is allocated in the hidden
1981-
tuple and populated with a copy of the bound value.
1982-
1983-
A `bind` expression is an alternative way of constructing a shared function
1984-
closure; the [`fn@` expression](#shared-function-expressions) form is another
1985-
way.
1986-
19871952
### Shared function expressions
19881953

19891954
*TODO*.

doc/tutorial.md

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -396,22 +396,67 @@ synonym.
396396

397397
## Literals
398398

399+
### Numeric literals
400+
399401
Integers can be written in decimal (`144`), hexadecimal (`0x90`), and
400-
binary (`0b10010000`) base. Without a suffix, an integer literal is
401-
considered to be of type `int`. Add a `u` (`144u`) to make it a `uint`
402-
instead. Literals of the fixed-size integer types can be created by
403-
the literal with the type name (`255u8`, `50i64`, etc).
402+
binary (`0b10010000`) base.
403+
404+
If you write an integer literal without a suffix (`3`, `-500`, etc.),
405+
the Rust compiler will try to infer its type based on type annotations
406+
and function signatures in the surrounding program. For example, here
407+
the type of `x` is inferred to be `u16` because it is passed to a
408+
function that takes a `u16` argument:
409+
410+
~~~~~
411+
let x = 3;
412+
413+
fn identity_u16(n: u16) -> u16 { n }
414+
415+
identity_u16(x);
416+
~~~~
417+
418+
On the other hand, if the program gives conflicting information about
419+
what the type of the unsuffixed literal should be, you'll get an error
420+
message.
421+
422+
~~~~~{.xfail-test}
423+
let x = 3;
424+
let y: i32 = 3;
425+
426+
fn identity_u8(n: u8) -> u8 { n }
427+
fn identity_u16(n: u16) -> u16 { n }
428+
429+
identity_u8(x); // after this, `x` is assumed to have type `u8`
430+
identity_u16(x); // raises a type error (expected `u16` but found `u8`)
431+
identity_u16(y); // raises a type error (expected `u16` but found `i32`)
432+
~~~~
433+
434+
In the absence of any type annotations at all, Rust will assume that
435+
an unsuffixed integer literal has type `int`.
436+
437+
~~~~
438+
let n = 50;
439+
log(error, n); // n is an int
440+
~~~~
441+
442+
It's also possible to avoid any type ambiguity by writing integer
443+
literals with a suffix. The suffixes `i` and `u` are for the types
444+
`int` and `uint`, respectively: the literal `-3i` has type `int`,
445+
while `127u` has type `uint`. For the fixed-size integer types, just
446+
suffix the literal with the type name: `255u8`, `50i64`, etc.
404447
405448
Note that, in Rust, no implicit conversion between integer types
406-
happens. If you are adding one to a variable of type `uint`, you must
407-
type `v += 1u`—saying `+= 1` will give you a type error.
449+
happens. If you are adding one to a variable of type `uint`, saying
450+
`+= 1u8` will give you a type error.
408451
409452
Floating point numbers are written `0.0`, `1e6`, or `2.1e-4`. Without
410453
a suffix, the literal is assumed to be of type `float`. Suffixes `f32`
411454
and `f64` can be used to create literals of a specific type. The
412455
suffix `f` can be used to write `float` literals without a dot or
413456
exponent: `3f`.
414457
458+
### Other literals
459+
415460
The nil literal is written just like the type: `()`. The keywords
416461
`true` and `false` produce the boolean literals.
417462
@@ -903,19 +948,6 @@ argument to every element of a vector, producing a new vector.
903948
Even when a closure takes no parameters, you must still write the bars
904949
for the parameter list, as in `{|| ...}`.
905950
906-
## Binding
907-
908-
Partial application is done using the `bind` keyword in Rust.
909-
910-
~~~~
911-
let findx = bind str::find_char(_, 'x');
912-
~~~~
913-
914-
Binding a function produces a boxed closure (`fn@` type) in which some
915-
of the arguments to the bound function have already been provided.
916-
`findx` will be a function taking a single string argument, and
917-
returning the position where the letter `x` occurs.
918-
919951
## Iteration
920952
921953
Functions taking closures provide a good way to define non-trivial

src/cargo/cargo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,8 @@ fn load_crate(filename: str) -> option<crate> {
328328
mut deps: []
329329
};
330330
let v = visit::mk_simple_visitor(@{
331-
visit_view_item: bind goto_view_item(e, _),
332-
visit_item: bind goto_item(e, _),
331+
visit_view_item: {|a|goto_view_item(e, a)},
332+
visit_item: {|a|goto_item(e, a)},
333333
with *visit::default_simple_visitor()
334334
});
335335

src/compiletest/runtest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ fn compose_and_run_compiler(
325325
let abs_ab = path::connect(config.aux_base, rel_ab);
326326
let aux_args =
327327
make_compile_args(config, props, ["--lib"] + extra_link_args,
328-
bind make_lib_name(_, _, testfile), abs_ab);
328+
{|a,b|make_lib_name(a, b, testfile)}, abs_ab);
329329
let auxres = compose_and_run(config, abs_ab, aux_args, [],
330330
config.compile_lib_path, option::none);
331331
if auxres.status != 0 {

src/fuzzer/fuzzer.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ fn steal(crate: ast::crate, tm: test_mode) -> stolen_stuff {
139139
let exprs = @mut [];
140140
let tys = @mut [];
141141
let v = visit::mk_simple_visitor(@{
142-
visit_expr: bind stash_expr_if(safe_to_steal_expr, exprs, _, tm),
143-
visit_ty: bind stash_ty_if(safe_to_steal_ty, tys, _, tm)
142+
visit_expr: {|a|stash_expr_if(safe_to_steal_expr, exprs, a, tm)},
143+
visit_ty: {|a|stash_ty_if(safe_to_steal_ty, tys, a, tm)}
144144
with *visit::default_simple_visitor()
145145
});
146146
visit::visit_crate(crate, (), v);
@@ -188,8 +188,8 @@ fn replace_expr_in_crate(crate: ast::crate, i: uint,
188188
}
189189
}
190190
let afp =
191-
@{fold_expr: fold::wrap(bind fold_expr_rep(j, i,
192-
newexpr.node, _, _, tm))
191+
@{fold_expr: fold::wrap({|a,b|
192+
fold_expr_rep(j, i, newexpr.node, a, b, tm)})
193193
with *fold::default_ast_fold()};
194194
let af = fold::make_fold(afp);
195195
let crate2: @ast::crate = @af.fold_crate(crate);
@@ -211,7 +211,7 @@ fn replace_ty_in_crate(crate: ast::crate, i: uint, newty: ast::ty,
211211
} else { fold::noop_fold_ty(original, fld) }
212212
}
213213
let afp =
214-
@{fold_ty: fold::wrap(bind fold_ty_rep(j, i, newty.node, _, _, tm))
214+
@{fold_ty: fold::wrap({|a,b|fold_ty_rep(j, i, newty.node, a, b, tm)})
215215
with *fold::default_ast_fold()};
216216
let af = fold::make_fold(afp);
217217
let crate2: @ast::crate = @af.fold_crate(crate);
@@ -235,7 +235,7 @@ fn check_variants_of_ast(crate: ast::crate, codemap: codemap::codemap,
235235
filename: str, cx: context) {
236236
let stolen = steal(crate, cx.mode);
237237
let extra_exprs = vec::filter(common_exprs(),
238-
bind safe_to_use_expr(_, cx.mode));
238+
{|a|safe_to_use_expr(a, cx.mode)});
239239
check_variants_T(crate, codemap, filename, "expr",
240240
extra_exprs + stolen.exprs, pprust::expr_to_str,
241241
replace_expr_in_crate, cx);
@@ -268,13 +268,13 @@ fn check_variants_T<T: copy>(
268268
// testing the string for stability is easier and ok for now.
269269
let handler = diagnostic::mk_handler(none);
270270
let str3 =
271-
@as_str(bind pprust::print_crate(
271+
@as_str({|a|pprust::print_crate(
272272
codemap,
273273
diagnostic::mk_span_handler(handler, codemap),
274274
crate2,
275275
filename,
276-
io::str_reader(""), _,
277-
pprust::no_ann()));
276+
io::str_reader(""), a,
277+
pprust::no_ann())});
278278
alt cx.mode {
279279
tm_converge {
280280
check_roundtrip_convergence(str3, 1u);
@@ -421,12 +421,12 @@ fn parse_and_print(code: @str) -> str {
421421
let crate = parse::parse_crate_from_source_str(
422422
filename, code, [], sess);
423423
io::with_str_reader(*code) { |rdr|
424-
as_str(bind pprust::print_crate(sess.cm,
424+
as_str({|a|pprust::print_crate(sess.cm,
425425
sess.span_diagnostic,
426426
crate,
427427
filename,
428-
rdr, _,
429-
pprust::no_ann()))
428+
rdr, a,
429+
pprust::no_ann())})
430430
}
431431
}
432432

@@ -439,7 +439,7 @@ fn has_raw_pointers(c: ast::crate) -> bool {
439439
}
440440
}
441441
let v =
442-
visit::mk_simple_visitor(@{visit_ty: bind visit_ty(has_rp, _)
442+
visit::mk_simple_visitor(@{visit_ty: {|a|visit_ty(has_rp, a)}
443443
with *visit::default_simple_visitor()});
444444
visit::visit_crate(c, (), v);
445445
ret *has_rp;
@@ -565,12 +565,12 @@ fn check_variants(files: [str], cx: context) {
565565
s, [], sess);
566566
io::with_str_reader(*s) { |rdr|
567567
#error("%s",
568-
as_str(bind pprust::print_crate(sess.cm,
568+
as_str({|a|pprust::print_crate(sess.cm,
569569
sess.span_diagnostic,
570570
crate,
571571
file,
572-
rdr, _,
573-
pprust::no_ann())));
572+
rdr, a,
573+
pprust::no_ann())}));
574574
}
575575
check_variants_of_ast(*crate, sess.cm, file, cx);
576576
}

src/libcore/comm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,11 @@ fn peek<T: send>(p: port<T>) -> bool { peek_(***p) }
177177

178178
#[doc(hidden)]
179179
fn recv_chan<T: send>(ch: comm::chan<T>) -> T {
180-
as_raw_port(ch, recv_(_))
180+
as_raw_port(ch, {|x|recv_(x)})
181181
}
182182

183183
fn peek_chan<T: send>(ch: comm::chan<T>) -> bool {
184-
as_raw_port(ch, peek_(_))
184+
as_raw_port(ch, {|x|peek_(x)})
185185
}
186186

187187
#[doc = "Receive on a raw port pointer"]

src/libcore/extfmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ mod ct {
174174
let curr: [flag] = [f];
175175
ret {flags: curr + rest, next: j};
176176
}
177-
let more = bind more_(_, s, i, lim);
177+
let more = {|x|more_(x, s, i, lim)};
178178
let f = s[i];
179179
ret if f == '-' as u8 {
180180
more(flag_left_justify)

src/libstd/bitv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ Converts the bitvector to a vector of uint with the same length.
185185
Each uint in the resulting vector has either value 0u or 1u.
186186
"]
187187
fn to_vec(v: bitv) -> [uint] {
188-
let sub = bind init_to_vec(v, _);
188+
let sub = {|x|init_to_vec(v, x)};
189189
ret vec::from_fn::<uint>(v.nbits, sub);
190190
}
191191

src/libstd/c_vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ mod tests {
136136
assert mem as int != 0;
137137

138138
ret unsafe { c_vec_with_dtor(mem as *mut u8, n as uint,
139-
bind free(mem)) };
139+
{||free(mem)}) };
140140
}
141141

142142
#[test]

src/libstd/deque.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ mod tests {
292292
two(17, 42));
293293

294294
#debug("*** test parameterized: taggypar<int>");
295-
let eq4: eqfn<taggypar<int>> = bind taggypareq::<int>(_, _);
295+
let eq4: eqfn<taggypar<int>> = {|x,y|taggypareq::<int>(x, y)};
296296
test_parameterized::<taggypar<int>>(eq4, onepar::<int>(1),
297297
twopar::<int>(1, 2),
298298
threepar::<int>(1, 2, 3),

src/libstd/test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ fn run_tests_console(opts: test_opts,
162162
mut ignored: 0u,
163163
mut failures: []};
164164

165-
run_tests(opts, tests, bind callback(_, st));
165+
run_tests(opts, tests, {|x|callback(x, st)});
166166

167167
assert (st.passed + st.failed + st.ignored == st.total);
168168
let success = st.failed == 0u;
@@ -349,7 +349,7 @@ fn filter_tests(opts: test_opts,
349349
} else { ret option::none; }
350350
}
351351

352-
let filter = bind filter_fn(_, filter_str);
352+
let filter = {|x|filter_fn(x, filter_str)};
353353

354354
vec::filter_map(filtered, filter)
355355
};
@@ -367,7 +367,7 @@ fn filter_tests(opts: test_opts,
367367
} else { ret option::none; }
368368
};
369369

370-
vec::filter_map(filtered, bind filter(_))
370+
vec::filter_map(filtered, {|x|filter(x)})
371371
};
372372

373373
// Sort the tests alphabetically
@@ -376,7 +376,7 @@ fn filter_tests(opts: test_opts,
376376
fn lteq(t1: test_desc, t2: test_desc) -> bool {
377377
str::le(t1.name, t2.name)
378378
}
379-
sort::merge_sort(bind lteq(_, _), filtered)
379+
sort::merge_sort({|x,y|lteq(x, y)}, filtered)
380380
};
381381

382382
ret filtered;

0 commit comments

Comments
 (0)