From 085217bb8cb27e2f6e2f99297fca4d6813847bb6 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Wed, 26 Mar 2025 14:22:32 +0100 Subject: [PATCH 1/2] varlink: Fix clippy nightly complaints --> varlink/src/lib.rs:1056:53 | 1056 | ... .map_err(map_context!()) | _______________________________________________^ 1057 | | ... .map_err(Error::from)?, | |___________________________________________^ help: consider removing | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion = note: `-D clippy::useless-conversion` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::useless_conversion)]` --- varlink/src/lib.rs | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/varlink/src/lib.rs b/varlink/src/lib.rs index 069b42a..d188f68 100644 --- a/varlink/src/lib.rs +++ b/varlink/src/lib.rs @@ -1051,11 +1051,7 @@ where let mut req = match (self.method.take(), self.request.take()) { (Some(method), Some(request)) => Request::create( method, - Some( - serde_json::to_value(request) - .map_err(map_context!()) - .map_err(Error::from)?, - ), + Some(serde_json::to_value(request).map_err(map_context!())?), ), _ => { return Err(MError::from(context!(ErrorKind::MethodCalledAlready))); @@ -1082,15 +1078,10 @@ where let mut w = conn.writer.take().unwrap(); - let b = serde_json::to_string(&req) - .map_err(map_context!()) - .map_err(Error::from)? - + "\0"; + let b = serde_json::to_string(&req).map_err(map_context!())? + "\0"; - w.write_all(b.as_bytes()) - .map_err(map_context!()) - .map_err(Error::from)?; - w.flush().map_err(map_context!()).map_err(Error::from)?; + w.write_all(b.as_bytes()).map_err(map_context!())?; + w.flush().map_err(map_context!())?; if oneway { conn.writer = Some(w); } else { @@ -1128,18 +1119,13 @@ where let mut buf = Vec::new(); let mut reader = self.reader.take().unwrap(); - reader - .read_until(0, &mut buf) - .map_err(map_context!()) - .map_err(Error::from)?; + reader.read_until(0, &mut buf).map_err(map_context!())?; self.reader = Some(reader); if buf.is_empty() { return Err(context!(ErrorKind::ConnectionClosed).into()); } buf.pop(); - let reply: Reply = serde_json::from_slice(&buf) - .map_err(map_context!()) - .map_err(Error::from)?; + let reply: Reply = serde_json::from_slice(&buf).map_err(map_context!())?; match reply.continues { Some(true) => self.continues = true, _ => { @@ -1158,9 +1144,7 @@ where parameters: Some(p), .. } => { - let mreply: MReply = serde_json::from_value(p) - .map_err(map_context!()) - .map_err(Error::from)?; + let mreply: MReply = serde_json::from_value(p).map_err(map_context!())?; Ok(mreply) } Reply { @@ -1168,8 +1152,7 @@ where } => { let mreply: MReply = serde_json::from_value(serde_json::Value::Object(serde_json::Map::new())) - .map_err(map_context!()) - .map_err(Error::from)?; + .map_err(map_context!())?; Ok(mreply) } } From 1f826c4cdee144364f1b9020d7fc05398982e23f Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Sat, 22 Mar 2025 12:31:33 +0100 Subject: [PATCH 2/2] varlink_generator: Fix generating code which compiles with Rust 2024 This generates code which also compiles with Rust 2024. See https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html Fixes #121 --- examples/more/src/org_example_more.rs | 24 +++++++++---------- examples/ping/src/org_example_ping.rs | 4 +--- varlink_generator/src/lib.rs | 2 +- .../tests/org.example.complex.rs_out | 8 ++----- 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/examples/more/src/org_example_more.rs b/examples/more/src/org_example_more.rs index f8641a6..d6167e3 100644 --- a/examples/more/src/org_example_more.rs +++ b/examples/more/src/org_example_more.rs @@ -104,18 +104,18 @@ impl From<&varlink::Reply> for ErrorKind { #[allow(unused_variables)] fn from(e: &varlink::Reply) -> Self { match e { - varlink::Reply { - error: Some(ref t), .. - } if t == "org.example.more.TestMoreError" => match e { - varlink::Reply { - parameters: Some(p), - .. - } => match serde_json::from_value(p.clone()) { - Ok(v) => ErrorKind::TestMoreError(v), - Err(_) => ErrorKind::TestMoreError(None), - }, - _ => ErrorKind::TestMoreError(None), - }, + varlink::Reply { error: Some(t), .. } if t == "org.example.more.TestMoreError" => { + match e { + varlink::Reply { + parameters: Some(p), + .. + } => match serde_json::from_value(p.clone()) { + Ok(v) => ErrorKind::TestMoreError(v), + Err(_) => ErrorKind::TestMoreError(None), + }, + _ => ErrorKind::TestMoreError(None), + } + } _ => ErrorKind::VarlinkReply_Error, } } diff --git a/examples/ping/src/org_example_ping.rs b/examples/ping/src/org_example_ping.rs index 6266578..dff802f 100644 --- a/examples/ping/src/org_example_ping.rs +++ b/examples/ping/src/org_example_ping.rs @@ -104,9 +104,7 @@ impl From<&varlink::Reply> for ErrorKind { #[allow(unused_variables)] fn from(e: &varlink::Reply) -> Self { match e { - varlink::Reply { - error: Some(ref t), .. - } if t == "org.example.ping.PingError" => match e { + varlink::Reply { error: Some(t), .. } if t == "org.example.ping.PingError" => match e { varlink::Reply { parameters: Some(p), .. diff --git a/varlink_generator/src/lib.rs b/varlink_generator/src/lib.rs index b17fb63..626c15c 100644 --- a/varlink_generator/src/lib.rs +++ b/varlink_generator/src/lib.rs @@ -713,7 +713,7 @@ fn generate_error_code( let error_name = format!("{iname}.{ename}", iname = idl.name, ename = t.name); let ename = TokenStream::from_str(&format!("ErrorKind::{}", t.name)).unwrap(); arms.extend(quote!( - varlink::Reply { error: Some(ref t), .. } if t == #error_name => { + varlink::Reply { error: Some(t), .. } if t == #error_name => { match e { varlink::Reply { parameters: Some(p), diff --git a/varlink_generator/tests/org.example.complex.rs_out b/varlink_generator/tests/org.example.complex.rs_out index 339c314..c60c398 100644 --- a/varlink_generator/tests/org.example.complex.rs_out +++ b/varlink_generator/tests/org.example.complex.rs_out @@ -103,9 +103,7 @@ impl From<&varlink::Reply> for ErrorKind { #[allow(unused_variables)] fn from(e: &varlink::Reply) -> Self { match e { - varlink::Reply { - error: Some(ref t), .. - } if t == "org.example.complex.ErrorBar" => match e { + varlink::Reply { error: Some(t), .. } if t == "org.example.complex.ErrorBar" => match e { varlink::Reply { parameters: Some(p), .. @@ -115,9 +113,7 @@ impl From<&varlink::Reply> for ErrorKind { }, _ => ErrorKind::ErrorBar(None), }, - varlink::Reply { - error: Some(ref t), .. - } if t == "org.example.complex.ErrorFoo" => match e { + varlink::Reply { error: Some(t), .. } if t == "org.example.complex.ErrorFoo" => match e { varlink::Reply { parameters: Some(p), ..