Skip to content
This repository was archived by the owner on Aug 15, 2025. It is now read-only.

Commit bd99729

Browse files
authored
Use qualified path for Result::Ok in bincode_derive (#757)
* Use qualified path for Result::Ok in bincode_derive * add test
1 parent dd3feea commit bd99729

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

derive/src/derive_enum.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl DeriveEnum {
124124
}
125125
}
126126
}
127-
body.push_parsed("Ok(())")?;
127+
body.push_parsed("core::result::Result::Ok(())")?;
128128
Ok(())
129129
})?;
130130
match_body.punct(',');
@@ -274,7 +274,7 @@ impl DeriveEnum {
274274
variant_case.push(variant_index.remove(0));
275275
}
276276
variant_case.puncts("=>");
277-
variant_case.ident_str("Ok");
277+
variant_case.push_parsed("core::result::Result::Ok")?;
278278
variant_case.group(Delimiter::Parenthesis, |variant_case_body| {
279279
// Self::Variant { }
280280
// Self::Variant { 0: ..., 1: ... 2: ... },
@@ -384,7 +384,7 @@ impl DeriveEnum {
384384
variant_case.push(variant_index.remove(0));
385385
}
386386
variant_case.puncts("=>");
387-
variant_case.ident_str("Ok");
387+
variant_case.push_parsed("core::result::Result::Ok")?;
388388
variant_case.group(Delimiter::Parenthesis, |variant_case_body| {
389389
// Self::Variant { }
390390
// Self::Variant { 0: ..., 1: ... 2: ... },

derive/src/derive_struct.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl DeriveStruct {
5656
}
5757
}
5858
}
59-
fn_body.push_parsed("Ok(())")?;
59+
fn_body.push_parsed("core::result::Result::Ok(())")?;
6060
Ok(())
6161
})?;
6262
Ok(())
@@ -95,7 +95,7 @@ impl DeriveStruct {
9595
.with_return_type(format!("core::result::Result<Self, {}::error::DecodeError>", crate_name))
9696
.body(|fn_body| {
9797
// Ok(Self {
98-
fn_body.ident_str("Ok");
98+
fn_body.push_parsed("core::result::Result::Ok")?;
9999
fn_body.group(Delimiter::Parenthesis, |ok_group| {
100100
ok_group.ident_str("Self");
101101
ok_group.group(Delimiter::Brace, |struct_body| {
@@ -174,7 +174,7 @@ impl DeriveStruct {
174174
.with_return_type(format!("core::result::Result<Self, {}::error::DecodeError>", crate_name))
175175
.body(|fn_body| {
176176
// Ok(Self {
177-
fn_body.ident_str("Ok");
177+
fn_body.push_parsed("core::result::Result::Ok")?;
178178
fn_body.group(Delimiter::Parenthesis, |ok_group| {
179179
ok_group.ident_str("Self");
180180
ok_group.group(Delimiter::Brace, |struct_body| {

tests/derive.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,23 @@ fn test_enum_with_generics_roundtrip() {
403403
assert_eq!(start, decoded);
404404
}
405405

406+
mod derive_with_polluted_scope {
407+
#[allow(dead_code)]
408+
#[allow(non_snake_case)]
409+
fn Ok() {}
410+
411+
#[derive(bincode::Encode, bincode::Decode)]
412+
struct A {
413+
a: u32,
414+
}
415+
416+
#[derive(bincode::Encode, bincode::Decode)]
417+
enum B {
418+
A,
419+
B,
420+
}
421+
}
422+
406423
#[cfg(feature = "alloc")]
407424
mod zoxide {
408425
extern crate alloc;

0 commit comments

Comments
 (0)