Message fields that had lifetimes, but which were deprecated, were still contributing their lifetime parameters into the system. For example, the following .proto file:
message ThisShouldNotHaveALifetimeParameter {
optional string dep = 1 [deprecated=true]; // since deprecated, should not cause lifetime parameter
}
Would cause the following faulty rust struct to be generated:
Adding an extra condition to the check in has_lifetime() in message.rs fixes this:
let res = self
.all_fields()
- .any(|f| f.typ.has_lifetime(desc, f.packed(), ignore));
+ .any(|f| f.typ.has_lifetime(desc, f.packed(), ignore) && (!f.deprecated || config.add_deprecated_fields));
ignore.pop();
res
This necessitated config: &Config to be passed as parameters to many functions within types.rs.
Test cases were also added that would check for the absence of lifetime parameter by using the trybuild crate to assert a compilation failure (fails when the lifetime parameter is added).
Duplication
Some test files (test_deprecated_lifetime.rs, test_deprecated_lifetime_pb.proto, etc.) have been duplicated for both v2 and v3. I couldn't find a way to combine them (e.g. under common) in a way that would meaningfully decrease duplication, while still keeping separate tests for v2 and v3 (do let me know if I'm missing something).
Hex
Small addition to hex.rs to help type inference.
Version number and Dependencies
pb-rs updated to 0.9.2quick-protobuf not updated, since trybuild is a dev-dependency and should not affect public API
Problem
Message fields that had lifetimes, but which were deprecated, were still contributing their lifetime parameters into the system. For example, the following
.proto
file:Would cause the following faulty rust struct to be generated:
Solution
Adding an extra condition to the check in
has_lifetime()
inmessage.rs
fixes this:This necessitated
config: &Config
to be passed as parameters to many functions withintypes.rs
.Test cases were also added that would check for the absence of lifetime parameter by using the
trybuild
crate to assert a compilation failure (fails when the lifetime parameter is added).Duplication
Some test files (
test_deprecated_lifetime.rs
,test_deprecated_lifetime_pb.proto
, etc.) have been duplicated for bothv2
andv3
. I couldn't find a way to combine them (e.g. undercommon
) in a way that would meaningfully decrease duplication, while still keeping separate tests forv2
andv3
(do let me know if I'm missing something).Hex
Small addition to
hex.rs
to help type inference.Version number and Dependencies
pb-rs
updated to0.9.2
quick-protobuf
not updated, sincetrybuild
is a dev-dependency and should not affect public API