Skip to content

Commit e7d9693

Browse files
committed
Correct mismatch between the way that pattern ids and expression ids map to types (pattern ids map to the input type, expression ids map to the output type)
1 parent 3402435 commit e7d9693

File tree

7 files changed

+131
-115
lines changed

7 files changed

+131
-115
lines changed

src/librustc/middle/borrowck/check_loans.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ pub impl<'self> CheckLoanCtxt<'self> {
378378
// Dynamically check writes to `@mut`
379379

380380
let key = root_map_key {
381-
id: base.id,
381+
id: guarantor.id,
382382
derefs: deref_count
383383
};
384384
debug!("Inserting write guard at %?", key);

src/librustc/middle/borrowck/gather_loans/lifetime.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl GuaranteeLifetimeContext {
9797
);
9898

9999
if !omit_root {
100-
self.check_root(base, derefs, ptr_mutbl, discr_scope);
100+
self.check_root(cmt, base, derefs, ptr_mutbl, discr_scope);
101101
} else {
102102
debug!("omitting root, base=%s, base_scope=%?",
103103
base.repr(self.tcx()), base_scope);
@@ -168,12 +168,14 @@ impl GuaranteeLifetimeContext {
168168
}
169169

170170
fn check_root(&self,
171+
cmt_deref: mc::cmt,
171172
cmt_base: mc::cmt,
172173
derefs: uint,
173174
ptr_mutbl: ast::mutability,
174175
discr_scope: Option<ast::node_id>) {
175-
debug!("check_root(cmt_base=%s, derefs=%? ptr_mutbl=%?, \
176+
debug!("check_root(cmt_deref=%s, cmt_base=%s, derefs=%?, ptr_mutbl=%?, \
176177
discr_scope=%?)",
178+
cmt_deref.repr(self.tcx()),
177179
cmt_base.repr(self.tcx()),
178180
derefs,
179181
ptr_mutbl,
@@ -234,7 +236,7 @@ impl GuaranteeLifetimeContext {
234236
};
235237

236238
// Add a record of what is required
237-
let rm_key = root_map_key {id: cmt_base.id, derefs: derefs};
239+
let rm_key = root_map_key {id: cmt_deref.id, derefs: derefs};
238240
let root_info = RootInfo {scope: root_scope, freeze: opt_dyna};
239241
self.bccx.root_map.insert(rm_key, root_info);
240242

src/librustc/middle/borrowck/mod.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,19 @@ pub struct BorrowStats {
172172

173173
pub type LoanMap = @mut HashMap<ast::node_id, @Loan>;
174174

175-
// the keys to the root map combine the `id` of the expression with
176-
// the number of types that it is autodereferenced. So, for example,
177-
// if you have an expression `x.f` and x has type ~@T, we could add an
178-
// entry {id:x, derefs:0} to refer to `x` itself, `{id:x, derefs:1}`
179-
// to refer to the deref of the unique pointer, and so on.
175+
// The keys to the root map combine the `id` of the deref expression
176+
// with the number of types that it is *autodereferenced*. So, for
177+
// example, imagine I have a variable `x: @@@T` and an expression
178+
// `(*x).f`. This will have 3 derefs, one explicit and then two
179+
// autoderefs. These are the relevant `root_map_key` values that could
180+
// appear:
181+
//
182+
// {id:*x, derefs:0} --> roots `x` (type: @@@T, due to explicit deref)
183+
// {id:*x, derefs:1} --> roots `*x` (type: @@T, due to autoderef #1)
184+
// {id:*x, derefs:2} --> roots `**x` (type: @T, due to autoderef #2)
185+
//
186+
// Note that there is no entry with derefs:3---the type of that expression
187+
// is T, which is not a box.
180188
#[deriving(Eq, IterBytes)]
181189
pub struct root_map_key {
182190
id: ast::node_id,

0 commit comments

Comments
 (0)