From bbfd0c9bb7adaa9eafa680a1cfc6de704efcc225 Mon Sep 17 00:00:00 2001 From: nhaef <nico.haefele@sap.com> Date: Mon, 10 Mar 2025 12:32:34 +0100 Subject: [PATCH 1/2] Use qualified path for Result::Ok in bincode_derive --- derive/src/derive_enum.rs | 6 +++--- derive/src/derive_struct.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/derive/src/derive_enum.rs b/derive/src/derive_enum.rs index 36a95858..c93ac8ec 100644 --- a/derive/src/derive_enum.rs +++ b/derive/src/derive_enum.rs @@ -124,7 +124,7 @@ impl DeriveEnum { } } } - body.push_parsed("Ok(())")?; + body.push_parsed("core::result::Result::Ok(())")?; Ok(()) })?; match_body.punct(','); @@ -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: ... }, @@ -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: ... }, diff --git a/derive/src/derive_struct.rs b/derive/src/derive_struct.rs index 6908dab1..93a63a0f 100644 --- a/derive/src/derive_struct.rs +++ b/derive/src/derive_struct.rs @@ -56,7 +56,7 @@ impl DeriveStruct { } } } - fn_body.push_parsed("Ok(())")?; + fn_body.push_parsed("core::result::Result::Ok(())")?; Ok(()) })?; Ok(()) @@ -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| { @@ -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| { From 476d0a07e5ac4c327e1f1a5d65d6ac689cbc8818 Mon Sep 17 00:00:00 2001 From: nhaef <nico.haefele@sap.com> Date: Mon, 10 Mar 2025 13:06:43 +0100 Subject: [PATCH 2/2] add test --- tests/derive.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/derive.rs b/tests/derive.rs index b2a23793..693aec5f 100644 --- a/tests/derive.rs +++ b/tests/derive.rs @@ -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;