diff --git a/benchmark/benchmark.rs b/benchmark/benchmark.rs index ea94fd985..eb26b04de 100644 --- a/benchmark/benchmark.rs +++ b/benchmark/benchmark.rs @@ -174,10 +174,7 @@ impl<'a> Scratch<'a> for UseScratch { type Allocator = message::ScratchSpaceHeapAllocator<'a>; fn get_allocators(&'a mut self) -> (Self::Allocator, Self::Allocator) { - let UseScratch { - ref mut buffer1, - ref mut buffer2, - } = self; + let UseScratch { buffer1, buffer2 } = self; ( message::ScratchSpaceHeapAllocator::new(capnp::Word::words_to_bytes_mut(buffer1)), message::ScratchSpaceHeapAllocator::new(capnp::Word::words_to_bytes_mut(buffer2)), diff --git a/capnp-rpc/src/queued.rs b/capnp-rpc/src/queued.rs index f5e3a5d65..c90a18467 100644 --- a/capnp-rpc/src/queued.rs +++ b/capnp-rpc/src/queued.rs @@ -143,7 +143,7 @@ impl PipelineHook for Pipeline { } fn get_pipelined_cap_move(&self, ops: Vec) -> Box { - if let Some(ref p) = self.inner.borrow().redirect { + if let Some(p) = &self.inner.borrow().redirect { return p.get_pipelined_cap_move(ops); } @@ -258,7 +258,7 @@ impl ClientHook for Client { params: Box, results: Box, ) -> Promise<(), Error> { - if let Some(ref client) = self.inner.borrow().redirect { + if let Some(client) = &self.inner.borrow().redirect { return client.call(interface_id, method_id, params, results); } @@ -288,20 +288,20 @@ impl ClientHook for Client { } fn get_resolved(&self) -> Option> { - match self.inner.borrow().redirect { - Some(ref inner) => Some(inner.clone()), + match &self.inner.borrow().redirect { + Some(inner) => Some(inner.clone()), None => None, } } fn when_more_resolved(&self) -> Option, Error>> { - if let Some(ref client) = self.inner.borrow().redirect { + if let Some(client) = &self.inner.borrow().redirect { return Some(Promise::ok(client.add_ref())); } let promise = self.inner.borrow_mut().client_resolution_queue.push(()); - match self.inner.borrow().promise_to_drive { - Some(ref p) => Some(Promise::from_future( + match &self.inner.borrow().promise_to_drive { + Some(p) => Some(Promise::from_future( futures::future::try_join(p.clone(), promise).map_ok(|v| v.1), )), None => Some(Promise::from_future(promise)), diff --git a/capnp-rpc/src/rpc.rs b/capnp-rpc/src/rpc.rs index ff0c1be6a..0bf3ddc47 100644 --- a/capnp-rpc/src/rpc.rs +++ b/capnp-rpc/src/rpc.rs @@ -90,7 +90,7 @@ where while self.idx < self.table.slots.len() { let idx = self.idx; self.idx += 1; - if let Some(ref v) = self.table.slots[idx] { + if let Some(v) = &self.table.slots[idx] { return Some(v); } } @@ -127,10 +127,7 @@ impl ExportTable { pub fn find(&mut self, id: u32) -> Option<&mut T> { let idx = id as usize; if idx < self.slots.len() { - match self.slots[idx] { - Some(ref mut v) => Some(v), - None => None, - } + self.slots[idx].as_mut() } else { None } @@ -210,8 +207,8 @@ impl QuestionRef { impl Drop for QuestionRef { fn drop(&mut self) { let mut questions = self.connection_state.questions.borrow_mut(); - match questions.slots[self.id as usize] { - Some(ref mut q) => { + match &mut questions.slots[self.id as usize] { + Some(q) => { if let Ok(ref mut c) = *self.connection_state.connection.borrow_mut() { let mut message = c.new_outgoing_message(100); // XXX size hint { @@ -796,7 +793,7 @@ impl ConnectionState { answer_id ))); } - Some(ref mut answer) => { + Some(answer) => { if !answer.active { return Err(Error::failed(format!( "'Finish' for invalid question ID {}.", @@ -879,9 +876,7 @@ impl ConnectionState { connection_state.add_task(task); } disembargo::context::ReceiverLoopback(embargo_id) => { - if let Some(ref mut embargo) = - connection_state.embargoes.borrow_mut().find(embargo_id) - { + if let Some(embargo) = connection_state.embargoes.borrow_mut().find(embargo_id) { let fulfiller = embargo.fulfiller.take().unwrap(); let _ = fulfiller.send(Ok(())); } else { @@ -1008,9 +1003,9 @@ impl ConnectionState { }) .then(move |v| { match redirected_results_done_fulfiller { - Some(f) => match v { - Ok(ref r) => drop(f.send(Ok(Response::redirected(r.clone())))), - Err(ref e) => drop(f.send(Err(e.clone()))), + Some(f) => match &v { + Ok(r) => drop(f.send(Ok(Response::redirected(r.clone())))), + Err(e) => drop(f.send(Err(e.clone()))), }, None => (), } @@ -1023,7 +1018,7 @@ impl ConnectionState { { let ref mut slots = connection_state.answers.borrow_mut().slots; match slots.get_mut(&question_id) { - Some(ref mut answer) => { + Some(answer) => { answer.pipeline = Some(Box::new(pipeline)); if redirect_results { answer.redirected_results = redirected_results_done_promise; @@ -1076,7 +1071,7 @@ impl ConnectionState { unimplemented!() } return_::TakeFromOtherQuestion(id) => { - if let Some(ref mut answer) = + if let Some(answer) = connection_state.answers.borrow_mut().slots.get_mut(&id) { if let Some(res) = answer.redirected_results.take() { @@ -1147,7 +1142,7 @@ impl ConnectionState { // If the import is in the table, fulfill it. let ref mut slots = connection_state.imports.borrow_mut().slots; - if let Some(ref mut import) = slots.get_mut(&resolve.get_promise_id()) { + if let Some(import) = slots.get_mut(&resolve.get_promise_id()) { match import.promise_client_to_resolve.take() { Some(weak_promise_client) => { match weak_promise_client.upgrade() { @@ -1189,7 +1184,7 @@ impl ConnectionState { fn answer_has_sent_return(&self, id: AnswerId, result_exports: Vec) { let mut erase = false; let answers_slots = &mut self.answers.borrow_mut().slots; - if let Some(ref mut a) = answers_slots.get_mut(&id) { + if let Some(a) = answers_slots.get_mut(&id) { a.return_has_been_sent = true; if a.received_finish.get() { erase = true; @@ -1346,8 +1341,7 @@ impl ConnectionState { // Update the export table to point at this object instead. We know that our // entry in the export table is still live because when it is destroyed the // asynchronous resolution task (i.e. this code) is canceled. - if let Some(ref mut exp) = connection_state.exports.borrow_mut().find(export_id) - { + if let Some(exp) = connection_state.exports.borrow_mut().find(export_id) { connection_state .exports_by_cap .borrow_mut() @@ -1426,7 +1420,7 @@ impl ConnectionState { let export_id = state.exports_by_cap.borrow()[(&ptr)]; match state.exports.borrow_mut().find(export_id) { None => unreachable!(), - Some(ref mut exp) => { + Some(exp) => { descriptor.set_sender_hosted(export_id); exp.refcount += 1; Ok(Some(export_id)) @@ -1441,7 +1435,7 @@ impl ConnectionState { match inner.when_more_resolved() { Some(wrapped) => { // This is a promise. Arrange for the `Resolve` message to be sent later. - if let Some(ref mut exp) = state.exports.borrow_mut().find(export_id) { + if let Some(exp) = state.exports.borrow_mut().find(export_id) { exp.resolve_op = ConnectionState::resolve_exported_promise( state, export_id, wrapped, ); @@ -1522,9 +1516,9 @@ impl ConnectionState { if is_promise { // We need to construct a PromiseClient around this import, if we haven't already. match state.imports.borrow_mut().slots.get_mut(&import_id) { - Some(ref mut import) => { - match import.app_client { - Some(ref c) => { + Some(import) => { + match &import.app_client { + Some(c) => { // Use the existing one. Box::new(c.upgrade().expect("dangling client ref?")) } @@ -1555,7 +1549,7 @@ impl ConnectionState { } else { let client: Box> = Box::new(import_client.into()); match state.imports.borrow_mut().slots.get_mut(&import_id) { - Some(ref mut v) => { + Some(v) => { v.app_client = Some(client.downgrade()); } None => { @@ -1580,7 +1574,7 @@ impl ConnectionState { Ok(Some(ConnectionState::import(&state, sender_promise, true))) } cap_descriptor::ReceiverHosted(receiver_hosted) => { - if let Some(ref mut exp) = state.exports.borrow_mut().find(receiver_hosted) { + if let Some(exp) = state.exports.borrow_mut().find(receiver_hosted) { Ok(Some(exp.client_hook.add_ref())) } else { Ok(Some(broken::new_cap(Error::failed( @@ -2155,8 +2149,8 @@ impl PipelineHook for Pipeline { let pipeline_client = PipelineClient::new(connection_state, question_ref.clone(), ops.clone()); - match *redirect_later { - Some(ref _r) => { + match redirect_later { + Some(_r) => { let client: Client = pipeline_client.into(); let promise_client = PromiseClient::new(connection_state, Box::new(client), None); @@ -2449,7 +2443,7 @@ impl ResultsDone { // Send a Canceled return. match connection_state.connection.borrow_mut().as_mut() { - Ok(ref mut connection) => { + Ok(connection) => { let mut message = connection.new_outgoing_message(50); // XXX size hint { let root: message::Builder = @@ -2500,7 +2494,7 @@ impl ResultsDone { (false, Err(e)) => { // Send an error return. match connection_state.connection.borrow_mut().as_mut() { - Ok(ref mut connection) => { + Ok(connection) => { let mut message = connection.new_outgoing_message(50); // XXX size hint { let root: message::Builder = @@ -2632,27 +2626,15 @@ where VatId: 'static, { fn upgrade(&self) -> Option> { - let variant = match self.variant { - WeakClientVariant::Import(ref ic) => match ic.upgrade() { - Some(ic) => ClientVariant::Import(ic), - None => return None, - }, - WeakClientVariant::Pipeline(ref pc) => match pc.upgrade() { - Some(pc) => ClientVariant::Pipeline(pc), - None => return None, - }, - WeakClientVariant::Promise(ref pc) => match pc.upgrade() { - Some(pc) => ClientVariant::Promise(pc), - None => return None, - }, + let variant = match &self.variant { + WeakClientVariant::Import(ic) => ClientVariant::Import(ic.upgrade()?), + WeakClientVariant::Pipeline(pc) => ClientVariant::Pipeline(pc.upgrade()?), + WeakClientVariant::Promise(pc) => ClientVariant::Promise(pc.upgrade()?), WeakClientVariant::__NoIntercept(()) => ClientVariant::__NoIntercept(()), }; - let state = match self.connection_state.upgrade() { - Some(s) => s, - None => return None, - }; + let connection_state = self.connection_state.upgrade()?; Some(Client { - connection_state: state, + connection_state, variant, }) } @@ -2700,7 +2682,7 @@ impl Drop for ImportClient { // Send a message releasing our remote references. let mut tmp = connection_state.connection.borrow_mut(); match (self.remote_ref_count > 0, tmp.as_mut()) { - (true, Ok(ref mut c)) => { + (true, Ok(c)) => { let mut message = c.new_outgoing_message(50); // XXX size hint { let root: message::Builder = message.get_body().unwrap().init_as(); @@ -2903,9 +2885,9 @@ impl Drop for PromiseClient { // the import still exists and the pointer still points back to this object because this // object may actually outlive the import. let ref mut slots = self.connection_state.imports.borrow_mut().slots; - if let Some(ref mut import) = slots.get_mut(&id) { + if let Some(import) = slots.get_mut(&id) { let mut drop_it = false; - if let Some(ref c) = import.app_client { + if let Some(c) = &import.app_client { if let Some(cs) = c.upgrade() { if cs.get_ptr() == self_ptr { drop_it = true; @@ -2953,14 +2935,14 @@ impl Client { client } fn downgrade(&self) -> WeakClient { - let variant = match self.variant { - ClientVariant::Import(ref import_client) => { + let variant = match &self.variant { + ClientVariant::Import(import_client) => { WeakClientVariant::Import(Rc::downgrade(import_client)) } - ClientVariant::Pipeline(ref pipeline_client) => { + ClientVariant::Pipeline(pipeline_client) => { WeakClientVariant::Pipeline(Rc::downgrade(pipeline_client)) } - ClientVariant::Promise(ref promise_client) => { + ClientVariant::Promise(promise_client) => { WeakClientVariant::Promise(Rc::downgrade(promise_client)) } _ => { @@ -2984,12 +2966,12 @@ impl Client { &self, mut target: crate::rpc_capnp::message_target::Builder, ) -> Option> { - match self.variant { - ClientVariant::Import(ref import_client) => { + match &self.variant { + ClientVariant::Import(import_client) => { target.set_imported_cap(import_client.borrow().import_id); None } - ClientVariant::Pipeline(ref pipeline_client) => { + ClientVariant::Pipeline(pipeline_client) => { let mut builder = target.init_promised_answer(); let question_ref = &pipeline_client.borrow().question_ref; builder.set_question_id(question_ref.borrow().id); @@ -3008,7 +2990,7 @@ impl Client { } None } - ClientVariant::Promise(ref promise_client) => { + ClientVariant::Promise(promise_client) => { promise_client.borrow_mut().received_call = true; self.connection_state .write_target(&*promise_client.borrow().cap, target) @@ -3020,12 +3002,12 @@ impl Client { } fn write_descriptor(&self, mut descriptor: cap_descriptor::Builder) -> Option { - match self.variant { - ClientVariant::Import(ref import_client) => { + match &self.variant { + ClientVariant::Import(import_client) => { descriptor.set_receiver_hosted(import_client.borrow().import_id); None } - ClientVariant::Pipeline(ref pipeline_client) => { + ClientVariant::Pipeline(pipeline_client) => { let mut promised_answer = descriptor.init_receiver_answer(); let question_ref = &pipeline_client.borrow().question_ref; promised_answer.set_question_id(question_ref.borrow().id); @@ -3045,7 +3027,7 @@ impl Client { None } - ClientVariant::Promise(ref promise_client) => { + ClientVariant::Promise(promise_client) => { promise_client.borrow_mut().received_call = true; ConnectionState::write_descriptor( @@ -3064,14 +3046,12 @@ impl Client { impl Clone for Client { fn clone(&self) -> Client { - let variant = match self.variant { - ClientVariant::Import(ref import_client) => { - ClientVariant::Import(import_client.clone()) - } - ClientVariant::Pipeline(ref pipeline_client) => { + let variant = match &self.variant { + ClientVariant::Import(import_client) => ClientVariant::Import(import_client.clone()), + ClientVariant::Pipeline(pipeline_client) => { ClientVariant::Pipeline(pipeline_client.clone()) } - ClientVariant::Promise(ref promise_client) => { + ClientVariant::Promise(promise_client) => { ClientVariant::Promise(promise_client.clone()) } _ => { @@ -3150,14 +3130,12 @@ impl ClientHook for Client { } fn get_ptr(&self) -> usize { - match self.variant { - ClientVariant::Import(ref import_client) => { - (&*import_client.borrow()) as *const _ as usize - } - ClientVariant::Pipeline(ref pipeline_client) => { + match &self.variant { + ClientVariant::Import(import_client) => (&*import_client.borrow()) as *const _ as usize, + ClientVariant::Pipeline(pipeline_client) => { (&*pipeline_client.borrow()) as *const _ as usize } - ClientVariant::Promise(ref promise_client) => { + ClientVariant::Promise(promise_client) => { (&*promise_client.borrow()) as *const _ as usize } _ => { @@ -3171,10 +3149,10 @@ impl ClientHook for Client { } fn get_resolved(&self) -> Option> { - match self.variant { - ClientVariant::Import(ref _import_client) => None, - ClientVariant::Pipeline(ref _pipeline_client) => None, - ClientVariant::Promise(ref promise_client) => { + match &self.variant { + ClientVariant::Import(_import_client) => None, + ClientVariant::Pipeline(_pipeline_client) => None, + ClientVariant::Promise(promise_client) => { if promise_client.borrow().is_resolved { Some(promise_client.borrow().cap.clone()) } else { @@ -3188,10 +3166,10 @@ impl ClientHook for Client { } fn when_more_resolved(&self) -> Option, Error>> { - match self.variant { - ClientVariant::Import(ref _import_client) => None, - ClientVariant::Pipeline(ref _pipeline_client) => None, - ClientVariant::Promise(ref promise_client) => { + match &self.variant { + ClientVariant::Import(_import_client) => None, + ClientVariant::Pipeline(_pipeline_client) => None, + ClientVariant::Promise(promise_client) => { Some(promise_client.borrow_mut().resolution_waiters.push(())) } _ => { diff --git a/capnp/src/lib.rs b/capnp/src/lib.rs index 3650be3f2..7d613253a 100644 --- a/capnp/src/lib.rs +++ b/capnp/src/lib.rs @@ -287,18 +287,18 @@ pub enum OutputSegments<'a> { impl<'a> core::ops::Deref for OutputSegments<'a> { type Target = [&'a [u8]]; fn deref(&self) -> &[&'a [u8]] { - match *self { - OutputSegments::SingleSegment(ref s) => s, - OutputSegments::MultiSegment(ref v) => v, + match self { + OutputSegments::SingleSegment(s) => s, + OutputSegments::MultiSegment(v) => v, } } } impl<'s> message::ReaderSegments for OutputSegments<'s> { fn get_segment(&self, id: u32) -> Option<&[u8]> { - match *self { - OutputSegments::SingleSegment(ref s) => s.get(id as usize).copied(), - OutputSegments::MultiSegment(ref v) => v.get(id as usize).copied(), + match self { + OutputSegments::SingleSegment(s) => s.get(id as usize).copied(), + OutputSegments::MultiSegment(v) => v.get(id as usize).copied(), } } } diff --git a/capnp/src/message.rs b/capnp/src/message.rs index 4415d1ae1..c30234051 100644 --- a/capnp/src/message.rs +++ b/capnp/src/message.rs @@ -419,7 +419,7 @@ where } let (seg_start, _seg_len) = self.arena.get_segment_mut(0); let location: *mut u8 = seg_start; - let Self { ref mut arena } = *self; + let Self { arena } = self; any_pointer::Builder::new(layout::PointerBuilder::get_root(arena, 0, location)) } diff --git a/capnp/src/private/arena.rs b/capnp/src/private/arena.rs index 93845a032..8f645bc9d 100644 --- a/capnp/src/private/arena.rs +++ b/capnp/src/private/arena.rs @@ -289,8 +289,8 @@ where { /// Allocates a new segment with capacity for at least `minimum_size` words. fn allocate_segment(&mut self, minimum_size: WordCount32) -> Result<()> { - let seg = match self.allocator { - Some(ref mut a) => a.allocate_segment(minimum_size), + let seg = match &mut self.allocator { + Some(a) => a.allocate_segment(minimum_size), None => unreachable!(), }; self.segments.push(BuilderSegment { @@ -332,7 +332,7 @@ where } fn deallocate_all(&mut self) { - if let Some(ref mut a) = self.allocator { + if let Some(a) = &mut self.allocator { for seg in &self.segments { a.deallocate_segment(seg.ptr, seg.capacity, seg.allocated); } diff --git a/capnp/src/private/layout.rs b/capnp/src/private/layout.rs index 7d9271805..56ccb25cc 100644 --- a/capnp/src/private/layout.rs +++ b/capnp/src/private/layout.rs @@ -2750,10 +2750,7 @@ impl CapTableReader { if index >= hooks.len() { None } else { - match hooks[index] { - None => None, - Some(ref hook) => Some(hook.add_ref()), - } + hooks[index].as_ref().map(|hook| hook.add_ref()) } } } @@ -2785,10 +2782,7 @@ impl CapTableBuilder { if index >= hooks.len() { None } else { - match hooks[index] { - None => None, - Some(ref hook) => Some(hook.add_ref()), - } + hooks[index].as_ref().map(|hook| hook.add_ref()) } } } diff --git a/capnpc/src/codegen.rs b/capnpc/src/codegen.rs index 201630a36..7e8f868f0 100644 --- a/capnpc/src/codegen.rs +++ b/capnpc/src/codegen.rs @@ -128,7 +128,7 @@ impl CodeGenerationCommand { // It would be simpler to use the ? operator instead of a pattern match, but then the error message // would not include `filepath`. match ::std::fs::File::create(&filepath) { - Ok(ref mut writer) => { + Ok(mut writer) => { writer.write_all(text.as_bytes()).map_err(convert_io_err)?; } Err(e) => { @@ -325,9 +325,9 @@ pub enum FormattedText { } fn to_lines(ft: &FormattedText, indent: usize) -> Vec { - match *ft { - Indent(ref ft) => to_lines(ft, indent + 1), - Branch(ref fts) => { + match ft { + Indent(ft) => to_lines(ft, indent + 1), + Branch(fts) => { let mut result = Vec::new(); for ft in fts.iter() { for line in &to_lines(ft, indent) { @@ -336,7 +336,7 @@ fn to_lines(ft: &FormattedText, indent: usize) -> Vec { } result } - Line(ref s) => { + Line(s) => { let mut s1: String = " ".repeat(indent * 2); s1.push_str(s); vec![s1.to_string()] @@ -1057,7 +1057,7 @@ fn generate_setter( } } }; - if let Some(ref reader_type) = maybe_reader_type { + if let Some(reader_type) = &maybe_reader_type { let return_type = if return_result { "-> ::capnp::Result<()>" } else {