Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes 905, fix: Use full path of Result type + unit test + Option unti test #917

Merged
merged 5 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{
devShells.default = pkgs.mkShell {
packages = with pkgs; [ cargo rustc ];
buildInputs = with pkgs; [ pkg-config protobuf curl ];
buildInputs = with pkgs; [ pkg-config protobuf curl cmake ninja ];
};
});
}
4 changes: 2 additions & 2 deletions prost-derive/src/field/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,14 @@ impl Field {
#[doc=#get_doc]
pub fn #get(&self, key: #key_ref_ty) -> ::core::option::Option<#ty> {
self.#ident.get(#take_ref key).cloned().and_then(|x| {
let result: Result<#ty, _> = ::core::convert::TryFrom::try_from(x);
let result: ::core::result::Result<#ty, _> = ::core::convert::TryFrom::try_from(x);
result.ok()
})
}
#[doc=#insert_doc]
pub fn #insert(&mut self, key: #key_ty, value: #ty) -> ::core::option::Option<#ty> {
self.#ident.insert(key, value as i32).and_then(|x| {
let result: Result<#ty, _> = ::core::convert::TryFrom::try_from(x);
let result: ::core::result::Result<#ty, _> = ::core::convert::TryFrom::try_from(x);
result.ok()
})
}
Expand Down
6 changes: 3 additions & 3 deletions prost-derive/src/field/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl Field {
struct #wrap_name<'a>(&'a i32);
impl<'a> ::core::fmt::Debug for #wrap_name<'a> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
let res: Result<#ty, _> = ::core::convert::TryFrom::try_from(*self.0);
let res: ::core::result::Result<#ty, _> = ::core::convert::TryFrom::try_from(*self.0);
match res {
Err(_) => ::core::fmt::Debug::fmt(&self.0, f),
Ok(en) => ::core::fmt::Debug::fmt(&en, f),
Expand Down Expand Up @@ -316,7 +316,7 @@ impl Field {
#[doc=#get_doc]
pub fn #get(&self) -> #ty {
self.#ident.and_then(|x| {
let result: Result<#ty, _> = ::core::convert::TryFrom::try_from(x);
let result: ::core::result::Result<#ty, _> = ::core::convert::TryFrom::try_from(x);
result.ok()
}).unwrap_or(#default)
}
Expand All @@ -341,7 +341,7 @@ impl Field {
fn(i32) -> ::core::option::Option<#ty>,
> {
self.#ident.iter().cloned().filter_map(|x| {
let result: Result<#ty, _> = ::core::convert::TryFrom::try_from(x);
let result: ::core::result::Result<#ty, _> = ::core::convert::TryFrom::try_from(x);
result.ok()
})
}
Expand Down
16 changes: 16 additions & 0 deletions tests/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ fn main() {
.compile_protos(&[src.join("custom_debug.proto")], includes)
.unwrap();

config
.compile_protos(&[src.join("result_enum.proto")], includes)
.unwrap();

config
.compile_protos(&[src.join("result_struct.proto")], includes)
.unwrap();

config
.compile_protos(&[src.join("option_enum.proto")], includes)
.unwrap();

config
.compile_protos(&[src.join("option_struct.proto")], includes)
.unwrap();

prost_build::Config::new()
.protoc_arg("--experimental_allow_proto3_optional")
.compile_protos(&[src.join("proto3_presence.proto")], includes)
Expand Down
18 changes: 16 additions & 2 deletions tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,22 @@ mod no_unused_results;
#[cfg(test)]
#[cfg(feature = "std")]
mod skip_debug;
#[cfg(test)]
mod well_known_types;

mod test_enum_named_option_value {
include!(concat!(env!("OUT_DIR"), "/myenum.optionn.rs"));
}

mod test_enum_named_result_value {
include!(concat!(env!("OUT_DIR"), "/myenum.result.rs"));
}

mod test_result_named_option_value {
include!(concat!(env!("OUT_DIR"), "/mystruct.optionn.rs"));
}

mod test_result_named_result_value {
include!(concat!(env!("OUT_DIR"), "/mystruct.result.rs"));
}

pub mod foo {
pub mod bar_baz {
Expand Down
3 changes: 3 additions & 0 deletions tests/src/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

include!(concat!(env!("OUT_DIR"), "/myenum.result.rs"));
include!(concat!(env!("OUT_DIR"), "/mymessage.result.rs"));
11 changes: 11 additions & 0 deletions tests/src/option_enum.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
syntax = "proto3";
package myenum.optionn;


enum Option {
HELLO = 0;
}

message FailMessage {
Option result = 1;
}
8 changes: 8 additions & 0 deletions tests/src/option_struct.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
syntax = "proto3";
package mystruct.optionn;


message Option {
string msg = 1;
}

11 changes: 11 additions & 0 deletions tests/src/result_enum.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
syntax = "proto3";
package myenum.result;


enum Result {
HELLO = 0;
}

message FailMessage {
Result result = 1;
}
8 changes: 8 additions & 0 deletions tests/src/result_struct.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
syntax = "proto3";
package mystruct.result;


message Result {
string msg = 1;
}