Skip to content

Commit c4f0980

Browse files
committed
auto merge of #13990 : nikomatsakis/rust/issue-5527-cleanup-writeback, r=pcwalton
As part of #5527 I had to make some changes here and I just couldn't take it anymore. Refactor the writeback code. Should be functionally equivalent to the old stuff. r? @pcwalton
2 parents d8781b3 + 683d664 commit c4f0980

File tree

5 files changed

+416
-298
lines changed

5 files changed

+416
-298
lines changed

src/librustc/middle/ty_fold.rs

+17
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ pub trait TypeFolder {
7171
fn fold_trait_store(&mut self, s: ty::TraitStore) -> ty::TraitStore {
7272
super_fold_trait_store(self, s)
7373
}
74+
75+
fn fold_autoref(&mut self, ar: &ty::AutoRef) -> ty::AutoRef {
76+
super_fold_autoref(self, ar)
77+
}
7478
}
7579

7680
pub fn fold_opt_ty<T:TypeFolder>(this: &mut T,
@@ -200,6 +204,19 @@ pub fn super_fold_trait_store<T:TypeFolder>(this: &mut T,
200204
}
201205
}
202206

207+
pub fn super_fold_autoref<T:TypeFolder>(this: &mut T,
208+
autoref: &ty::AutoRef)
209+
-> ty::AutoRef
210+
{
211+
match *autoref {
212+
ty::AutoPtr(r, m) => ty::AutoPtr(this.fold_region(r), m),
213+
ty::AutoBorrowVec(r, m) => ty::AutoBorrowVec(this.fold_region(r), m),
214+
ty::AutoBorrowVecRef(r, m) => ty::AutoBorrowVecRef(this.fold_region(r), m),
215+
ty::AutoUnsafe(m) => ty::AutoUnsafe(m),
216+
ty::AutoBorrowObj(r, m) => ty::AutoBorrowObj(this.fold_region(r), m),
217+
}
218+
}
219+
203220
///////////////////////////////////////////////////////////////////////////
204221
// Some sample folders
205222

src/librustc/middle/typeck/check/mod.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ enum IsBinopAssignment{
221221

222222
#[deriving(Clone)]
223223
pub struct FnCtxt<'a> {
224+
// This flag is set to true if, during the writeback phase, we encounter
225+
// a type error in this function.
226+
writeback_errors: Cell<bool>,
227+
224228
// Number of errors that had been reported when we started
225229
// checking this function. On exit, if we find that *more* errors
226230
// have been reported, we will skip regionck and other work that
@@ -280,6 +284,7 @@ fn blank_fn_ctxt<'a>(ccx: &'a CrateCtxt<'a>,
280284
region_bnd: ast::NodeId)
281285
-> FnCtxt<'a> {
282286
FnCtxt {
287+
writeback_errors: Cell::new(false),
283288
err_count_on_creation: ccx.tcx.sess.err_count(),
284289
ret_ty: rty,
285290
ps: RefCell::new(FnStyleState::function(ast::NormalFn, 0)),
@@ -469,6 +474,7 @@ fn check_fn<'a>(ccx: &'a CrateCtxt<'a>,
469474
// Create the function context. This is either derived from scratch or,
470475
// in the case of function expressions, based on the outer context.
471476
let fcx = FnCtxt {
477+
writeback_errors: Cell::new(false),
472478
err_count_on_creation: err_count_on_creation,
473479
ret_ty: ret_ty,
474480
ps: RefCell::new(FnStyleState::function(fn_style, id)),
@@ -1198,11 +1204,10 @@ impl<'a> FnCtxt<'a> {
11981204

11991205
pub fn opt_node_ty_substs(&self,
12001206
id: ast::NodeId,
1201-
f: |&ty::substs| -> bool)
1202-
-> bool {
1207+
f: |&ty::substs|) {
12031208
match self.inh.node_type_substs.borrow().find(&id) {
1204-
Some(s) => f(s),
1205-
None => true
1209+
Some(s) => { f(s) }
1210+
None => { }
12061211
}
12071212
}
12081213

src/librustc/middle/typeck/check/vtable.rs

-1
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,6 @@ pub fn early_resolve_expr(ex: &ast::Expr, fcx: &FnCtxt, is_early: bool) {
644644
insert_vtables(fcx, MethodCall::expr(ex.id), vtbls);
645645
}
646646
}
647-
true
648647
});
649648
}
650649

0 commit comments

Comments
 (0)