diff --git a/src/libcore/at_vec.rs b/src/libcore/at_vec.rs index 49ba1d5aa907dbdafb52aee0cb398893354feb57..13429c902669e13adda4eb1b03f8bfbb6b67884c 100644 --- a/src/libcore/at_vec.rs +++ b/src/libcore/at_vec.rs @@ -145,12 +145,22 @@ fn vec_reserve_shared_actual(++t: *sys::TypeDesc, #[cfg(notest)] pub mod traits { + #[cfg(stage0)] pub impl @[T] : Add<&[const T],@[T]> { #[inline(always)] pure fn add(rhs: & &self/[const T]) -> @[T] { append(self, (*rhs)) } } + + #[cfg(stage1)] + #[cfg(stage2)] + pub impl @[T] : Add<&[const T],@[T]> { + #[inline(always)] + pure fn add(&self, rhs: & &self/[const T]) -> @[T] { + append(*self, (*rhs)) + } + } } #[cfg(test)] diff --git a/src/libcore/dvec.rs b/src/libcore/dvec.rs index 96fdc876c94e387c0484462453c385963abbbf0f..b3da5f1e98b5cd1afc53806ef2d17c19616b69d8 100644 --- a/src/libcore/dvec.rs +++ b/src/libcore/dvec.rs @@ -358,10 +358,19 @@ fn rev_eachi(f: fn(uint, v: &A) -> bool) { } } +#[cfg(stage0)] impl DVec: Index { #[inline(always)] pure fn index(idx: uint) -> A { self.get_elt(idx) } } +#[cfg(stage1)] +#[cfg(stage2)] +impl DVec: Index { + #[inline(always)] + pure fn index(&self, idx: uint) -> A { + self.get_elt(idx) + } +} diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 02827a7316594a16ce666ef2d6a26d591d1d82ab..71d4b297252f576086c469c309ec3046dc7267a5 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -18,11 +18,19 @@ pub trait Drop { fn finalize(&self); // XXX: Rename to "drop"? --pcwalton } +#[cfg(stage0)] #[lang="add"] pub trait Add { pure fn add(rhs: &RHS) -> Result; } +#[cfg(stage1)] +#[cfg(stage2)] +#[lang="add"] +pub trait Add { + pure fn add(&self, rhs: &RHS) -> Result; +} + #[lang="sub"] pub trait Sub { pure fn sub(&self, rhs: &RHS) -> Result; @@ -73,8 +81,16 @@ pub trait Shr { pure fn shr(&self, rhs: &RHS) -> Result; } +#[cfg(stage0)] #[lang="index"] pub trait Index { pure fn index(index: Index) -> Result; } +#[cfg(stage1)] +#[cfg(stage2)] +#[lang="index"] +pub trait Index { + pure fn index(&self, index: Index) -> Result; +} + diff --git a/src/libcore/str.rs b/src/libcore/str.rs index f4900d80a8e9558dd8c36c44f9891435f8dd2862..40a8f9afd678d2e6ddfa38f27296879faa0337af 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -2107,12 +2107,21 @@ impl ~str: Trimmable { #[cfg(notest)] pub mod traits { + #[cfg(stage0)] impl ~str : Add<&str,~str> { #[inline(always)] pure fn add(rhs: & &self/str) -> ~str { append(copy self, (*rhs)) } } + #[cfg(stage1)] + #[cfg(stage2)] + impl ~str : Add<&str,~str> { + #[inline(always)] + pure fn add(&self, rhs: & &self/str) -> ~str { + append(copy *self, (*rhs)) + } + } } #[cfg(test)] diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index ceb169c2e6e9c65185ece2be3a84b717baf8afa5..8b6cb2ade5e7a3ab1a28567564c68f350128149c 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -1438,18 +1438,37 @@ impl @[T] : Ord { } #[cfg(notest)] -impl ~[T] : Add<&[const T],~[T]> { - #[inline(always)] - pure fn add(rhs: & &self/[const T]) -> ~[T] { - append(copy self, (*rhs)) +pub mod traits { + #[cfg(stage0)] + impl ~[T] : Add<&[const T],~[T]> { + #[inline(always)] + pure fn add(rhs: & &self/[const T]) -> ~[T] { + append(copy self, (*rhs)) + } + } + #[cfg(stage1)] + #[cfg(stage2)] + impl ~[T] : Add<&[const T],~[T]> { + #[inline(always)] + pure fn add(&self, rhs: & &self/[const T]) -> ~[T] { + append(copy *self, (*rhs)) + } } -} -#[cfg(notest)] -impl ~[mut T] : Add<&[const T],~[mut T]> { - #[inline(always)] - pure fn add(rhs: & &self/[const T]) -> ~[mut T] { - append_mut(copy self, (*rhs)) + #[cfg(stage0)] + impl ~[mut T] : Add<&[const T],~[mut T]> { + #[inline(always)] + pure fn add(rhs: & &self/[const T]) -> ~[mut T] { + append_mut(copy self, (*rhs)) + } + } + #[cfg(stage1)] + #[cfg(stage2)] + impl ~[mut T] : Add<&[const T],~[mut T]> { + #[inline(always)] + pure fn add(&self, rhs: & &self/[const T]) -> ~[mut T] { + append_mut(copy *self, (*rhs)) + } } } diff --git a/src/librustc/middle/borrowck/gather_loans.rs b/src/librustc/middle/borrowck/gather_loans.rs index 3320414ee0fa6a913998043dd833f0daacafd339..d573bf15d38fb56c932659a238901519dd4eeaa1 100644 --- a/src/librustc/middle/borrowck/gather_loans.rs +++ b/src/librustc/middle/borrowck/gather_loans.rs @@ -20,6 +20,8 @@ use preserve::{preserve_condition, pc_ok, pc_if_pure}; use ty::{ty_region}; +use core::send_map::linear::LinearMap; + export gather_loans; /// Context used while gathering loans: @@ -53,14 +55,16 @@ enum gather_loan_ctxt = @{bccx: borrowck_ctxt, req_maps: req_maps, mut item_ub: ast::node_id, - mut root_ub: ast::node_id}; + mut root_ub: ast::node_id, + mut ignore_adjustments: LinearMap}; fn gather_loans(bccx: borrowck_ctxt, crate: @ast::crate) -> req_maps { let glcx = gather_loan_ctxt(@{bccx: bccx, req_maps: {req_loan_map: HashMap(), pure_map: HashMap()}, mut item_ub: 0, - mut root_ub: 0}); + mut root_ub: 0, + mut ignore_adjustments: LinearMap()}); let v = visit::mk_vt(@{visit_expr: req_loans_in_expr, visit_fn: req_loans_in_fn, .. *visit::default_visitor()}); @@ -104,8 +108,10 @@ fn req_loans_in_expr(ex: @ast::expr, ex.id, pprust::expr_to_str(ex, tcx.sess.intr())); // If this expression is borrowed, have to ensure it remains valid: - for tcx.adjustments.find(ex.id).each |adjustments| { - self.guarantee_adjustments(ex, *adjustments); + if !self.ignore_adjustments.contains_key(&ex.id) { + for tcx.adjustments.find(ex.id).each |adjustments| { + self.guarantee_adjustments(ex, *adjustments); + } } // Special checks for various kinds of expressions: @@ -179,7 +185,8 @@ fn req_loans_in_expr(ex: @ast::expr, ast::expr_index(rcvr, _) | ast::expr_binary(_, rcvr, _) | - ast::expr_unary(_, rcvr) + ast::expr_unary(_, rcvr) | + ast::expr_assign_op(_, rcvr, _) if self.bccx.method_map.contains_key(ex.id) => { // Receivers in method calls are always passed by ref. // @@ -193,6 +200,11 @@ fn req_loans_in_expr(ex: @ast::expr, let scope_r = ty::re_scope(ex.id); let rcvr_cmt = self.bccx.cat_expr(rcvr); self.guarantee_valid(rcvr_cmt, m_imm, scope_r); + + // FIXME (#3387): Total hack: Ignore adjustments for the left-hand + // side. Their regions will be inferred to be too large. + self.ignore_adjustments.insert(rcvr.id, ()); + visit::visit_expr(ex, self, vt); } diff --git a/src/libstd/bitv.rs b/src/libstd/bitv.rs index e9ff56df30d67fc20c3e43d22c35d6b845d41fa1..72f21a687daa992cd857f892f3fb5aae80432238 100644 --- a/src/libstd/bitv.rs +++ b/src/libstd/bitv.rs @@ -565,11 +565,19 @@ pub fn from_fn(len: uint, f: fn(index: uint) -> bool) -> Bitv { pure fn right(_w0: uint, w1: uint) -> uint { return w1; } +#[cfg(stage0)] impl Bitv: ops::Index { pure fn index(i: uint) -> bool { self.get(i) } } +#[cfg(stage1)] +#[cfg(stage2)] +impl Bitv: ops::Index { + pure fn index(&self, i: uint) -> bool { + self.get(i) + } +} #[cfg(test)] mod tests { diff --git a/src/libstd/ebml.rs b/src/libstd/ebml.rs index 1bfba2c7b0ca13bfd3818620643b439b883d29f5..3b65f913755232e802987150ce8f7e45b788c193 100644 --- a/src/libstd/ebml.rs +++ b/src/libstd/ebml.rs @@ -57,6 +57,7 @@ pub mod Reader { // ebml reading + #[cfg(stage0)] impl Doc: ops::Index { pure fn index(tag: uint) -> Doc { unsafe { @@ -64,6 +65,15 @@ impl Doc: ops::Index { } } } + #[cfg(stage1)] + #[cfg(stage2)] + impl Doc: ops::Index { + pure fn index(&self, tag: uint) -> Doc { + unsafe { + get_doc(*self, tag) + } + } + } fn vuint_at(data: &[u8], start: uint) -> {val: uint, next: uint} { let a = data[start]; diff --git a/src/libstd/map.rs b/src/libstd/map.rs index 05a8e37d9afa574c6c02c3993cbf7b048ab46746..add1976539c57a1eade7aec9c8c934d4d901a96b 100644 --- a/src/libstd/map.rs +++ b/src/libstd/map.rs @@ -429,6 +429,7 @@ impl T: ToStr { } } + #[cfg(stage0)] impl T: ops::Index { pure fn index(k: K) -> V { unsafe { @@ -436,6 +437,15 @@ impl T: ops::Index { } } } + #[cfg(stage1)] + #[cfg(stage2)] + impl T: ops::Index { + pure fn index(&self, k: K) -> V { + unsafe { + self.get(k) + } + } + } fn chains(nchains: uint) -> ~[mut Option<@Entry>] { vec::to_mut(vec::from_elem(nchains, None)) diff --git a/src/libstd/smallintmap.rs b/src/libstd/smallintmap.rs index b83387a87bab04d0025177ebd599536ed03e4702..3e82c3c9419787e5a9f30251037223de8872f1bc 100644 --- a/src/libstd/smallintmap.rs +++ b/src/libstd/smallintmap.rs @@ -150,6 +150,7 @@ fn update(key: uint, newval: V, ff: fn(V, V) -> V) -> bool { } } +#[cfg(stage0)] impl SmallIntMap: ops::Index { pure fn index(key: uint) -> V { unsafe { @@ -157,6 +158,15 @@ impl SmallIntMap: ops::Index { } } } +#[cfg(stage1)] +#[cfg(stage2)] +impl SmallIntMap: ops::Index { + pure fn index(&self, key: uint) -> V { + unsafe { + get(*self, key) + } + } +} /// Cast the given smallintmap to a map::map pub fn as_map(s: SmallIntMap) -> map::Map {