From dc21daeeb88c20b6431e70fe4ef5cc416af8410d Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Tue, 30 Apr 2013 16:34:22 -0400 Subject: [PATCH] borrowck: fix critical bug prevent us from ever using write guards :) --- src/librustc/middle/borrowck/check_loans.rs | 3 +++ .../middle/borrowck/gather_loans/lifetime.rs | 1 + .../middle/borrowck/gather_loans/mod.rs | 4 ++-- src/test/run-pass/too-much-recursion.rs | 22 ------------------- 4 files changed, 6 insertions(+), 24 deletions(-) delete mode 100644 src/test/run-pass/too-much-recursion.rs diff --git a/src/librustc/middle/borrowck/check_loans.rs b/src/librustc/middle/borrowck/check_loans.rs index 9330395c061..70da9c93805 100644 --- a/src/librustc/middle/borrowck/check_loans.rs +++ b/src/librustc/middle/borrowck/check_loans.rs @@ -357,6 +357,8 @@ fn check_for_aliasable_mutable_writes(self: &CheckLoanCtxt, //! Safety checks related to writes to aliasable, mutable locations let guarantor = cmt.guarantor(); + debug!("check_for_aliasable_mutable_writes(cmt=%s, guarantor=%s)", + cmt.repr(self.tcx()), guarantor.repr(self.tcx())); match guarantor.cat { mc::cat_deref(b, _, mc::region_ptr(m_mutbl, _)) => { // Statically prohibit writes to `&mut` when aliasable @@ -379,6 +381,7 @@ fn check_for_aliasable_mutable_writes(self: &CheckLoanCtxt, id: base.id, derefs: deref_count }; + debug!("Inserting write guard at %?", key); self.bccx.write_guard_map.insert(key); } diff --git a/src/librustc/middle/borrowck/gather_loans/lifetime.rs b/src/librustc/middle/borrowck/gather_loans/lifetime.rs index 4d267b7dc47..fdfb26c0d08 100644 --- a/src/librustc/middle/borrowck/gather_loans/lifetime.rs +++ b/src/librustc/middle/borrowck/gather_loans/lifetime.rs @@ -90,6 +90,7 @@ fn check(&self, cmt: mc::cmt, discr_scope: Option) { // See rule Freeze-Imm-Managed-Ptr-2 in doc.rs let omit_root = ( + ptr_mutbl == m_imm && self.bccx.is_subregion_of(self.loan_region, base_scope) && base.mutbl.is_immutable() && !self.is_moved(base) diff --git a/src/librustc/middle/borrowck/gather_loans/mod.rs b/src/librustc/middle/borrowck/gather_loans/mod.rs index 1bc3b70ac38..8a986a22d4c 100644 --- a/src/librustc/middle/borrowck/gather_loans/mod.rs +++ b/src/librustc/middle/borrowck/gather_loans/mod.rs @@ -148,7 +148,7 @@ fn gather_loans_in_expr(ex: @ast::expr, // If this expression is borrowed, have to ensure it remains valid: { - let mut this = &mut *self; // FIXME(#5074) + let this = &mut *self; // FIXME(#5074) if !this.ignore_adjustments.contains(&ex.id) { for tcx.adjustments.find(&ex.id).each |&adjustments| { this.guarantee_adjustments(ex, *adjustments); @@ -283,7 +283,7 @@ fn guarantee_adjustments(&mut self, let mcx = &mc::mem_categorization_ctxt { tcx: self.tcx(), method_map: self.bccx.method_map}; - let mut cmt = mcx.cat_expr_autoderefd(expr, autoderefs); + let cmt = mcx.cat_expr_autoderefd(expr, autoderefs); debug!("after autoderef, cmt=%s", cmt.repr(self.tcx())); match *autoref { diff --git a/src/test/run-pass/too-much-recursion.rs b/src/test/run-pass/too-much-recursion.rs deleted file mode 100644 index adccc786926..00000000000 --- a/src/test/run-pass/too-much-recursion.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// xfail-win32 -// error-pattern:ran out of stack - -// Test that the task fails after hitting the recursion limit, but -// that it doesn't bring down the whole proc - -pub fn main() { - do task::spawn_unlinked { - fn f() { f() }; - f(); - }; -} -- GitLab