Skip to content

Commit c544698

Browse files
committed
Remove Option param from Message::descriptor_static function.
It is no longer needed in modern Rust.
1 parent 8723fca commit c544698

16 files changed

Lines changed: 113 additions & 114 deletions

File tree

protobuf-codegen/src/message.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ impl<'a> MessageGen<'a> {
256256
}
257257

258258
fn write_descriptor_static(&self, w: &mut CodeWriter) {
259-
w.def_fn(&format!("descriptor_static(_: ::std::option::Option<{}>) -> &'static ::protobuf::reflect::MessageDescriptor", self.type_name), |w| {
259+
w.def_fn(&format!("descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor"), |w| {
260260
w.lazy_static_decl_get("descriptor", "::protobuf::reflect::MessageDescriptor", |w| {
261261
let fields = self.fields_except_group();
262262
if fields.is_empty() {
@@ -332,7 +332,7 @@ impl<'a> MessageGen<'a> {
332332
});
333333
w.write_line("");
334334
w.def_fn("descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor", |w| {
335-
w.write_line("::protobuf::Message::descriptor_static(None::<Self>)");
335+
w.write_line("Self::descriptor_static()");
336336
});
337337
w.write_line("");
338338
w.def_fn(&format!("new() -> {}", self.type_name), |w| {

protobuf-test-common/src/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn test_serialize_deserialize<M : Message + PartialEq>(hex: &str, msg: &M) {
2424
expected_hex,
2525
serialized_hex,
2626
"message {}",
27-
M::descriptor_static(None).name()
27+
M::descriptor_static().name()
2828
);
2929
let parsed = parse_from_bytes::<M>(&expected_bytes).unwrap();
3030
assert_eq!(*msg, parsed);

protobuf/src/core.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,7 @@ pub trait Message: fmt::Debug + Clear + Any + Send + Sync {
168168
fn new() -> Self where Self : Sized;
169169

170170
/// Get message descriptor for message type.
171-
// http://stackoverflow.com/q/20342436/15018
172-
fn descriptor_static(_: Option<Self>) -> &'static MessageDescriptor
171+
fn descriptor_static() -> &'static MessageDescriptor
173172
where Self : Sized
174173
{
175174
panic!(

protobuf/src/descriptor.rs

Lines changed: 50 additions & 50 deletions
Large diffs are not rendered by default.

protobuf/src/plugin.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,14 @@ impl ::protobuf::Message for CodeGeneratorRequest {
213213
}
214214

215215
fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor {
216-
::protobuf::Message::descriptor_static(None::<Self>)
216+
Self::descriptor_static()
217217
}
218218

219219
fn new() -> CodeGeneratorRequest {
220220
CodeGeneratorRequest::new()
221221
}
222222

223-
fn descriptor_static(_: ::std::option::Option<CodeGeneratorRequest>) -> &'static ::protobuf::reflect::MessageDescriptor {
223+
fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor {
224224
static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy {
225225
lock: ::protobuf::lazy::ONCE_INIT,
226226
ptr: 0 as *const ::protobuf::reflect::MessageDescriptor,
@@ -441,14 +441,14 @@ impl ::protobuf::Message for CodeGeneratorResponse {
441441
}
442442

443443
fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor {
444-
::protobuf::Message::descriptor_static(None::<Self>)
444+
Self::descriptor_static()
445445
}
446446

447447
fn new() -> CodeGeneratorResponse {
448448
CodeGeneratorResponse::new()
449449
}
450450

451-
fn descriptor_static(_: ::std::option::Option<CodeGeneratorResponse>) -> &'static ::protobuf::reflect::MessageDescriptor {
451+
fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor {
452452
static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy {
453453
lock: ::protobuf::lazy::ONCE_INIT,
454454
ptr: 0 as *const ::protobuf::reflect::MessageDescriptor,
@@ -712,14 +712,14 @@ impl ::protobuf::Message for CodeGeneratorResponse_File {
712712
}
713713

714714
fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor {
715-
::protobuf::Message::descriptor_static(None::<Self>)
715+
Self::descriptor_static()
716716
}
717717

718718
fn new() -> CodeGeneratorResponse_File {
719719
CodeGeneratorResponse_File::new()
720720
}
721721

722-
fn descriptor_static(_: ::std::option::Option<CodeGeneratorResponse_File>) -> &'static ::protobuf::reflect::MessageDescriptor {
722+
fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor {
723723
static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy {
724724
lock: ::protobuf::lazy::ONCE_INIT,
725725
ptr: 0 as *const ::protobuf::reflect::MessageDescriptor,

protobuf/src/reflect/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub struct MessageDescriptor {
154154

155155
impl MessageDescriptor {
156156
pub fn for_type<M : Message>() -> &'static MessageDescriptor {
157-
Message::descriptor_static(None::<M>)
157+
M::descriptor_static()
158158
}
159159

160160
pub fn new<M : 'static + Message + Default>(

protobuf/src/well_known_types/any.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,14 @@ impl ::protobuf::Message for Any {
161161
}
162162

163163
fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor {
164-
::protobuf::Message::descriptor_static(None::<Self>)
164+
Self::descriptor_static()
165165
}
166166

167167
fn new() -> Any {
168168
Any::new()
169169
}
170170

171-
fn descriptor_static(_: ::std::option::Option<Any>) -> &'static ::protobuf::reflect::MessageDescriptor {
171+
fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor {
172172
static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy {
173173
lock: ::protobuf::lazy::ONCE_INIT,
174174
ptr: 0 as *const ::protobuf::reflect::MessageDescriptor,

protobuf/src/well_known_types/api.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,14 +366,14 @@ impl ::protobuf::Message for Api {
366366
}
367367

368368
fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor {
369-
::protobuf::Message::descriptor_static(None::<Self>)
369+
Self::descriptor_static()
370370
}
371371

372372
fn new() -> Api {
373373
Api::new()
374374
}
375375

376-
fn descriptor_static(_: ::std::option::Option<Api>) -> &'static ::protobuf::reflect::MessageDescriptor {
376+
fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor {
377377
static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy {
378378
lock: ::protobuf::lazy::ONCE_INIT,
379379
ptr: 0 as *const ::protobuf::reflect::MessageDescriptor,
@@ -763,14 +763,14 @@ impl ::protobuf::Message for Method {
763763
}
764764

765765
fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor {
766-
::protobuf::Message::descriptor_static(None::<Self>)
766+
Self::descriptor_static()
767767
}
768768

769769
fn new() -> Method {
770770
Method::new()
771771
}
772772

773-
fn descriptor_static(_: ::std::option::Option<Method>) -> &'static ::protobuf::reflect::MessageDescriptor {
773+
fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor {
774774
static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy {
775775
lock: ::protobuf::lazy::ONCE_INIT,
776776
ptr: 0 as *const ::protobuf::reflect::MessageDescriptor,
@@ -998,14 +998,14 @@ impl ::protobuf::Message for Mixin {
998998
}
999999

10001000
fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor {
1001-
::protobuf::Message::descriptor_static(None::<Self>)
1001+
Self::descriptor_static()
10021002
}
10031003

10041004
fn new() -> Mixin {
10051005
Mixin::new()
10061006
}
10071007

1008-
fn descriptor_static(_: ::std::option::Option<Mixin>) -> &'static ::protobuf::reflect::MessageDescriptor {
1008+
fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor {
10091009
static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy {
10101010
lock: ::protobuf::lazy::ONCE_INIT,
10111011
ptr: 0 as *const ::protobuf::reflect::MessageDescriptor,

protobuf/src/well_known_types/duration.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,14 @@ impl ::protobuf::Message for Duration {
147147
}
148148

149149
fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor {
150-
::protobuf::Message::descriptor_static(None::<Self>)
150+
Self::descriptor_static()
151151
}
152152

153153
fn new() -> Duration {
154154
Duration::new()
155155
}
156156

157-
fn descriptor_static(_: ::std::option::Option<Duration>) -> &'static ::protobuf::reflect::MessageDescriptor {
157+
fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor {
158158
static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy {
159159
lock: ::protobuf::lazy::ONCE_INIT,
160160
ptr: 0 as *const ::protobuf::reflect::MessageDescriptor,

protobuf/src/well_known_types/empty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ impl ::protobuf::Message for Empty {
8888
}
8989

9090
fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor {
91-
::protobuf::Message::descriptor_static(None::<Self>)
91+
Self::descriptor_static()
9292
}
9393

9494
fn new() -> Empty {
9595
Empty::new()
9696
}
9797

98-
fn descriptor_static(_: ::std::option::Option<Empty>) -> &'static ::protobuf::reflect::MessageDescriptor {
98+
fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor {
9999
static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy {
100100
lock: ::protobuf::lazy::ONCE_INIT,
101101
ptr: 0 as *const ::protobuf::reflect::MessageDescriptor,

0 commit comments

Comments
 (0)