Skip to content

Commit c63c487

Browse files
committed
Rust: trim comments and fix test import
1 parent 6098b69 commit c63c487

2 files changed

Lines changed: 1 addition & 10 deletions

File tree

compiler/cpp/src/thrift/generate/t_rs_generator.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,7 +1704,6 @@ void t_rs_generator::render_struct_sync_read(const string& struct_name,
17041704
f_gen_ << indent() << rust_safe_field_id(tfield->get_key()) << " => {" << '\n';
17051705
indent_up();
17061706
if (is_union_field) {
1707-
// Catch EmptyUnion from unknown variants for forward compatibility.
17081707
// Use the resolved (non-Box) type since Box<T>::method() isn't valid syntax.
17091708
string resolved_type = to_rust_type(resolved);
17101709
bool is_boxed_union = to_rust_type(tfield->get_type()) != resolved_type;
@@ -1714,9 +1713,6 @@ void t_rs_generator::render_struct_sync_read(const string& struct_name,
17141713
indent_up();
17151714
f_gen_ << indent() << "Ok(val) => { " << struct_field_read_temp_variable(tfield) << " = Some(" << val_expr << "); }," << '\n';
17161715
f_gen_ << indent() << "Err(thrift::Error::Protocol(ref e)) if e.kind == ProtocolErrorKind::EmptyUnion => {" << '\n';
1717-
indent_up();
1718-
f_gen_ << indent() << "// forward compatibility: unknown union variant skipped" << '\n';
1719-
indent_down();
17201716
f_gen_ << indent() << "}," << '\n';
17211717
f_gen_ << indent() << "Err(e) => return Err(e)," << '\n';
17221718
indent_down();

lib/rs/test/src/lib.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ mod tests {
5757

5858
use thrift::protocol::{
5959
TBinaryInputProtocol, TBinaryOutputProtocol, TFieldIdentifier, TOutputProtocol,
60-
TStructIdentifier, TType,
60+
TSerializable, TStructIdentifier, TType,
6161
};
6262

6363
// Serialize AidKit with an unknown union variant (id=99), verify it deserializes as None.
@@ -71,19 +71,16 @@ mod tests {
7171
name: "AidKit".to_owned(),
7272
})
7373
.unwrap();
74-
// field 1: optional aid (union => Struct on wire)
7574
prot.write_field_begin(&TFieldIdentifier {
7675
name: None,
7776
field_type: TType::Struct,
7877
id: Some(1),
7978
})
8079
.unwrap();
81-
// inner union-as-struct
8280
prot.write_struct_begin(&TStructIdentifier {
8381
name: "MeasuringAids".to_owned(),
8482
})
8583
.unwrap();
86-
// unknown variant: use an id that doesn't exist (99), type i32
8784
prot.write_field_begin(&TFieldIdentifier {
8885
name: None,
8986
field_type: TType::I32,
@@ -94,13 +91,11 @@ mod tests {
9491
prot.write_field_end().unwrap();
9592
prot.write_field_stop().unwrap();
9693
prot.write_struct_end().unwrap();
97-
// end outer field
9894
prot.write_field_end().unwrap();
9995
prot.write_field_stop().unwrap();
10096
prot.write_struct_end().unwrap();
10197
}
10298

103-
// Read it back using generated code
10499
let read_cursor = Cursor::new(write_buf);
105100
let mut rprot = TBinaryInputProtocol::new(read_cursor, false);
106101
let kit = base_one::AidKit::read_from_in_protocol(&mut rprot)

0 commit comments

Comments
 (0)