Skip to content

Commit 95528d0

Browse files
committed
---
yaml --- r: 128759 b: refs/heads/try c: 9d55421 h: refs/heads/master i: 128757: a318fec 128755: c957f3d 128751: 86f0a95 v: v3
1 parent ac3505a commit 95528d0

File tree

17 files changed

+109
-73
lines changed

17 files changed

+109
-73
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 07d86b46a949a94223da714e35b343243e4ecce4
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a86d9ad15e339ab343a12513f9c90556f677b9ca
5-
refs/heads/try: 3fe0ba9afc7504ec01a778d8d72bd0b72fd013e1
5+
refs/heads/try: 9d554212de0398ac044e6d815da3bfb184831e77
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/librustc/middle/borrowck/gather_loans/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ impl<'a> GatherLoanCtxt<'a> {
261261
self.bccx, borrow_span, cause,
262262
cmt.clone(), loan_region);
263263

264+
debug!("guarantee_valid(): restrictions={:?}", restr);
265+
264266
// Create the loan record (if needed).
265267
let loan = match restr {
266268
restrictions::Safe => {

branches/try/src/librustc/middle/borrowck/gather_loans/restrictions.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ impl<'a> RestrictionsContext<'a> {
122122
}
123123

124124
mc::cat_deref(cmt_base, _, mc::BorrowedPtr(ty::ImmBorrow, lt)) |
125-
mc::cat_deref(cmt_base, _, mc::BorrowedPtr(ty::UniqueImmBorrow, lt)) |
126-
mc::cat_deref(cmt_base, _, mc::Implicit(ty::ImmBorrow, lt)) |
127-
mc::cat_deref(cmt_base, _, mc::Implicit(ty::UniqueImmBorrow, lt)) => {
125+
mc::cat_deref(cmt_base, _, mc::Implicit(ty::ImmBorrow, lt)) => {
128126
// R-Deref-Imm-Borrowed
129127
if !self.bccx.is_subregion_of(self.loan_region, lt) {
130128
self.bccx.report(
@@ -142,7 +140,9 @@ impl<'a> RestrictionsContext<'a> {
142140
mc::cat_deref(cmt_base, _, pk) => {
143141
match pk {
144142
mc::BorrowedPtr(ty::MutBorrow, lt) |
145-
mc::Implicit(ty::MutBorrow, lt) => {
143+
mc::BorrowedPtr(ty::UniqueImmBorrow, lt) |
144+
mc::Implicit(ty::MutBorrow, lt) |
145+
mc::Implicit(ty::UniqueImmBorrow, lt) => {
146146
// R-Deref-Mut-Borrowed
147147
if !self.bccx.is_subregion_of(self.loan_region, lt) {
148148
self.bccx.report(

branches/try/src/librustc/middle/expr_use_visitor.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,16 @@ impl<'d,'t,TYPER:mc::Typer> ExprUseVisitor<'d,'t,TYPER> {
399399
ast::ExprForLoop(ref pat, ref head, ref blk, _) => {
400400
// The pattern lives as long as the block.
401401
debug!("walk_expr for loop case: blk id={}", blk.id);
402-
self.walk_expr(&**head);
402+
self.consume_expr(&**head);
403403

404-
let head_cmt = return_if_err!(self.mc.cat_expr(&**head));
405-
self.walk_pat(head_cmt, pat.clone());
404+
// Fetch the type of the value that the iteration yields to
405+
// produce the pattern's categorized mutable type.
406+
let pattern_type = ty::node_id_to_type(self.tcx(), pat.id);
407+
let pat_cmt = self.mc.cat_rvalue(pat.id,
408+
pat.span,
409+
ty::ReScope(blk.id),
410+
pattern_type);
411+
self.walk_pat(pat_cmt, pat.clone());
406412

407413
self.walk_block(&**blk);
408414
}
@@ -835,6 +841,7 @@ impl<'d,'t,TYPER:mc::Typer> ExprUseVisitor<'d,'t,TYPER> {
835841
}
836842
ast::PatIdent(ast::BindByValue(_), _, _) => {
837843
let mode = copy_or_move(typer.tcx(), cmt_pat.ty, PatBindingMove);
844+
debug!("walk_pat binding consuming pat");
838845
delegate.consume_pat(pat, cmt_pat, mode);
839846
}
840847
_ => {

branches/try/src/librustc/middle/trans/base.rs

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,8 +1343,7 @@ pub fn new_fn_ctxt<'a>(ccx: &'a CrateContext,
13431343
output_type: ty::t,
13441344
param_substs: &'a param_substs,
13451345
sp: Option<Span>,
1346-
block_arena: &'a TypedArena<Block<'a>>,
1347-
handle_items: HandleItemsFlag)
1346+
block_arena: &'a TypedArena<Block<'a>>)
13481347
-> FunctionContext<'a> {
13491348
param_substs.validate();
13501349

@@ -1379,8 +1378,7 @@ pub fn new_fn_ctxt<'a>(ccx: &'a CrateContext,
13791378
block_arena: block_arena,
13801379
ccx: ccx,
13811380
debug_context: debug_context,
1382-
scopes: RefCell::new(Vec::new()),
1383-
handle_items: handle_items,
1381+
scopes: RefCell::new(Vec::new())
13841382
};
13851383

13861384
if has_env {
@@ -1708,8 +1706,7 @@ pub fn trans_closure(ccx: &CrateContext,
17081706
abi: Abi,
17091707
has_env: bool,
17101708
is_unboxed_closure: IsUnboxedClosureFlag,
1711-
maybe_load_env: <'a> |&'a Block<'a>| -> &'a Block<'a>,
1712-
handle_items: HandleItemsFlag) {
1709+
maybe_load_env: <'a> |&'a Block<'a>| -> &'a Block<'a>) {
17131710
ccx.stats.n_closures.set(ccx.stats.n_closures.get() + 1);
17141711

17151712
let _icx = push_ctxt("trans_closure");
@@ -1726,8 +1723,7 @@ pub fn trans_closure(ccx: &CrateContext,
17261723
output_type,
17271724
param_substs,
17281725
Some(body.span),
1729-
&arena,
1730-
handle_items);
1726+
&arena);
17311727
let mut bcx = init_function(&fcx, false, output_type);
17321728

17331729
// cleanup scope for the incoming arguments
@@ -1836,8 +1832,7 @@ pub fn trans_fn(ccx: &CrateContext,
18361832
llfndecl: ValueRef,
18371833
param_substs: &param_substs,
18381834
id: ast::NodeId,
1839-
attrs: &[ast::Attribute],
1840-
handle_items: HandleItemsFlag) {
1835+
attrs: &[ast::Attribute]) {
18411836
let _s = StatRecorder::new(ccx, ccx.tcx.map.path_to_string(id).to_string());
18421837
debug!("trans_fn(param_substs={})", param_substs.repr(ccx.tcx()));
18431838
let _icx = push_ctxt("trans_fn");
@@ -1857,8 +1852,7 @@ pub fn trans_fn(ccx: &CrateContext,
18571852
abi,
18581853
false,
18591854
NotUnboxedClosure,
1860-
|bcx| bcx,
1861-
handle_items);
1855+
|bcx| bcx);
18621856
}
18631857

18641858
pub fn trans_enum_variant(ccx: &CrateContext,
@@ -1964,7 +1958,7 @@ fn trans_enum_variant_or_tuple_like_struct(ccx: &CrateContext,
19641958

19651959
let arena = TypedArena::new();
19661960
let fcx = new_fn_ctxt(ccx, llfndecl, ctor_id, false, result_ty,
1967-
param_substs, None, &arena, TranslateItems);
1961+
param_substs, None, &arena);
19681962
let bcx = init_function(&fcx, false, result_ty);
19691963

19701964
assert!(!fcx.needs_ret_allocas);
@@ -2066,24 +2060,22 @@ pub fn trans_item(ccx: &CrateContext, item: &ast::Item) {
20662060
llfn,
20672061
&param_substs::empty(),
20682062
item.id,
2069-
None,
2070-
TranslateItems);
2063+
None);
20712064
} else {
20722065
trans_fn(ccx,
20732066
&**decl,
20742067
&**body,
20752068
llfn,
20762069
&param_substs::empty(),
20772070
item.id,
2078-
item.attrs.as_slice(),
2079-
TranslateItems);
2071+
item.attrs.as_slice());
20802072
}
2081-
} else {
2082-
// Be sure to travel more than just one layer deep to catch nested
2083-
// items in blocks and such.
2084-
let mut v = TransItemVisitor{ ccx: ccx };
2085-
v.visit_block(&**body, ());
20862073
}
2074+
2075+
// Be sure to travel more than just one layer deep to catch nested
2076+
// items in blocks and such.
2077+
let mut v = TransItemVisitor{ ccx: ccx };
2078+
v.visit_block(&**body, ());
20872079
}
20882080
ast::ItemImpl(ref generics, _, _, ref ms) => {
20892081
meth::trans_impl(ccx, item.ident, ms.as_slice(), generics, item.id);

branches/try/src/librustc/middle/trans/callee.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,7 @@ pub fn trans_unboxing_shim(bcx: &Block,
339339
return_type,
340340
&empty_param_substs,
341341
None,
342-
&block_arena,
343-
TranslateItems);
342+
&block_arena);
344343
let mut bcx = init_function(&fcx, false, return_type);
345344

346345
// Create the substituted versions of the self type.

branches/try/src/librustc/middle/trans/closure.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,7 @@ pub fn trans_expr_fn<'a>(
394394
ty::ty_fn_abi(fty),
395395
true,
396396
NotUnboxedClosure,
397-
|bcx| load_environment(bcx, cdata_ty, &freevars, store),
398-
bcx.fcx.handle_items);
397+
|bcx| load_environment(bcx, cdata_ty, &freevars, store));
399398
fill_fn_pair(bcx, dest_addr, llfn, llbox);
400399
bcx
401400
}
@@ -487,8 +486,7 @@ pub fn trans_unboxed_closure<'a>(
487486
ty::ty_fn_abi(function_type),
488487
true,
489488
IsUnboxedClosure,
490-
|bcx| load_unboxed_closure_environment(bcx, freevars_ptr),
491-
bcx.fcx.handle_items);
489+
|bcx| load_unboxed_closure_environment(bcx, freevars_ptr));
492490

493491
// Don't hoist this to the top of the function. It's perfectly legitimate
494492
// to have a zero-size unboxed closure (in which case dest will be
@@ -575,7 +573,7 @@ pub fn get_wrapper_for_bare_fn(ccx: &CrateContext,
575573
let arena = TypedArena::new();
576574
let empty_param_substs = param_substs::empty();
577575
let fcx = new_fn_ctxt(ccx, llfn, ast::DUMMY_NODE_ID, true, f.sig.output,
578-
&empty_param_substs, None, &arena, TranslateItems);
576+
&empty_param_substs, None, &arena);
579577
let bcx = init_function(&fcx, true, f.sig.output);
580578

581579
let args = create_datums_for_fn_args(&fcx,

branches/try/src/librustc/middle/trans/common.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,6 @@ impl<T:Subst+Clone> SubstP for T {
224224
pub type RvalueDatum = datum::Datum<datum::Rvalue>;
225225
pub type LvalueDatum = datum::Datum<datum::Lvalue>;
226226

227-
#[deriving(Clone, Eq, PartialEq)]
228-
pub enum HandleItemsFlag {
229-
IgnoreItems,
230-
TranslateItems,
231-
}
232-
233227
// Function context. Every LLVM function we create will have one of
234228
// these.
235229
pub struct FunctionContext<'a> {
@@ -303,9 +297,6 @@ pub struct FunctionContext<'a> {
303297

304298
// Cleanup scopes.
305299
pub scopes: RefCell<Vec<cleanup::CleanupScope<'a>> >,
306-
307-
// How to handle items encountered during translation of this function.
308-
pub handle_items: HandleItemsFlag,
309300
}
310301

311302
impl<'a> FunctionContext<'a> {

branches/try/src/librustc/middle/trans/controlflow.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,8 @@ pub fn trans_stmt<'a>(cx: &'a Block<'a>,
6969
debuginfo::create_local_var_metadata(bcx, &**local);
7070
}
7171
}
72-
ast::DeclItem(ref i) => {
73-
match fcx.handle_items {
74-
TranslateItems => trans_item(cx.fcx.ccx, &**i),
75-
IgnoreItems => {}
76-
}
77-
}
72+
// Inner items are visited by `trans_item`/`trans_meth`.
73+
ast::DeclItem(_) => {},
7874
}
7975
}
8076
ast::StmtMac(..) => cx.tcx().sess.bug("unexpanded macro")

branches/try/src/librustc/middle/trans/foreign.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,7 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext,
577577
llwrapfn: ValueRef,
578578
param_substs: &param_substs,
579579
id: ast::NodeId,
580-
hash: Option<&str>,
581-
handle_items: HandleItemsFlag) {
580+
hash: Option<&str>) {
582581
let _icx = push_ctxt("foreign::build_foreign_fn");
583582

584583
let fnty = ty::node_id_to_type(ccx.tcx(), id);
@@ -587,8 +586,7 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext,
587586

588587
unsafe { // unsafe because we call LLVM operations
589588
// Build up the Rust function (`foo0` above).
590-
let llrustfn = build_rust_fn(ccx, decl, body, param_substs, attrs, id,
591-
hash, handle_items);
589+
let llrustfn = build_rust_fn(ccx, decl, body, param_substs, attrs, id, hash);
592590

593591
// Build up the foreign wrapper (`foo` above).
594592
return build_wrap_fn(ccx, llrustfn, llwrapfn, &tys, mty);
@@ -600,8 +598,7 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext,
600598
param_substs: &param_substs,
601599
attrs: &[ast::Attribute],
602600
id: ast::NodeId,
603-
hash: Option<&str>,
604-
handle_items: HandleItemsFlag)
601+
hash: Option<&str>)
605602
-> ValueRef {
606603
let _icx = push_ctxt("foreign::foreign::build_rust_fn");
607604
let tcx = ccx.tcx();
@@ -633,7 +630,7 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: &CrateContext,
633630

634631
let llfn = base::decl_internal_rust_fn(ccx, t, ps.as_slice());
635632
base::set_llvm_fn_attrs(attrs, llfn);
636-
base::trans_fn(ccx, decl, body, llfn, param_substs, id, [], handle_items);
633+
base::trans_fn(ccx, decl, body, llfn, param_substs, id, []);
637634
llfn
638635
}
639636

branches/try/src/librustc/middle/trans/glue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ fn make_generic_glue(ccx: &CrateContext,
468468
let arena = TypedArena::new();
469469
let empty_param_substs = param_substs::empty();
470470
let fcx = new_fn_ctxt(ccx, llfn, ast::DUMMY_NODE_ID, false, ty::mk_nil(),
471-
&empty_param_substs, None, &arena, TranslateItems);
471+
&empty_param_substs, None, &arena);
472472

473473
let bcx = init_function(&fcx, false, ty::mk_nil());
474474

branches/try/src/librustc/middle/trans/inline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub fn maybe_instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
133133
if unparameterized {
134134
let llfn = get_item_val(ccx, mth.id);
135135
trans_fn(ccx, &*mth.pe_fn_decl(), &*mth.pe_body(), llfn,
136-
&param_substs::empty(), mth.id, [], TranslateItems);
136+
&param_substs::empty(), mth.id, []);
137137
}
138138
local_def(mth.id)
139139
}

branches/try/src/librustc/middle/trans/meth.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,10 @@ pub fn trans_impl(ccx: &CrateContext,
7575
llfn,
7676
&param_substs::empty(),
7777
method.id,
78-
[],
79-
TranslateItems);
80-
} else {
81-
let mut v = TransItemVisitor{ ccx: ccx };
82-
visit::walk_method_helper(&mut v, &**method, ());
78+
[]);
8379
}
80+
let mut v = TransItemVisitor{ ccx: ccx };
81+
visit::walk_method_helper(&mut v, &**method, ());
8482
}
8583
}
8684

branches/try/src/librustc/middle/trans/monomorphize.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,9 @@ pub fn monomorphic_fn(ccx: &CrateContext,
164164
if abi != abi::Rust {
165165
foreign::trans_rust_fn_with_foreign_abi(
166166
ccx, &**decl, &**body, [], d, &psubsts, fn_id.node,
167-
Some(hash.as_slice()), IgnoreItems);
167+
Some(hash.as_slice()));
168168
} else {
169-
trans_fn(ccx, &**decl, &**body, d, &psubsts, fn_id.node, [],
170-
IgnoreItems);
169+
trans_fn(ccx, &**decl, &**body, d, &psubsts, fn_id.node, []);
171170
}
172171

173172
d
@@ -201,8 +200,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
201200
ast_map::NodeMethod(mth) => {
202201
let d = mk_lldecl(abi::Rust);
203202
set_llvm_fn_attrs(mth.attrs.as_slice(), d);
204-
trans_fn(ccx, &*mth.pe_fn_decl(), &*mth.pe_body(), d, &psubsts, mth.id, [],
205-
IgnoreItems);
203+
trans_fn(ccx, &*mth.pe_fn_decl(), &*mth.pe_body(), d, &psubsts, mth.id, []);
206204
d
207205
}
208206
ast_map::NodeTraitMethod(method) => {
@@ -211,7 +209,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
211209
let d = mk_lldecl(abi::Rust);
212210
set_llvm_fn_attrs(mth.attrs.as_slice(), d);
213211
trans_fn(ccx, &*mth.pe_fn_decl(), &*mth.pe_body(), d,
214-
&psubsts, mth.id, [], IgnoreItems);
212+
&psubsts, mth.id, []);
215213
d
216214
}
217215
_ => {

branches/try/src/librustc/middle/trans/reflect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ impl<'a, 'b> Reflector<'a, 'b> {
312312
let empty_param_substs = param_substs::empty();
313313
let fcx = new_fn_ctxt(ccx, llfdecl, ast::DUMMY_NODE_ID, false,
314314
ty::mk_u64(), &empty_param_substs,
315-
None, &arena, TranslateItems);
315+
None, &arena);
316316
let bcx = init_function(&fcx, false, ty::mk_u64());
317317

318318
// we know the return type of llfdecl is an int here, so
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
struct Foo {
12+
x: int,
13+
}
14+
15+
pub fn main() {
16+
let mut this = &mut Foo {
17+
x: 1,
18+
};
19+
let r = || {
20+
let p = &this.x;
21+
&mut this.x; //~ ERROR cannot borrow
22+
};
23+
r()
24+
}
25+

0 commit comments

Comments
 (0)