From 55ff380aff591663219dca76727bf65c7b4048a8 Mon Sep 17 00:00:00 2001 From: David Renshaw Date: Fri, 15 Nov 2024 11:50:03 -0500 Subject: [PATCH] when a struct has no pointer fields, we can elide lifetime in impl blocks --- capnp-rpc/src/rpc_capnp.rs | 8 ++++---- capnp-rpc/src/rpc_twoparty_capnp.rs | 10 +++++----- capnp/src/schema_capnp.rs | 12 ++++++------ capnpc/src/codegen.rs | 20 +++++++++++++++++++- 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/capnp-rpc/src/rpc_capnp.rs b/capnp-rpc/src/rpc_capnp.rs index 92b604ccb..a1be17d70 100644 --- a/capnp-rpc/src/rpc_capnp.rs +++ b/capnp-rpc/src/rpc_capnp.rs @@ -3060,7 +3060,7 @@ pub mod finish { } } - impl<'a> Reader<'a> { + impl Reader<'_> { pub fn reborrow(&self) -> Reader<'_> { Self { ..*self } } @@ -3815,7 +3815,7 @@ pub mod release { } } - impl<'a> Reader<'a> { + impl Reader<'_> { pub fn reborrow(&self) -> Reader<'_> { Self { ..*self } } @@ -4450,7 +4450,7 @@ pub mod disembargo { } } - impl<'a> Reader<'a> { + impl Reader<'_> { pub fn reborrow(&self) -> Reader<'_> { Self { ..*self } } @@ -7511,7 +7511,7 @@ pub mod promised_answer { } } - impl<'a> Reader<'a> { + impl Reader<'_> { pub fn reborrow(&self) -> Reader<'_> { Self { ..*self } } diff --git a/capnp-rpc/src/rpc_twoparty_capnp.rs b/capnp-rpc/src/rpc_twoparty_capnp.rs index c886ca62c..e30850d02 100644 --- a/capnp-rpc/src/rpc_twoparty_capnp.rs +++ b/capnp-rpc/src/rpc_twoparty_capnp.rs @@ -176,7 +176,7 @@ pub mod vat_id { } } - impl<'a> Reader<'a> { + impl Reader<'_> { pub fn reborrow(&self) -> Reader<'_> { Self { ..*self } } @@ -457,7 +457,7 @@ pub mod provision_id { } } - impl<'a> Reader<'a> { + impl Reader<'_> { pub fn reborrow(&self) -> Reader<'_> { Self { ..*self } } @@ -731,7 +731,7 @@ pub mod recipient_id { } } - impl<'a> Reader<'a> { + impl Reader<'_> { pub fn reborrow(&self) -> Reader<'_> { Self { ..*self } } @@ -974,7 +974,7 @@ pub mod third_party_cap_id { } } - impl<'a> Reader<'a> { + impl Reader<'_> { pub fn reborrow(&self) -> Reader<'_> { Self { ..*self } } @@ -1218,7 +1218,7 @@ pub mod join_key_part { } } - impl<'a> Reader<'a> { + impl Reader<'_> { pub fn reborrow(&self) -> Reader<'_> { Self { ..*self } } diff --git a/capnp/src/schema_capnp.rs b/capnp/src/schema_capnp.rs index 890a6fa9a..6bfc8a5be 100644 --- a/capnp/src/schema_capnp.rs +++ b/capnp/src/schema_capnp.rs @@ -5393,7 +5393,7 @@ pub mod field { } } - impl<'a> Reader<'a> { + impl Reader<'_> { pub fn reborrow(&self) -> Reader<'_> { Self { ..*self } } @@ -5668,7 +5668,7 @@ pub mod field { } } - impl<'a> Reader<'a> { + impl Reader<'_> { pub fn reborrow(&self) -> Reader<'_> { Self { ..*self } } @@ -9679,7 +9679,7 @@ pub mod type_ { } } - impl<'a> Reader<'a> { + impl Reader<'_> { pub fn reborrow(&self) -> Reader<'_> { Self { ..*self } } @@ -10044,7 +10044,7 @@ pub mod type_ { } } - impl<'a> Reader<'a> { + impl Reader<'_> { pub fn reborrow(&self) -> Reader<'_> { Self { ..*self } } @@ -10356,7 +10356,7 @@ pub mod type_ { } } - impl<'a> Reader<'a> { + impl Reader<'_> { pub fn reborrow(&self) -> Reader<'_> { Self { ..*self } } @@ -13069,7 +13069,7 @@ pub mod capnp_version { } } - impl<'a> Reader<'a> { + impl Reader<'_> { pub fn reborrow(&self) -> Reader<'_> { Self { ..*self } } diff --git a/capnpc/src/codegen.rs b/capnpc/src/codegen.rs index 6d177b88e..c1d1c56e2 100644 --- a/capnpc/src/codegen.rs +++ b/capnpc/src/codegen.rs @@ -2052,6 +2052,7 @@ fn generate_node( private_mod_interior.push(generate_members_by_discriminant(*node_reader)?); private_mod_interior.push(generate_members_by_name(*node_reader)?); + let mut has_pointer_field = false; let fields = struct_reader.get_fields()?; for field in fields { let name = get_field_name(field)?; @@ -2060,6 +2061,19 @@ fn generate_node( let discriminant_value = field.get_discriminant_value(); let is_union_field = discriminant_value != field::NO_DISCRIMINANT; + match field.which()? { + field::Slot(s) => match s.get_type()?.which()? { + type_::Text(()) + | type_::Data(()) + | type_::List(_) + | type_::Struct(_) + | type_::Interface(_) + | type_::AnyPointer(_) => has_pointer_field = true, + _ => (), + }, + field::Group(_) => has_pointer_field = true, + } + if !is_union_field { pipeline_impl_interior.push(generate_pipeline_getter(ctx, field)?); let (ty, get, default_decl) = getter_text(ctx, &field, true, true)?; @@ -2275,7 +2289,11 @@ fn generate_node( ]), line("}"), BlankLine, - Line(format!("impl <'a,{0}> Reader<'a,{0}> {1} {{", params.params, params.where_clause)), + if has_pointer_field { // we do this to keep clippy happy + Line(format!("impl <'a,{0}> Reader<'a,{0}> {1} {{", params.params, params.where_clause)) + } else { + Line(format!("impl <{0}> Reader<'_,{0}> {1} {{", params.params, params.where_clause)) + }, indent(vec![ Line(format!("pub fn reborrow(&self) -> Reader<'_,{}> {{",params.params)), indent(line("Self { .. *self }")),