Skip to content

Commit

Permalink
fix: remove unused oneof_decl (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
LYF1999 authored Nov 25, 2022
1 parent ea8d379 commit bb657f7
Showing 1 changed file with 39 additions and 34 deletions.
73 changes: 39 additions & 34 deletions pilota-build/src/parser/protobuf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,30 +204,46 @@ impl Lower {

let mut nested_items: Vec<_> = Default::default();

let mut extra_fields = Vec::default();

message.oneof_decl.iter().enumerate().for_each(|(idx, d)| {
let fields = oneof_fields.remove(&(idx as i32)).unwrap();
nested_items.push(Arc::new(ir::Item {
related_items: Default::default(),
tags: Arc::new(crate::tags!(OneOf)),
kind: ir::ItemKind::Enum(ir::Enum {
if let Some(fields) = oneof_fields.remove(&(idx as i32)) {
nested_items.push(Arc::new(ir::Item {
related_items: Default::default(),
tags: Arc::new(crate::tags!(OneOf)),
kind: ir::ItemKind::Enum(ir::Enum {
name: d.name().into(),
repr: None,
variants: fields
.iter()
.map(|f| ir::EnumVariant {
discr: None,
id: f.number,
name: f.name().into(),
fields: vec![self.lower_ty(
f.type_,
f.type_name.as_deref(),
&nested_messages,
)],
tags: Default::default(),
})
.collect_vec(),
}),
}));

extra_fields.push(ir::Field {
name: d.name().into(),
repr: None,
variants: fields
.iter()
.map(|f| ir::EnumVariant {
discr: None,
id: f.number,
name: f.name().into(),
fields: vec![self.lower_ty(
f.type_,
f.type_name.as_deref(),
&nested_messages,
)],
tags: Default::default(),
})
.collect_vec(),
}),
}));
id: -1,
ty: ir::Ty {
kind: ir::TyKind::Path(Path {
segments: Arc::from([d.name().into()]),
}),
tags: Default::default(),
},
tags: Arc::new(crate::tags!(OneOf)),
kind: ir::FieldKind::Optional,
});
}
});

parent_messages.push(message.name().into());
Expand Down Expand Up @@ -286,18 +302,7 @@ impl Lower {
},
}
})
.chain(message.oneof_decl.iter().map(|d| ir::Field {
name: d.name().into(),
id: -1,
ty: ir::Ty {
kind: ir::TyKind::Path(Path {
segments: Arc::from([d.name().into()]),
}),
tags: Default::default(),
},
tags: Arc::new(crate::tags!(OneOf)),
kind: ir::FieldKind::Optional,
}))
.chain(extra_fields)
.collect(),
name: message.name().into(),
}),
Expand Down

0 comments on commit bb657f7

Please sign in to comment.