Skip to content

Commit 9022afb

Browse files
committed
---
yaml --- r: 64377 b: refs/heads/snap-stage3 c: 040e470 h: refs/heads/master i: 64375: c8e08e3 v: v3
1 parent fa8a341 commit 9022afb

31 files changed

+818
-371
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 88a1b713059b50be51fa93f39165ae9d35d27cdd
4+
refs/heads/snap-stage3: 040e470f475944a355101aa89e9ec447c10b0caa
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libextra/smallintmap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ impl<V> SmallIntMap<V> {
161161
/// Visit all key-value pairs in reverse order
162162
pub fn each_reverse<'a>(&'a self, it: &fn(uint, &'a V) -> bool) -> bool {
163163
for uint::range_rev(self.v.len(), 0) |i| {
164-
match self.v[i - 1] {
165-
Some(ref elt) => if !it(i - 1, elt) { return false; },
164+
match self.v[i] {
165+
Some(ref elt) => if !it(i, elt) { return false; },
166166
None => ()
167167
}
168168
}

branches/snap-stage3/src/librustc/front/std_inject.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ pub fn maybe_inject_libstd_ref(sess: Session, crate: @ast::crate)
3232
fn use_std(crate: &ast::crate) -> bool {
3333
!attr::attrs_contains_name(crate.node.attrs, "no_std")
3434
}
35+
fn no_prelude(attrs: &[ast::attribute]) -> bool {
36+
attr::attrs_contains_name(attrs, "no_implicit_prelude")
37+
}
3538

3639
fn inject_libstd_ref(sess: Session, crate: &ast::crate) -> @ast::crate {
3740
fn spanned<T:Copy>(x: T) -> codemap::spanned<T> {
@@ -63,7 +66,12 @@ fn inject_libstd_ref(sess: Session, crate: &ast::crate) -> @ast::crate {
6366
view_items: vis,
6467
../*bad*/copy crate.module
6568
};
66-
new_module = fld.fold_mod(&new_module);
69+
70+
if !no_prelude(crate.attrs) {
71+
// only add `use std::prelude::*;` if there wasn't a
72+
// `#[no_implicit_prelude];` at the crate level.
73+
new_module = fld.fold_mod(&new_module);
74+
}
6775

6876
// FIXME #2543: Bad copy.
6977
let new_crate = ast::crate_ {
@@ -72,6 +80,16 @@ fn inject_libstd_ref(sess: Session, crate: &ast::crate) -> @ast::crate {
7280
};
7381
(new_crate, span)
7482
},
83+
fold_item: |item, fld| {
84+
if !no_prelude(item.attrs) {
85+
// only recur if there wasn't `#[no_implicit_prelude];`
86+
// on this item, i.e. this means that the prelude is not
87+
// implicitly imported though the whole subtree
88+
fold::noop_fold_item(item, fld)
89+
} else {
90+
Some(item)
91+
}
92+
},
7593
fold_mod: |module, fld| {
7694
let n2 = sess.next_node_id();
7795

branches/snap-stage3/src/librustc/middle/const_eval.rs

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,58 @@ pub fn classify(e: &expr,
165165
pub fn lookup_const(tcx: ty::ctxt, e: &expr) -> Option<@expr> {
166166
match tcx.def_map.find(&e.id) {
167167
Some(&ast::def_static(def_id, false)) => lookup_const_by_id(tcx, def_id),
168+
Some(&ast::def_variant(enum_def, variant_def)) => lookup_variant_by_id(tcx,
169+
enum_def,
170+
variant_def),
168171
_ => None
169172
}
170173
}
171174

175+
pub fn lookup_variant_by_id(tcx: ty::ctxt,
176+
enum_def: ast::def_id,
177+
variant_def: ast::def_id)
178+
-> Option<@expr> {
179+
fn variant_expr(variants: &[ast::variant], id: ast::node_id) -> Option<@expr> {
180+
for variants.iter().advance |variant| {
181+
if variant.node.id == id {
182+
return variant.node.disr_expr;
183+
}
184+
}
185+
None
186+
}
187+
188+
if ast_util::is_local(enum_def) {
189+
match tcx.items.find(&enum_def.node) {
190+
None => None,
191+
Some(&ast_map::node_item(it, _)) => match it.node {
192+
item_enum(ast::enum_def { variants: ref variants }, _) => {
193+
variant_expr(*variants, variant_def.node)
194+
}
195+
_ => None
196+
},
197+
Some(_) => None
198+
}
199+
} else {
200+
let maps = astencode::Maps {
201+
root_map: @mut HashMap::new(),
202+
method_map: @mut HashMap::new(),
203+
vtable_map: @mut HashMap::new(),
204+
write_guard_map: @mut HashSet::new(),
205+
capture_map: @mut HashMap::new()
206+
};
207+
match csearch::maybe_get_item_ast(tcx, enum_def,
208+
|a, b, c, d| astencode::decode_inlined_item(a, b, maps, /*bar*/ copy c, d)) {
209+
csearch::found(ast::ii_item(item)) => match item.node {
210+
item_enum(ast::enum_def { variants: ref variants }, _) => {
211+
variant_expr(*variants, variant_def.node)
212+
}
213+
_ => None
214+
},
215+
_ => None
216+
}
217+
}
218+
}
219+
172220
pub fn lookup_const_by_id(tcx: ty::ctxt,
173221
def_id: ast::def_id)
174222
-> Option<@expr> {
@@ -237,13 +285,13 @@ pub enum const_val {
237285
}
238286

239287
pub fn eval_const_expr(tcx: middle::ty::ctxt, e: &expr) -> const_val {
240-
match eval_const_expr_partial(tcx, e) {
288+
match eval_const_expr_partial(&tcx, e) {
241289
Ok(r) => r,
242290
Err(s) => tcx.sess.span_fatal(e.span, s)
243291
}
244292
}
245293

246-
pub fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: &expr)
294+
pub fn eval_const_expr_partial<T: ty::ExprTyProvider>(tcx: &T, e: &expr)
247295
-> Result<const_val, ~str> {
248296
use middle::ty;
249297
fn fromb(b: bool) -> Result<const_val, ~str> { Ok(const_int(b as i64)) }
@@ -360,7 +408,7 @@ pub fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: &expr)
360408
}
361409
}
362410
expr_cast(base, _) => {
363-
let ety = ty::expr_ty(tcx, e);
411+
let ety = tcx.expr_ty(e);
364412
let base = eval_const_expr_partial(tcx, base);
365413
match /*bad*/copy base {
366414
Err(_) => base,
@@ -390,8 +438,8 @@ pub fn eval_const_expr_partial(tcx: middle::ty::ctxt, e: &expr)
390438
}
391439
}
392440
expr_path(_) => {
393-
match lookup_const(tcx, e) {
394-
Some(actual_e) => eval_const_expr_partial(tcx, actual_e),
441+
match lookup_const(tcx.ty_ctxt(), e) {
442+
Some(actual_e) => eval_const_expr_partial(&tcx.ty_ctxt(), actual_e),
395443
None => Err(~"Non-constant path in constant expr")
396444
}
397445
}

branches/snap-stage3/src/librustc/middle/kind.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ fn check_item(item: @item, (cx, visitor): (Context, visit::vt<Context>)) {
122122
None => cx.tcx.sess.bug("trait ref not in def map!"),
123123
Some(&trait_def) => {
124124
let trait_def_id = ast_util::def_id_of_def(trait_def);
125-
if cx.tcx.lang_items.drop_trait() == Some(trait_def_id) {
125+
if cx.tcx.lang_items.drop_trait() == trait_def_id {
126126
// Yes, it's a destructor.
127127
match self_type.node {
128128
ty_path(_, ref bounds, path_node_id) => {
@@ -309,7 +309,7 @@ pub fn check_expr(e: @expr, (cx, v): (Context, visit::vt<Context>)) {
309309
"explicit copy requires a copyable argument");
310310
}
311311
expr_repeat(element, count_expr, _) => {
312-
let count = ty::eval_repeat_count(cx.tcx, count_expr);
312+
let count = ty::eval_repeat_count(&cx.tcx, count_expr);
313313
if count > 1 {
314314
let element_ty = ty::expr_ty(cx.tcx, element);
315315
check_copy(cx, element_ty, element.span,

0 commit comments

Comments
 (0)