Clean up panic checks a bit

This commit is contained in:
Steven Fackler 2015-01-26 21:13:10 -08:00
parent 7101cab178
commit dec549b9ca

View File

@ -1028,9 +1028,7 @@ impl Connection {
pub fn transaction<'a>(&'a self) -> Result<Transaction<'a>> { pub fn transaction<'a>(&'a self) -> Result<Transaction<'a>> {
let mut conn = self.conn.borrow_mut(); let mut conn = self.conn.borrow_mut();
check_desync!(conn); check_desync!(conn);
if conn.trans_depth != 0 { assert!(conn.trans_depth == 0, "`transaction` must be called on the active transaction");
panic!("`transaction` must be called on the active transaction");
}
try!(conn.quick_query("BEGIN")); try!(conn.quick_query("BEGIN"));
conn.trans_depth += 1; conn.trans_depth += 1;
Ok(Transaction { Ok(Transaction {
@ -1230,9 +1228,8 @@ impl<'conn> Transaction<'conn> {
pub fn transaction<'a>(&'a self) -> Result<Transaction<'a>> { pub fn transaction<'a>(&'a self) -> Result<Transaction<'a>> {
let mut conn = self.conn.conn.borrow_mut(); let mut conn = self.conn.conn.borrow_mut();
check_desync!(conn); check_desync!(conn);
if conn.trans_depth != self.depth { assert!(conn.trans_depth == self.depth, "`transaction` may only be called on the active \
panic!("`transaction` may only be called on the active transaction"); transaction");
}
try!(conn.quick_query("SAVEPOINT sp")); try!(conn.quick_query("SAVEPOINT sp"));
conn.trans_depth += 1; conn.trans_depth += 1;
Ok(Transaction { Ok(Transaction {
@ -1493,15 +1490,13 @@ impl<'conn> Statement<'conn> {
params: &[&ToSql], params: &[&ToSql],
row_limit: i32) row_limit: i32)
-> Result<LazyRows<'trans, 'stmt>> { -> Result<LazyRows<'trans, 'stmt>> {
if self.conn as *const _ != trans.conn as *const _ { assert!(self.conn as *const _ == trans.conn as *const _,
panic!("the `Transaction` passed to `lazy_query` must be associated with the same \ "the `Transaction` passed to `lazy_query` must be associated with the same \
`Connection` as the `Statement`"); `Connection` as the `Statement`");
}
let conn = self.conn.conn.borrow(); let conn = self.conn.conn.borrow();
check_desync!(conn); check_desync!(conn);
if conn.trans_depth != trans.depth { assert!(conn.trans_depth == trans.depth,
panic!("`lazy_query` may only be called on the active transaction"); "`lazy_query` may only be called on the active transaction");
}
drop(conn); drop(conn);
let id = self.next_portal_id.get(); let id = self.next_portal_id.get();