diff --git a/pilota-build/src/codegen/workspace.rs b/pilota-build/src/codegen/workspace.rs index 59d6c84f..2dfc0d8e 100644 --- a/pilota-build/src/codegen/workspace.rs +++ b/pilota-build/src/codegen/workspace.rs @@ -10,7 +10,7 @@ use super::CodegenItem; use crate::{ db::RirDatabase, fmt::fmt_file, - middle::context::DefLocation, + middle::context::{CrateId, DefLocation}, rir::{self, ItemPath}, Codegen, CodegenBackend, Context, DefId, }; @@ -77,7 +77,7 @@ where let members = entry_map .keys() .filter_map(|k| { - if let DefLocation::Fixed(_) = k { + if let DefLocation::Fixed(..) = k { let name = self.cx().crate_name(k); Some(format!(" \"{name}\"")) } else { @@ -134,7 +134,7 @@ where &this.base_dir, CrateInfo { main_mod_path: match k { - DefLocation::Fixed(path) => Some(path.clone()), + DefLocation::Fixed(_, path) => Some(path.clone()), DefLocation::Dynamic => None, }, workspace_deps: workspace_deps.clone(), @@ -175,7 +175,10 @@ where let file_id = cx.node(def_id).unwrap().file_id; if cx.input_files().contains(&file_id) { let file = cx.file(file_id).unwrap(); - map.insert(def_id, DefLocation::Fixed(file.package.clone())); + map.insert( + def_id, + DefLocation::Fixed(CrateId { main_file: file_id }, file.package.clone()), + ); } else { map.insert(def_id, DefLocation::Dynamic); } diff --git a/pilota-build/src/lib.rs b/pilota-build/src/lib.rs index 6734e556..32baf96c 100644 --- a/pilota-build/src/lib.rs +++ b/pilota-build/src/lib.rs @@ -255,16 +255,6 @@ where args, } = Resolver::default().resolve_files(&files); - // discard duplicated items - // let mods = nodes - // .iter() - // .into_group_map_by(|(_, node)| - // files.get(&node.file_id).unwrap().package.clone()); - - // for (_, m) in mods { - // m.iter().unique_by(f); - // } - db.set_files_with_durability(Arc::new(files), Durability::HIGH); let items = nodes.iter().filter_map(|(k, v)| { if let NodeKind::Item(item) = &v.kind { diff --git a/pilota-build/src/middle/context.rs b/pilota-build/src/middle/context.rs index 2ee96cae..cbf284d9 100644 --- a/pilota-build/src/middle/context.rs +++ b/pilota-build/src/middle/context.rs @@ -10,7 +10,7 @@ use normpath::PathExt; use quote::format_ident; use salsa::ParallelDatabase; -use self::tls::{with_cur_item, CUR_ITEM}; +use self::tls::with_cur_item; use super::{ adjust::Adjust, resolver::{DefaultPathResolver, PathResolver, WorkspacePathResolver}, @@ -25,9 +25,14 @@ use crate::{ Plugin, }; +#[derive(Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Clone)] +pub struct CrateId { + pub(crate) main_file: FileId, +} + #[derive(Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Clone)] pub(crate) enum DefLocation { - Fixed(ItemPath), + Fixed(CrateId, ItemPath), Dynamic, } @@ -56,7 +61,7 @@ pub struct Context { pub adjusts: Arc>, pub services: Arc<[crate::IdlService]>, pub(crate) change_case: bool, - pub(crate) codegen_items: Arc>, + pub(crate) codegen_items: Arc<[DefId]>, pub(crate) path_resolver: Arc, pub(crate) mode: Arc, pub(crate) keep_unknown_fields: FxHashSet, @@ -266,7 +271,10 @@ impl ContextBuilder { let file_id = cx.db.node(def_id).unwrap().file_id; if cx.db.input_files().contains(&file_id) { let file = cx.db.file(file_id).unwrap(); - map.insert(def_id, DefLocation::Fixed(file.package.clone())); + map.insert( + def_id, + DefLocation::Fixed(CrateId { main_file: file_id }, file.package.clone()), + ); } else { map.insert(def_id, DefLocation::Dynamic); } @@ -374,7 +382,7 @@ impl ContextBuilder { db: self.db.snapshot(), change_case, services, - codegen_items: Arc::new(self.codegen_items), + codegen_items: Arc::from(self.codegen_items), path_resolver: match &self.mode { Mode::Workspace(_) => Arc::new(WorkspacePathResolver), Mode::SingleFile { .. } => Arc::new(DefaultPathResolver), @@ -833,13 +841,7 @@ impl Context { #[allow(clippy::single_match)] pub fn exec_plugin(&self, mut p: P) { - for def_id in self.codegen_items.clone().iter() { - let node = self.node(*def_id).unwrap(); - CUR_ITEM.set(def_id, || match &node.kind { - NodeKind::Item(item) => p.on_item(self, *def_id, item.clone()), - _ => {} - }) - } + p.on_codegen_uint(self, &self.codegen_items); p.on_emit(self) } @@ -866,7 +868,29 @@ impl Context { pub(crate) fn crate_name(&self, location: &DefLocation) -> FastStr { match location { - DefLocation::Fixed(path) => path.iter().join("_").into(), + DefLocation::Fixed(crate_id, _) => { + let main_file = crate_id.main_file; + let service = self + .services + .iter() + .find(|s| self.file_id(s.path.clone()).unwrap() == main_file) + .unwrap(); + service + .config + .get("crate_name") + .map(|s| s.as_str().map(|s| FastStr::new(s))) + .flatten() + .unwrap_or_else(|| { + service + .path + .file_stem() + .unwrap() + .to_str() + .unwrap() + .replace(".", "_") + .into() + }) + } DefLocation::Dynamic => "common".into(), } } diff --git a/pilota-build/src/middle/resolver.rs b/pilota-build/src/middle/resolver.rs index eeb13f6e..ee254bf4 100644 --- a/pilota-build/src/middle/resolver.rs +++ b/pilota-build/src/middle/resolver.rs @@ -112,7 +112,7 @@ impl PathResolver for WorkspacePathResolver { let info = cx.workspace_info(); let prefix = match &info.location_map[&item_def_id] { - location @ super::context::DefLocation::Fixed(prefix) => { + location @ super::context::DefLocation::Fixed(_, prefix) => { let mut path = Vec::with_capacity(prefix.len() + 1); path.push(cx.crate_name(location).into()); path.extend(prefix.iter().cloned()); diff --git a/pilota-build/src/plugin/mod.rs b/pilota-build/src/plugin/mod.rs index 6e31a49f..8694a577 100644 --- a/pilota-build/src/plugin/mod.rs +++ b/pilota-build/src/plugin/mod.rs @@ -7,7 +7,8 @@ use quote::quote; use crate::{ db::RirDatabase, - rir::{EnumVariant, Field, Item}, + middle::context::tls::CUR_ITEM, + rir::{EnumVariant, Field, Item, NodeKind}, symbol::{DefId, EnumRepr}, tags::EnumMode, ty::{self, Ty, Visitor}, @@ -19,6 +20,10 @@ mod serde; pub use self::serde::SerdePlugin; pub trait Plugin: Sync + Send { + fn on_codegen_uint(&mut self, cx: &Context, items: &[DefId]) { + walk_codegen_uint(self, cx, items) + } + fn on_item(&mut self, cx: &Context, def_id: DefId, item: Arc) { walk_item(self, cx, def_id, item) } @@ -115,6 +120,19 @@ pub fn walk_item(p: &mut P, cx: &Context, _def_id: DefId, it } } +pub fn walk_codegen_uint(p: &mut P, cx: &Context, items: &[DefId]) { + items.iter().for_each(|def_id| { + CUR_ITEM.set(def_id, || { + let node = cx.node(*def_id).unwrap(); + + match &node.kind { + NodeKind::Item(item) => p.on_item(cx, *def_id, item.clone()), + _ => {} + } + }); + }); +} + pub fn walk_field( _p: &mut P, _cx: &Context, diff --git a/pilota-build/test_data/plugin/serde.rs b/pilota-build/test_data/plugin/serde.rs index 168fc6b9..682543b1 100644 --- a/pilota-build/test_data/plugin/serde.rs +++ b/pilota-build/test_data/plugin/serde.rs @@ -93,21 +93,17 @@ pub mod serde { protocol.read_struct_end()?; let Some(a) = a else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field a is required".to_string() - ) - ) - }; + "field a is required".to_string(), + )); + }; let Some(b) = b else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field b is required".to_string() - ) - ) - }; + "field b is required".to_string(), + )); + }; let data = Self { a, b }; Ok(data) @@ -164,21 +160,17 @@ pub mod serde { protocol.read_struct_end().await?; let Some(a) = a else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field a is required".to_string() - ) - ) - }; + "field a is required".to_string(), + )); + }; let Some(b) = b else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field b is required".to_string() - ) - ) - }; + "field b is required".to_string(), + )); + }; let data = Self { a, b }; Ok(data) diff --git a/pilota-build/test_data/thrift/binary_bytes.rs b/pilota-build/test_data/thrift/binary_bytes.rs index 064f71fa..717a64f4 100644 --- a/pilota-build/test_data/thrift/binary_bytes.rs +++ b/pilota-build/test_data/thrift/binary_bytes.rs @@ -83,21 +83,17 @@ pub mod binary_bytes { protocol.read_struct_end()?; let Some(bytes) = bytes else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field bytes is required".to_string() - ) - ) - }; + "field bytes is required".to_string(), + )); + }; let Some(vec) = vec else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field vec is required".to_string() - ) - ) - }; + "field vec is required".to_string(), + )); + }; let data = Self { bytes, vec }; Ok(data) @@ -156,21 +152,17 @@ pub mod binary_bytes { protocol.read_struct_end().await?; let Some(bytes) = bytes else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field bytes is required".to_string() - ) - ) - }; + "field bytes is required".to_string(), + )); + }; let Some(vec) = vec else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field vec is required".to_string() - ) - ) - }; + "field vec is required".to_string(), + )); + }; let data = Self { bytes, vec }; Ok(data) diff --git a/pilota-build/test_data/thrift/decode_error.rs b/pilota-build/test_data/thrift/decode_error.rs index c5965e31..9f7ed21b 100644 --- a/pilota-build/test_data/thrift/decode_error.rs +++ b/pilota-build/test_data/thrift/decode_error.rs @@ -74,13 +74,11 @@ pub mod decode_error { protocol.read_struct_end()?; let Some(b) = b else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field b is required".to_string() - ) - ) - }; + "field b is required".to_string(), + )); + }; let data = Self { b }; Ok(data) @@ -133,13 +131,11 @@ pub mod decode_error { protocol.read_struct_end().await?; let Some(b) = b else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field b is required".to_string() - ) - ) - }; + "field b is required".to_string(), + )); + }; let data = Self { b }; Ok(data) @@ -226,13 +222,11 @@ pub mod decode_error { protocol.read_struct_end()?; let Some(a) = a else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field a is required".to_string() - ) - ) - }; + "field a is required".to_string(), + )); + }; let data = Self { a }; Ok(data) @@ -285,13 +279,11 @@ pub mod decode_error { protocol.read_struct_end().await?; let Some(a) = a else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field a is required".to_string() - ) - ) - }; + "field a is required".to_string(), + )); + }; let data = Self { a }; Ok(data) @@ -378,13 +370,11 @@ pub mod decode_error { protocol.read_struct_end()?; let Some(c) = c else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field c is required".to_string() - ) - ) - }; + "field c is required".to_string(), + )); + }; let data = Self { c }; Ok(data) @@ -437,13 +427,11 @@ pub mod decode_error { protocol.read_struct_end().await?; let Some(c) = c else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field c is required".to_string() - ) - ) - }; + "field c is required".to_string(), + )); + }; let data = Self { c }; Ok(data) diff --git a/pilota-build/test_data/thrift/normal.rs b/pilota-build/test_data/thrift/normal.rs index 8992bc66..6f962964 100644 --- a/pilota-build/test_data/thrift/normal.rs +++ b/pilota-build/test_data/thrift/normal.rs @@ -442,37 +442,29 @@ pub mod normal { protocol.read_struct_end()?; let Some(msg) = msg else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field msg is required".to_string() - ) - ) - }; + "field msg is required".to_string(), + )); + }; let Some(msg_map) = msg_map else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field msg_map is required".to_string() - ) - ) - }; + "field msg_map is required".to_string(), + )); + }; let Some(sub_msgs) = sub_msgs else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field sub_msgs is required".to_string() - ) - ) - }; + "field sub_msgs is required".to_string(), + )); + }; let Some(flag_msg) = flag_msg else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field flag_msg is required".to_string() - ) - ) - }; + "field flag_msg is required".to_string(), + )); + }; let data = Self { msg, @@ -594,37 +586,29 @@ pub mod normal { protocol.read_struct_end().await?; let Some(msg) = msg else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field msg is required".to_string() - ) - ) - }; + "field msg is required".to_string(), + )); + }; let Some(msg_map) = msg_map else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field msg_map is required".to_string() - ) - ) - }; + "field msg_map is required".to_string(), + )); + }; let Some(sub_msgs) = sub_msgs else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field sub_msgs is required".to_string() - ) - ) - }; + "field sub_msgs is required".to_string(), + )); + }; let Some(flag_msg) = flag_msg else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field flag_msg is required".to_string() - ) - ) - }; + "field flag_msg is required".to_string(), + )); + }; let data = Self { msg, @@ -889,13 +873,11 @@ pub mod normal { protocol.read_struct_end()?; let Some(req) = req else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field req is required".to_string() - ) - ) - }; + "field req is required".to_string(), + )); + }; let data = Self { req }; Ok(data) @@ -952,13 +934,11 @@ pub mod normal { protocol.read_struct_end().await?; let Some(req) = req else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field req is required".to_string() - ) - ) - }; + "field req is required".to_string(), + )); + }; let data = Self { req }; Ok(data) @@ -1554,13 +1534,11 @@ pub mod normal { protocol.read_struct_end()?; let Some(req) = req else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field req is required".to_string() - ) - ) - }; + "field req is required".to_string(), + )); + }; let data = Self { req }; Ok(data) @@ -1617,13 +1595,11 @@ pub mod normal { protocol.read_struct_end().await?; let Some(req) = req else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field req is required".to_string() - ) - ) - }; + "field req is required".to_string(), + )); + }; let data = Self { req }; Ok(data) diff --git a/pilota-build/test_data/thrift/pilota_name.rs b/pilota-build/test_data/thrift/pilota_name.rs index 401fe48e..7cac951c 100644 --- a/pilota-build/test_data/thrift/pilota_name.rs +++ b/pilota-build/test_data/thrift/pilota_name.rs @@ -74,13 +74,11 @@ pub mod pilota_name { protocol.read_struct_end()?; let Some(id) = id else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field id is required".to_string() - ) - ) - }; + "field id is required".to_string(), + )); + }; let data = Self { id }; Ok(data) @@ -133,13 +131,11 @@ pub mod pilota_name { protocol.read_struct_end().await?; let Some(id) = id else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field id is required".to_string() - ) - ) - }; + "field id is required".to_string(), + )); + }; let data = Self { id }; Ok(data) @@ -231,13 +227,11 @@ pub mod pilota_name { protocol.read_struct_end()?; let Some(req) = req else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field req is required".to_string() - ) - ) - }; + "field req is required".to_string(), + )); + }; let data = Self { req }; Ok(data) @@ -294,13 +288,11 @@ pub mod pilota_name { protocol.read_struct_end().await?; let Some(req) = req else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field req is required".to_string() - ) - ) - }; + "field req is required".to_string(), + )); + }; let data = Self { req }; Ok(data) @@ -527,21 +519,17 @@ pub mod pilota_name { protocol.read_struct_end()?; let Some(id) = id else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field id is required".to_string() - ) - ) - }; + "field id is required".to_string(), + )); + }; let Some(hello) = hello else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field hello is required".to_string() - ) - ) - }; + "field hello is required".to_string(), + )); + }; let data = Self { id, hello }; Ok(data) @@ -600,21 +588,17 @@ pub mod pilota_name { protocol.read_struct_end().await?; let Some(id) = id else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field id is required".to_string() - ) - ) - }; + "field id is required".to_string(), + )); + }; let Some(hello) = hello else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field hello is required".to_string() - ) - ) - }; + "field hello is required".to_string(), + )); + }; let data = Self { id, hello }; Ok(data) @@ -707,13 +691,11 @@ pub mod pilota_name { protocol.read_struct_end()?; let Some(req) = req else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field req is required".to_string() - ) - ) - }; + "field req is required".to_string(), + )); + }; let data = Self { req }; Ok(data) @@ -770,13 +752,11 @@ pub mod pilota_name { protocol.read_struct_end().await?; let Some(req) = req else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field req is required".to_string() - ) - ) - }; + "field req is required".to_string(), + )); + }; let data = Self { req }; Ok(data) diff --git a/pilota-build/test_data/thrift/self_kw.rs b/pilota-build/test_data/thrift/self_kw.rs index c05655a9..51b04208 100644 --- a/pilota-build/test_data/thrift/self_kw.rs +++ b/pilota-build/test_data/thrift/self_kw.rs @@ -154,13 +154,11 @@ pub mod self_kw { protocol.read_struct_end()?; let Some(r#type) = r#type else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field r#type is required".to_string() - ) - ) - }; + "field r#type is required".to_string(), + )); + }; let data = Self { r#type }; Ok(data) @@ -213,13 +211,11 @@ pub mod self_kw { protocol.read_struct_end().await?; let Some(r#type) = r#type else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field r#type is required".to_string() - ) - ) - }; + "field r#type is required".to_string(), + )); + }; let data = Self { r#type }; Ok(data) diff --git a/pilota-build/test_data/thrift/string.rs b/pilota-build/test_data/thrift/string.rs index b19c4574..cd8c2fcc 100644 --- a/pilota-build/test_data/thrift/string.rs +++ b/pilota-build/test_data/thrift/string.rs @@ -83,21 +83,17 @@ pub mod string { protocol.read_struct_end()?; let Some(faststr) = faststr else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field faststr is required".to_string() - ) - ) - }; + "field faststr is required".to_string(), + )); + }; let Some(string) = string else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field string is required".to_string() - ) - ) - }; + "field string is required".to_string(), + )); + }; let data = Self { faststr, string }; Ok(data) @@ -156,21 +152,17 @@ pub mod string { protocol.read_struct_end().await?; let Some(faststr) = faststr else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field faststr is required".to_string() - ) - ) - }; + "field faststr is required".to_string(), + )); + }; let Some(string) = string else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field string is required".to_string() - ) - ) - }; + "field string is required".to_string(), + )); + }; let data = Self { faststr, string }; Ok(data) diff --git a/pilota-build/test_data/thrift/wrapper_arc.rs b/pilota-build/test_data/thrift/wrapper_arc.rs index 3a24e6da..7cabf696 100644 --- a/pilota-build/test_data/thrift/wrapper_arc.rs +++ b/pilota-build/test_data/thrift/wrapper_arc.rs @@ -328,13 +328,11 @@ pub mod wrapper_arc { protocol.read_struct_end()?; let Some(req) = req else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field req is required".to_string() - ) - ) - }; + "field req is required".to_string(), + )); + }; let data = Self { req }; Ok(data) @@ -391,13 +389,11 @@ pub mod wrapper_arc { protocol.read_struct_end().await?; let Some(req) = req else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field req is required".to_string() - ) - ) - }; + "field req is required".to_string(), + )); + }; let data = Self { req }; Ok(data) @@ -718,29 +714,23 @@ pub mod wrapper_arc { protocol.read_struct_end()?; let Some(id) = id else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field id is required".to_string() - ) - ) - }; + "field id is required".to_string(), + )); + }; let Some(name2) = name2 else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field name2 is required".to_string() - ) - ) - }; + "field name2 is required".to_string(), + )); + }; let Some(name3) = name3 else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field name3 is required".to_string() - ) - ) - }; + "field name3 is required".to_string(), + )); + }; let data = Self { id, name2, name3 }; Ok(data) @@ -844,29 +834,23 @@ pub mod wrapper_arc { protocol.read_struct_end().await?; let Some(id) = id else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field id is required".to_string() - ) - ) - }; + "field id is required".to_string(), + )); + }; let Some(name2) = name2 else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field name2 is required".to_string() - ) - ) - }; + "field name2 is required".to_string(), + )); + }; let Some(name3) = name3 else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field name3 is required".to_string() - ) - ) - }; + "field name3 is required".to_string(), + )); + }; let data = Self { id, name2, name3 }; Ok(data) @@ -986,13 +970,11 @@ pub mod wrapper_arc { protocol.read_struct_end()?; let Some(req) = req else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field req is required".to_string() - ) - ) - }; + "field req is required".to_string(), + )); + }; let data = Self { req }; Ok(data) @@ -1050,13 +1032,11 @@ pub mod wrapper_arc { protocol.read_struct_end().await?; let Some(req) = req else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field req is required".to_string() - ) - ) - }; + "field req is required".to_string(), + )); + }; let data = Self { req }; Ok(data) diff --git a/pilota-build/test_data/unknown_fields.rs b/pilota-build/test_data/unknown_fields.rs index 5b21337a..93b26147 100644 --- a/pilota-build/test_data/unknown_fields.rs +++ b/pilota-build/test_data/unknown_fields.rs @@ -437,21 +437,17 @@ pub mod unknown_fields { protocol.read_struct_end()?; let Some(bytes) = bytes else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field bytes is required".to_string() - ) - ) - }; + "field bytes is required".to_string(), + )); + }; let Some(vec) = vec else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field vec is required".to_string() - ) - ) - }; + "field vec is required".to_string(), + )); + }; let data = Self { bytes, @@ -514,21 +510,17 @@ pub mod unknown_fields { protocol.read_struct_end().await?; let Some(bytes) = bytes else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field bytes is required".to_string() - ) - ) - }; + "field bytes is required".to_string(), + )); + }; let Some(vec) = vec else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field vec is required".to_string() - ) - ) - }; + "field vec is required".to_string(), + )); + }; let data = Self { bytes, @@ -642,13 +634,11 @@ pub mod unknown_fields { protocol.read_struct_end()?; let Some(td) = td else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field td is required".to_string() - ) - ) - }; + "field td is required".to_string(), + )); + }; let data = Self { td, @@ -702,13 +692,11 @@ pub mod unknown_fields { protocol.read_struct_end().await?; let Some(td) = td else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field td is required".to_string() - ) - ) - }; + "field td is required".to_string(), + )); + }; let data = Self { td, @@ -1015,29 +1003,23 @@ pub mod unknown_fields { protocol.read_struct_end()?; let Some(faststr) = faststr else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field faststr is required".to_string() - ) - ) - }; + "field faststr is required".to_string(), + )); + }; let Some(string) = string else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field string is required".to_string() - ) - ) - }; + "field string is required".to_string(), + )); + }; let Some(list) = list else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field list is required".to_string() - ) - ) - }; + "field list is required".to_string(), + )); + }; let data = Self { faststr, @@ -1121,29 +1103,23 @@ pub mod unknown_fields { protocol.read_struct_end().await?; let Some(faststr) = faststr else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field faststr is required".to_string() - ) - ) - }; + "field faststr is required".to_string(), + )); + }; let Some(string) = string else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field string is required".to_string() - ) - ) - }; + "field string is required".to_string(), + )); + }; let Some(list) = list else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field list is required".to_string() - ) - ) - }; + "field list is required".to_string(), + )); + }; let data = Self { faststr, @@ -1733,13 +1709,11 @@ pub mod unknown_fields { protocol.read_struct_end()?; let Some(a) = a else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field a is required".to_string() - ) - ) - }; + "field a is required".to_string(), + )); + }; let data = Self { a, _unknown_fields }; Ok(data) @@ -1792,13 +1766,11 @@ pub mod unknown_fields { protocol.read_struct_end().await?; let Some(a) = a else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field a is required".to_string() - ) - ) - }; + "field a is required".to_string(), + )); + }; let data = Self { a, @@ -2852,13 +2824,11 @@ pub mod unknown_fields { protocol.read_struct_end()?; let Some(req) = req else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field req is required".to_string() - ) - ) - }; + "field req is required".to_string(), + )); + }; let data = Self { req }; Ok(data) @@ -2915,13 +2885,11 @@ pub mod unknown_fields { protocol.read_struct_end().await?; let Some(req) = req else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field req is required".to_string() - ) - ) - }; + "field req is required".to_string(), + )); + }; let data = Self { req }; Ok(data) @@ -3236,13 +3204,11 @@ pub mod unknown_fields { protocol.read_struct_end()?; let Some(req) = req else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field req is required".to_string() - ) - ) - }; + "field req is required".to_string(), + )); + }; let data = Self { req }; Ok(data) @@ -3299,13 +3265,11 @@ pub mod unknown_fields { protocol.read_struct_end().await?; let Some(req) = req else { - return Err( - ::pilota::thrift::DecodeError::new( + return Err(::pilota::thrift::DecodeError::new( ::pilota::thrift::DecodeErrorKind::InvalidData, - "field req is required".to_string() - ) - ) - }; + "field req is required".to_string(), + )); + }; let data = Self { req }; Ok(data)