diff --git a/src/libcore/at_vec.rs b/src/libcore/at_vec.rs index 6d4a5849e3522..b6bc9ae9e454c 100644 --- a/src/libcore/at_vec.rs +++ b/src/libcore/at_vec.rs @@ -135,12 +135,22 @@ pub pure fn from_elem(n_elts: uint, t: T) -> @[T] { #[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 647f2f052cacc..70f50d82b120d 100644 --- a/src/libcore/dvec.rs +++ b/src/libcore/dvec.rs @@ -352,10 +352,19 @@ impl DVec { } } +#[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 87c165266f82d..881172fc43427 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -28,11 +28,19 @@ pub trait Drop { fn finalize(); // 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; @@ -83,8 +91,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 2d8d1cd9fd868..5e060ee13116c 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -2174,12 +2174,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 087ce42b28a5d..e24e231a6e9d4 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -1495,19 +1495,37 @@ impl @[T] : Ord { #[cfg(notest)] 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(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)) + } + } } #[cfg(test)] diff --git a/src/librustc/middle/borrowck/gather_loans.rs b/src/librustc/middle/borrowck/gather_loans.rs index 12e8c2b133d89..778c7787f9a19 100644 --- a/src/librustc/middle/borrowck/gather_loans.rs +++ b/src/librustc/middle/borrowck/gather_loans.rs @@ -10,6 +10,8 @@ use mem_categorization::{mem_categorization_ctxt, opt_deref_kind}; 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: @@ -43,14 +45,16 @@ export gather_loans; 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()}); @@ -94,8 +98,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: @@ -137,7 +143,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. // @@ -151,6 +158,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 3c1fc9ee6cea4..ca6a94349b72e 100644 --- a/src/libstd/bitv.rs +++ b/src/libstd/bitv.rs @@ -555,11 +555,19 @@ pure fn land(w0: uint, w1: uint) -> uint { return w0 & w1; } 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 905b7f318e060..208c5876f2120 100644 --- a/src/libstd/ebml.rs +++ b/src/libstd/ebml.rs @@ -47,6 +47,7 @@ pub mod Reader { // ebml reading + #[cfg(stage0)] impl Doc: ops::Index { pure fn index(tag: uint) -> Doc { unsafe { @@ -54,6 +55,15 @@ pub mod Reader { } } } + #[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 d68970679ad99..25dba92e5f687 100644 --- a/src/libstd/map.rs +++ b/src/libstd/map.rs @@ -417,6 +417,7 @@ pub mod chained { } } + #[cfg(stage0)] impl T: ops::Index { pure fn index(k: K) -> V { unsafe { @@ -424,6 +425,15 @@ pub mod chained { } } } + #[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 3f9d308584d45..a3ddfd6e2fc01 100644 --- a/src/libstd/smallintmap.rs +++ b/src/libstd/smallintmap.rs @@ -141,6 +141,7 @@ impl SmallIntMap: map::Map { } } +#[cfg(stage0)] impl SmallIntMap: ops::Index { pure fn index(key: uint) -> V { unsafe { @@ -148,6 +149,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 {