Skip to content

Commit 054f624

Browse files
committed
---
yaml --- r: 42634 b: refs/heads/try c: 86b8bf3 h: refs/heads/master v: v3
1 parent 0bfc506 commit 054f624

File tree

20 files changed

+135
-94
lines changed

20 files changed

+135
-94
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 19dfec2aaf746535de1521f68421f9980dbf25de
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 2f46b763da2c098913884f101b6d71d69af41b49
5-
refs/heads/try: d912d53ea9921c4fc9044c657ddcb3e044617fa9
5+
refs/heads/try: 86b8bf37bbd5c83953933c9c38a20567843c3a7f
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278

branches/try/AUTHORS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,5 @@ Vincent Belliard <[email protected]>
148148
Wade Mealing <[email protected]>
149149
William Ting <[email protected]>
150150
Yasuhiro Fujii <[email protected]>
151+
Youngsoo Son <[email protected]>
151152
Zack Corr <[email protected]>

branches/try/doc/rust.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ let log loop
222222
match mod move mut
223223
priv pub pure
224224
ref return
225-
self static struct
225+
self static struct super
226226
true trait type
227227
unsafe use
228228
while

branches/try/src/libcore/hashmap.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ pub mod linear {
6060
((capacity as float) * 3. / 4.) as uint
6161
}
6262

63-
pub fn LinearMap<K:Eq Hash,V>() -> LinearMap<K,V> {
64-
linear_map_with_capacity(INITIAL_CAPACITY)
65-
}
66-
6763
pub fn linear_map_with_capacity<K:Eq Hash,V>(
6864
initial_capacity: uint) -> LinearMap<K,V> {
6965
let r = rand::Rng();
@@ -351,7 +347,8 @@ pub mod linear {
351347
}
352348
}
353349

354-
impl<K:Hash IterBytes Eq,V> LinearMap<K,V> {
350+
pub impl<K:Hash IterBytes Eq,V> LinearMap<K,V> {
351+
/// Create an empty LinearMap
355352
static fn new() -> LinearMap<K, V> {
356353
linear_map_with_capacity(INITIAL_CAPACITY)
357354
}
@@ -495,7 +492,7 @@ pub mod linear {
495492

496493
pub impl <T: Hash IterBytes Eq> LinearSet<T> {
497494
/// Create an empty LinearSet
498-
static fn new() -> LinearSet<T> { LinearSet{map: LinearMap()} }
495+
static fn new() -> LinearSet<T> { LinearSet{map: LinearMap::new()} }
499496
}
500497
}
501498

branches/try/src/librustc/middle/resolve.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use core::prelude::*;
1212

13+
use driver::session;
1314
use driver::session::Session;
1415
use metadata::csearch::{each_path, get_method_names_if_trait};
1516
use metadata::csearch::{get_static_methods_if_impl, get_type_name_if_impl};
@@ -3931,7 +3932,10 @@ impl Resolver {
39313932
item_fn(ref fn_decl, _, ref ty_params, ref block) => {
39323933
// If this is the main function, we must record it in the
39333934
// session.
3934-
if !self.session.building_library {
3935+
// FIXME #4404 android JNI hacks
3936+
if !self.session.building_library ||
3937+
self.session.targ_cfg.os == session::os_android {
3938+
39353939
if self.attr_main_fn.is_none() &&
39363940
item.ident == special_idents::main {
39373941

branches/try/src/librustc/middle/trans/base.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ use middle::trans::shape::*;
6262
use middle::trans::tvec;
6363
use middle::trans::type_of::*;
6464
use util::common::indenter;
65-
use util::common::is_main_name;
6665
use util::ppaux::{ty_to_str, ty_to_short_str};
6766
use util::ppaux;
6867

@@ -2191,14 +2190,9 @@ fn is_main_fn(sess: &Session, node_id: ast::node_id) -> bool {
21912190

21922191
// Create a _rust_main(args: ~[str]) function which will be called from the
21932192
// runtime rust_start function
2194-
fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef) {
2195-
2196-
if ccx.main_fn != None::<ValueRef> {
2197-
ccx.sess.span_fatal(sp, ~"multiple 'main' functions");
2198-
}
2193+
fn create_main_wrapper(ccx: @crate_ctxt, _sp: span, main_llfn: ValueRef) {
21992194

22002195
let llfn = create_main(ccx, main_llfn);
2201-
ccx.main_fn = Some(llfn);
22022196
create_entry_fn(ccx, llfn);
22032197

22042198
fn create_main(ccx: @crate_ctxt, main_llfn: ValueRef) -> ValueRef {
@@ -3008,7 +3002,6 @@ fn trans_crate(sess: session::Session,
30083002
exp_map2: emap2,
30093003
reachable: reachable,
30103004
item_symbols: HashMap(),
3011-
mut main_fn: None::<ValueRef>,
30123005
link_meta: link_meta,
30133006
enum_sizes: ty::new_ty_hash(),
30143007
discrims: HashMap(),

branches/try/src/librustc/middle/trans/common.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ struct crate_ctxt {
163163
exp_map2: resolve::ExportMap2,
164164
reachable: reachable::map,
165165
item_symbols: HashMap<ast::node_id, ~str>,
166-
mut main_fn: Option<ValueRef>,
167166
link_meta: link_meta,
168167
enum_sizes: HashMap<ty::t, uint>,
169168
discrims: HashMap<ast::def_id, ValueRef>,

branches/try/src/librustc/middle/ty.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,13 +1659,13 @@ fn subst(cx: ctxt,
16591659
}
16601660
}
16611661
1662-
// Performs substitutions on a set of substitutions (result = super(sub)) to
1662+
// Performs substitutions on a set of substitutions (result = sup(sub)) to
16631663
// yield a new set of substitutions. This is used in trait inheritance.
1664-
fn subst_substs(cx: ctxt, super: &substs, sub: &substs) -> substs {
1664+
fn subst_substs(cx: ctxt, sup: &substs, sub: &substs) -> substs {
16651665
{
1666-
self_r: super.self_r,
1667-
self_ty: super.self_ty.map(|typ| subst(cx, sub, *typ)),
1668-
tps: super.tps.map(|typ| subst(cx, sub, *typ))
1666+
self_r: sup.self_r,
1667+
self_ty: sup.self_ty.map(|typ| subst(cx, sub, *typ)),
1668+
tps: sup.tps.map(|typ| subst(cx, sub, *typ))
16691669
}
16701670
}
16711671

branches/try/src/librustc/middle/typeck/check/mod.rs

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,7 +1497,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
14971497
match ty::get(lhs_resolved_t).sty {
14981498
ty::ty_fn(_) => {
14991499
tcx.sess.span_note(
1500-
ex.span, ~"did you forget the 'do' keyword for the call?");
1500+
ex.span, ~"did you forget the `do` keyword for the call?");
15011501
}
15021502
_ => ()
15031503
}
@@ -2207,23 +2207,33 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
22072207
Some(ty::ty_fn(ref fty)) => {
22082208
match fcx.mk_subty(false, expr.span,
22092209
(*fty).sig.output, ty::mk_bool(tcx)) {
2210-
result::Ok(_) => (),
2210+
result::Ok(_) =>
2211+
ty::mk_fn(tcx, FnTyBase {
2212+
meta: (*fty).meta,
2213+
sig: FnSig {output: ty::mk_nil(tcx),
2214+
../*bad*/copy (*fty).sig}
2215+
}),
22112216
result::Err(_) => {
22122217
fcx.type_error_message(expr.span,
22132218
|actual| {
2214-
fmt!("a `loop` function's last argument \
2215-
should return `bool`, not `%s`", actual)
2219+
fmt!("A `for` loop iterator should expect a \
2220+
closure that returns `bool`. This iterator \
2221+
expects a closure that returns `%s`. %s",
2222+
actual, if ty::type_is_nil((*fty).sig.output) {
2223+
"\nDid you mean to use `do` instead of \
2224+
`for`?" } else { "" } )
22162225
},
22172226
(*fty).sig.output, None);
22182227
err_happened = true;
2228+
// Kind of a hack: create a function type with the result
2229+
// replaced with ty_err, to suppress derived errors.
2230+
let t = ty::replace_fn_return_type(tcx, ty::mk_fn(tcx,
2231+
copy *fty),
2232+
ty::mk_err(tcx));
22192233
fcx.write_ty(id, ty::mk_err(tcx));
2234+
t
22202235
}
22212236
}
2222-
ty::mk_fn(tcx, FnTyBase {
2223-
meta: (*fty).meta,
2224-
sig: FnSig {output: ty::mk_nil(tcx),
2225-
../*bad*/copy (*fty).sig}
2226-
})
22272237
}
22282238
_ =>
22292239
match expected {
@@ -2245,14 +2255,22 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
22452255
}
22462256
};
22472257
match b.node {
2248-
ast::expr_fn_block(ref decl, ref body, cap_clause) => {
2249-
check_expr_fn(fcx, b, None,
2250-
decl, *body, ForLoop, Some(inner_ty));
2251-
demand::suptype(fcx, b.span, inner_ty, fcx.expr_ty(b));
2252-
capture::check_capture_clause(tcx, b.id, cap_clause);
2253-
}
2254-
// argh
2255-
_ => fail ~"expr_fn_block"
2258+
ast::expr_fn_block(ref decl, ref body, cap_clause) => {
2259+
// If an error occurred, we pretend this isn't a for
2260+
// loop, so as to assign types to all nodes while also
2261+
// propagating ty_err throughout so as to suppress
2262+
// derived errors. If we passed in ForLoop in the
2263+
// error case, we'd potentially emit a spurious error
2264+
// message because of the indirect_ret_ty.
2265+
let fn_kind = if err_happened { Vanilla }
2266+
else { ForLoop };
2267+
check_expr_fn(fcx, b, None,
2268+
decl, *body, fn_kind, Some(inner_ty));
2269+
demand::suptype(fcx, b.span, inner_ty, fcx.expr_ty(b));
2270+
capture::check_capture_clause(tcx, b.id, cap_clause);
2271+
}
2272+
// argh
2273+
_ => fail ~"expr_fn_block"
22562274
}
22572275
let block_ty = structurally_resolved_type(
22582276
fcx, expr.span, fcx.node_ty(b.id));

branches/try/src/librustc/util/common.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,6 @@ fn local_rhs_span(l: @ast::local, def: span) -> span {
101101
}
102102
}
103103

104-
fn is_main_name(path: syntax::ast_map::path) -> bool {
105-
vec::last(path) == syntax::ast_map::path_name(
106-
syntax::parse::token::special_idents::main
107-
)
108-
}
109-
110104
fn pluralize(n: uint, +s: ~str) -> ~str {
111105
if n == 1 { s }
112106
else { str::concat([s, ~"s"]) }

branches/try/src/libstd/priority_queue.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ impl <T: Ord> PriorityQueue<T> {
4747
if self.is_empty() { None } else { Some(self.top()) }
4848
}
4949

50+
/// Returns true if a queue contains some elements
51+
pure fn is_not_empty(&self) -> bool { self.data.is_not_empty() }
52+
5053
/// Returns the number of elements the queue can hold without reallocating
5154
pure fn capacity(&self) -> uint { vec::capacity(&self.data) }
5255

@@ -59,7 +62,7 @@ impl <T: Ord> PriorityQueue<T> {
5962
/// Pop the greatest item from the queue - fails if empty
6063
fn pop(&mut self) -> T {
6164
let mut item = self.data.pop();
62-
if !self.is_empty() { item <-> self.data[0]; self.siftdown(0); }
65+
if self.is_not_empty() { item <-> self.data[0]; self.siftdown(0); }
6366
item
6467
}
6568

@@ -77,7 +80,7 @@ impl <T: Ord> PriorityQueue<T> {
7780
/// Optimized version of a push followed by a pop
7881
fn push_pop(&mut self, item: T) -> T {
7982
let mut item = item;
80-
if !self.is_empty() && self.data[0] > item {
83+
if self.is_not_empty() && self.data[0] > item {
8184
item <-> self.data[0];
8285
self.siftdown(0);
8386
}
@@ -186,7 +189,7 @@ mod tests {
186189
let data = ~[2, 4, 6, 2, 1, 8, 10, 3, 5, 7, 0, 9, 1];
187190
let mut sorted = merge_sort(data, le);
188191
let mut heap = from_vec(data);
189-
while !heap.is_empty() {
192+
while heap.is_not_empty() {
190193
assert *heap.top() == sorted.last();
191194
assert heap.pop() == sorted.pop();
192195
}

branches/try/src/libstd/workcache.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ impl Context {
259259
static fn new(db: @Mut<Database>,
260260
lg: @Mut<Logger>,
261261
cfg: @json::Object) -> Context {
262-
Context {db: db, logger: lg, cfg: cfg, freshness: LinearMap()}
262+
Context{db: db, logger: lg, cfg: cfg, freshness: LinearMap::new()}
263263
}
264264
265265
fn prep<T:Owned
@@ -270,7 +270,7 @@ impl Context {
270270
blk: fn(@Mut<Prep>)->Work<T>) -> Work<T> {
271271
let p = @Mut(Prep {ctxt: self,
272272
fn_name: fn_name.to_owned(),
273-
declared_inputs: LinearMap()});
273+
declared_inputs: LinearMap::new()});
274274
blk(p)
275275
}
276276
}

branches/try/src/libsyntax/parse/parser.rs

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,43 +1660,45 @@ impl Parser {
16601660
// them as the lambda arguments
16611661
let e = self.parse_expr_res(RESTRICT_NO_BAR_OR_DOUBLEBAR_OP);
16621662
match e.node {
1663-
expr_call(f, args, false) => {
1664-
let block = self.parse_lambda_block_expr();
1665-
let last_arg = self.mk_expr(block.span.lo, block.span.hi,
1666-
ctor(block));
1667-
let args = vec::append(args, ~[last_arg]);
1668-
@expr {node: expr_call(f, args, true), .. *e}
1669-
}
1670-
expr_method_call(f, i, tps, args, false) => {
1671-
let block = self.parse_lambda_block_expr();
1672-
let last_arg = self.mk_expr(block.span.lo, block.span.hi,
1673-
ctor(block));
1674-
let args = vec::append(args, ~[last_arg]);
1675-
@expr {node: expr_method_call(f, i, tps, args, true), .. *e}
1676-
}
1677-
expr_field(f, i, tps) => {
1678-
let block = self.parse_lambda_block_expr();
1679-
let last_arg = self.mk_expr(block.span.lo, block.span.hi,
1680-
ctor(block));
1681-
@expr {node: expr_method_call(f, i, tps, ~[last_arg], true),
1682-
.. *e}
1683-
}
1684-
expr_path(*) | expr_call(*) | expr_method_call(*) |
1685-
expr_paren(*) => {
1686-
let block = self.parse_lambda_block_expr();
1687-
let last_arg = self.mk_expr(block.span.lo, block.span.hi,
1688-
ctor(block));
1689-
self.mk_expr(lo.lo, last_arg.span.hi,
1690-
expr_call(e, ~[last_arg], true))
1691-
}
1692-
_ => {
1693-
// There may be other types of expressions that can
1694-
// represent the callee in `for` and `do` expressions
1695-
// but they aren't represented by tests
1696-
debug!("sugary call on %?", e.node);
1697-
self.span_fatal(
1698-
lo, fmt!("`%s` must be followed by a block call", keyword));
1699-
}
1663+
expr_call(f, args, false) => {
1664+
let block = self.parse_lambda_block_expr();
1665+
let last_arg = self.mk_expr(block.span.lo, block.span.hi,
1666+
ctor(block));
1667+
let args = vec::append(args, ~[last_arg]);
1668+
self.mk_expr(lo.lo, block.span.hi, expr_call(f, args, true))
1669+
}
1670+
expr_method_call(f, i, tps, args, false) => {
1671+
let block = self.parse_lambda_block_expr();
1672+
let last_arg = self.mk_expr(block.span.lo, block.span.hi,
1673+
ctor(block));
1674+
let args = vec::append(args, ~[last_arg]);
1675+
self.mk_expr(lo.lo, block.span.hi,
1676+
expr_method_call(f, i, tps, args, true))
1677+
}
1678+
expr_field(f, i, tps) => {
1679+
let block = self.parse_lambda_block_expr();
1680+
let last_arg = self.mk_expr(block.span.lo, block.span.hi,
1681+
ctor(block));
1682+
self.mk_expr(lo.lo, block.span.hi,
1683+
expr_method_call(f, i, tps, ~[last_arg], true))
1684+
}
1685+
expr_path(*) | expr_call(*) | expr_method_call(*) |
1686+
expr_paren(*) => {
1687+
let block = self.parse_lambda_block_expr();
1688+
let last_arg = self.mk_expr(block.span.lo, block.span.hi,
1689+
ctor(block));
1690+
self.mk_expr(lo.lo, last_arg.span.hi,
1691+
expr_call(e, ~[last_arg], true))
1692+
}
1693+
_ => {
1694+
// There may be other types of expressions that can
1695+
// represent the callee in `for` and `do` expressions
1696+
// but they aren't represented by tests
1697+
debug!("sugary call on %?", e.node);
1698+
self.span_fatal(
1699+
lo, fmt!("`%s` must be followed by a block call",
1700+
keyword));
1701+
}
17001702
}
17011703
}
17021704

branches/try/src/libsyntax/parse/token.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ fn strict_keyword_table() -> HashMap<~str, ()> {
493493
~"once",
494494
~"priv", ~"pub", ~"pure",
495495
~"ref", ~"return",
496-
~"struct",
496+
~"struct", ~"super",
497497
~"true", ~"trait", ~"type",
498498
~"unsafe", ~"use",
499499
~"while"

branches/try/src/test/compile-fail/bad-for-loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010

1111
fn main() {
1212
fn baz(_x: fn(y: int) -> int) {}
13-
for baz |_e| { } //~ ERROR should return `bool`
13+
for baz |_e| { } //~ ERROR A `for` loop iterator should expect a closure that returns `bool`
1414
}

0 commit comments

Comments
 (0)