Skip to content

Refactor writeback code. cc #5527 #13990

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/librustc/middle/ty_fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ pub trait TypeFolder {
fn fold_trait_store(&mut self, s: ty::TraitStore) -> ty::TraitStore {
super_fold_trait_store(self, s)
}

fn fold_autoref(&mut self, ar: &ty::AutoRef) -> ty::AutoRef {
super_fold_autoref(self, ar)
}
}

pub fn fold_opt_ty<T:TypeFolder>(this: &mut T,
Expand Down Expand Up @@ -195,6 +199,19 @@ pub fn super_fold_trait_store<T:TypeFolder>(this: &mut T,
}
}

pub fn super_fold_autoref<T:TypeFolder>(this: &mut T,
autoref: &ty::AutoRef)
-> ty::AutoRef
{
match *autoref {
ty::AutoPtr(r, m) => ty::AutoPtr(this.fold_region(r), m),
ty::AutoBorrowVec(r, m) => ty::AutoBorrowVec(this.fold_region(r), m),
ty::AutoBorrowVecRef(r, m) => ty::AutoBorrowVecRef(this.fold_region(r), m),
ty::AutoUnsafe(m) => ty::AutoUnsafe(m),
ty::AutoBorrowObj(r, m) => ty::AutoBorrowObj(this.fold_region(r), m),
}
}

///////////////////////////////////////////////////////////////////////////
// Some sample folders

Expand Down
13 changes: 9 additions & 4 deletions src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ enum IsBinopAssignment{

#[deriving(Clone)]
pub struct FnCtxt<'a> {
// This flag is set to true if, during the writeback phase, we encounter
// a type error in this function.
writeback_errors: Cell<bool>,

// Number of errors that had been reported when we started
// checking this function. On exit, if we find that *more* errors
// have been reported, we will skip regionck and other work that
Expand Down Expand Up @@ -280,6 +284,7 @@ fn blank_fn_ctxt<'a>(ccx: &'a CrateCtxt<'a>,
region_bnd: ast::NodeId)
-> FnCtxt<'a> {
FnCtxt {
writeback_errors: Cell::new(false),
err_count_on_creation: ccx.tcx.sess.err_count(),
ret_ty: rty,
ps: RefCell::new(FnStyleState::function(ast::NormalFn, 0)),
Expand Down Expand Up @@ -469,6 +474,7 @@ fn check_fn<'a>(ccx: &'a CrateCtxt<'a>,
// Create the function context. This is either derived from scratch or,
// in the case of function expressions, based on the outer context.
let fcx = FnCtxt {
writeback_errors: Cell::new(false),
err_count_on_creation: err_count_on_creation,
ret_ty: ret_ty,
ps: RefCell::new(FnStyleState::function(fn_style, id)),
Expand Down Expand Up @@ -1198,11 +1204,10 @@ impl<'a> FnCtxt<'a> {

pub fn opt_node_ty_substs(&self,
id: ast::NodeId,
f: |&ty::substs| -> bool)
-> bool {
f: |&ty::substs|) {
match self.inh.node_type_substs.borrow().find(&id) {
Some(s) => f(s),
None => true
Some(s) => { f(s) }
None => { }
}
}

Expand Down
1 change: 0 additions & 1 deletion src/librustc/middle/typeck/check/vtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,6 @@ pub fn early_resolve_expr(ex: &ast::Expr, fcx: &FnCtxt, is_early: bool) {
insert_vtables(fcx, MethodCall::expr(ex.id), vtbls);
}
}
true
});
}

Expand Down
Loading