Skip to content

Commit

Permalink
panic if FastStr wrapped by Arc
Browse files Browse the repository at this point in the history
  • Loading branch information
LYF1999 committed Dec 14, 2022
1 parent 06d3a7e commit 2f8d52b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions pilota-build/src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ impl Resolver {
impl Folder for ArcFolder<'_> {
fn fold_ty(&mut self, ty: &Ty) -> Ty {
let kind = match &ty.kind {
TyKind::FastStr => panic!("faststr can not be wrapped by Arc"),
TyKind::Bool => panic!("bool can not be wrapped by Arc"),
TyKind::Vec(inner) => TyKind::Vec(Arc::new(self.fold_ty(inner.as_ref()))),
TyKind::Set(inner) => TyKind::Set(Arc::new(self.fold_ty(inner.as_ref()))),
TyKind::Map(k, v) => {
Expand Down
6 changes: 3 additions & 3 deletions pilota-build/test_data/thrift/wrapper_arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub mod wrapper_arc {
pub mod wrapper_arc {
#[derive(Debug, Default, Clone, PartialEq)]
pub struct Test {
pub id: ::std::sync::Arc<::pilota::FastStr>,
pub id: ::pilota::FastStr,
pub name2: ::std::vec::Vec<::std::vec::Vec<::std::sync::Arc<i32>>>,
pub name3: ::std::collections::HashMap<i32, ::std::vec::Vec<::std::sync::Arc<i32>>>,
}
Expand Down Expand Up @@ -86,7 +86,7 @@ pub mod wrapper_arc {
let field_id = field_ident.id;
match field_id {
Some(1i16) if field_ident.field_type == ::pilota::thrift::TType::Binary => {
id = Some(Arc::new(protocol.read_faststr()?));
id = Some(protocol.read_faststr()?);
}
Some(2i16) if field_ident.field_type == ::pilota::thrift::TType::List => {
name2 = Some({
Expand Down Expand Up @@ -188,7 +188,7 @@ pub mod wrapper_arc {
let field_id = field_ident.id;
match field_id {
Some(1i16) if field_ident.field_type == ::pilota::thrift::TType::Binary => {
id = Some(Arc::new(protocol.read_faststr().await?));
id = Some(protocol.read_faststr().await?);
}
Some(2i16) if field_ident.field_type == ::pilota::thrift::TType::List => {
name2 = Some({
Expand Down
2 changes: 1 addition & 1 deletion pilota-build/test_data/thrift/wrapper_arc.thrift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
struct TEST {
1: required string ID(pilota.rust_wrapper_arc="true"),
1: required string ID,
2: required list<list<i32>> Name2(pilota.rust_wrapper_arc="true"),
3: required map<i32, list<i32>> Name3(pilota.rust_wrapper_arc="true"),
}
Expand Down

0 comments on commit 2f8d52b

Please sign in to comment.