提交 c4f0980d 编写于 作者: B bors

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
......@@ -71,6 +71,10 @@ fn fold_region(&mut self, r: ty::Region) -> ty::Region {
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,
......@@ -200,6 +204,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
......
......@@ -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
......@@ -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)),
......@@ -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)),
......@@ -1198,11 +1204,10 @@ pub fn method_ty_substs(&self, id: ast::NodeId) -> ty::substs {
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 => { }
}
}
......
......@@ -644,7 +644,6 @@ fn mutability_allowed(a_mutbl: ast::Mutability,
insert_vtables(fcx, MethodCall::expr(ex.id), vtbls);
}
}
true
});
}
......
......@@ -26,5 +26,4 @@ fn test1() {
fn test2() {
let x: Foo<_> = Bar::<uint>;
//~^ ERROR mismatched types: expected `Foo<<generic #0>>` but found `Bar<uint>`
//~^^ ERROR cannot determine a type for this local variable: unconstrained type
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册