Skip to content

Commit

Permalink
Use qualified path for Result::Ok in bincode_derive (#757)
Browse files Browse the repository at this point in the history
* Use qualified path for Result::Ok in bincode_derive

* add test
  • Loading branch information
nhaef authored Mar 10, 2025
1 parent dd3feea commit bd99729
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
6 changes: 3 additions & 3 deletions derive/src/derive_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl DeriveEnum {
}
}
}
body.push_parsed("Ok(())")?;
body.push_parsed("core::result::Result::Ok(())")?;
Ok(())
})?;
match_body.punct(',');
Expand Down Expand Up @@ -274,7 +274,7 @@ impl DeriveEnum {
variant_case.push(variant_index.remove(0));
}
variant_case.puncts("=>");
variant_case.ident_str("Ok");
variant_case.push_parsed("core::result::Result::Ok")?;
variant_case.group(Delimiter::Parenthesis, |variant_case_body| {
// Self::Variant { }
// Self::Variant { 0: ..., 1: ... 2: ... },
Expand Down Expand Up @@ -384,7 +384,7 @@ impl DeriveEnum {
variant_case.push(variant_index.remove(0));
}
variant_case.puncts("=>");
variant_case.ident_str("Ok");
variant_case.push_parsed("core::result::Result::Ok")?;
variant_case.group(Delimiter::Parenthesis, |variant_case_body| {
// Self::Variant { }
// Self::Variant { 0: ..., 1: ... 2: ... },
Expand Down
6 changes: 3 additions & 3 deletions derive/src/derive_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl DeriveStruct {
}
}
}
fn_body.push_parsed("Ok(())")?;
fn_body.push_parsed("core::result::Result::Ok(())")?;
Ok(())
})?;
Ok(())
Expand Down Expand Up @@ -95,7 +95,7 @@ impl DeriveStruct {
.with_return_type(format!("core::result::Result<Self, {}::error::DecodeError>", crate_name))
.body(|fn_body| {
// Ok(Self {
fn_body.ident_str("Ok");
fn_body.push_parsed("core::result::Result::Ok")?;
fn_body.group(Delimiter::Parenthesis, |ok_group| {
ok_group.ident_str("Self");
ok_group.group(Delimiter::Brace, |struct_body| {
Expand Down Expand Up @@ -174,7 +174,7 @@ impl DeriveStruct {
.with_return_type(format!("core::result::Result<Self, {}::error::DecodeError>", crate_name))
.body(|fn_body| {
// Ok(Self {
fn_body.ident_str("Ok");
fn_body.push_parsed("core::result::Result::Ok")?;
fn_body.group(Delimiter::Parenthesis, |ok_group| {
ok_group.ident_str("Self");
ok_group.group(Delimiter::Brace, |struct_body| {
Expand Down
17 changes: 17 additions & 0 deletions tests/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,23 @@ fn test_enum_with_generics_roundtrip() {
assert_eq!(start, decoded);
}

mod derive_with_polluted_scope {
#[allow(dead_code)]
#[allow(non_snake_case)]
fn Ok() {}

#[derive(bincode::Encode, bincode::Decode)]
struct A {
a: u32,
}

#[derive(bincode::Encode, bincode::Decode)]
enum B {
A,
B,
}
}

#[cfg(feature = "alloc")]
mod zoxide {
extern crate alloc;
Expand Down

0 comments on commit bd99729

Please sign in to comment.