Skip to content

Commit bdd963f

Browse files
Cameron Zwarichalexcrichton
authored andcommitted
---
yaml --- r: 152663 b: refs/heads/try2 c: 90f7e3a h: refs/heads/master i: 152661: 99acdcc 152659: 312fd12 152655: 9e50540 v: v3
1 parent b50052c commit bdd963f

File tree

3 files changed

+50
-5
lines changed

3 files changed

+50
-5
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: f99349556014f9f2cb86814477248d46931b3048
8+
refs/heads/try2: 90f7e3a644c9795d9a7dce87d8c6b0cf369a7503
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/middle/borrowck/move_data.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use middle::dataflow::DataFlowContext;
2525
use middle::dataflow::BitwiseOperator;
2626
use middle::dataflow::DataFlowOperator;
2727
use euv = middle::expr_use_visitor;
28+
use mc = middle::mem_categorization;
2829
use middle::ty;
2930
use syntax::ast;
3031
use syntax::ast_util;
@@ -160,6 +161,22 @@ pub struct AssignDataFlowOperator;
160161

161162
pub type AssignDataFlow<'a> = DataFlowContext<'a, AssignDataFlowOperator>;
162163

164+
fn loan_path_is_precise(loan_path: &LoanPath) -> bool {
165+
match *loan_path {
166+
LpVar(_) => {
167+
true
168+
}
169+
LpExtend(_, _, LpInterior(mc::InteriorElement(_))) => {
170+
// Paths involving element accesses do not refer to a unique
171+
// location, as there is no accurate tracking of the indices.
172+
false
173+
}
174+
LpExtend(ref lp_base, _, _) => {
175+
loan_path_is_precise(&**lp_base)
176+
}
177+
}
178+
}
179+
163180
impl MoveData {
164181
pub fn new() -> MoveData {
165182
MoveData {
@@ -500,10 +517,17 @@ impl MoveData {
500517
path: MovePathIndex,
501518
kill_id: ast::NodeId,
502519
dfcx_moves: &mut MoveDataFlow) {
503-
self.each_applicable_move(path, |move_index| {
504-
dfcx_moves.add_kill(kill_id, move_index.get());
505-
true
506-
});
520+
// We can only perform kills for paths that refer to a unique location,
521+
// since otherwise we may kill a move from one location with an
522+
// assignment referring to another location.
523+
524+
let loan_path = self.path_loan_path(path);
525+
if loan_path_is_precise(&*loan_path) {
526+
self.each_applicable_move(path, |move_index| {
527+
dfcx_moves.add_kill(kill_id, move_index.get());
528+
true
529+
});
530+
}
507531
}
508532
}
509533

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn f() {
12+
let mut a = [box 0, box 1];
13+
drop(a[0]);
14+
a[1] = box 2;
15+
drop(a[0]); //~ ERROR use of moved value: `a[..]`
16+
}
17+
18+
fn main() {
19+
f();
20+
}
21+

0 commit comments

Comments
 (0)