Repository: near/borsh-rs (rust)

Issue:
bug: could not find `result` in `core`
After updating to `near-sdk` = `3.0.0-pre-release` which uses borsh `0.8.1` the contract build generates the following error:
```
error[E0433]: failed to resolve: could not find `result` in `core`
   --> src/lib.rs:146:10
    |
146 | #[derive(BorshDeserialize, BorshSerialize, PanicOnDefault)]
    |          ^^^^^^^^^^^^^^^^
    |          |
    |          could not find `result` in `core`
    |          in this macro invocation
    |
   ::: /Users/ekwork/.cargo/registry/src/github.com-1ecc6299db9ec823/borsh-derive-0.8.1/src/lib.rs:34:1
    |
34  | pub fn borsh_deserialize(input: TokenStream) -> TokenStream {
    | ----------------------------------------------------------- in this expansion of `#[derive(BorshDeserialize)]`

error[E0433]: failed to resolve: could not find `result` in `core`
   --> src/lib.rs:146:28
    |
146 | #[derive(BorshDeserialize, BorshSerialize, PanicOnDefault)]
    |                            ^^^^^^^^^^^^^^
    |                            |
    |                            could not find `result` in `core`
    |                            in this macro invocation
    |
   ::: /Users/ekwork/.cargo/registry/src/github.com-1ecc6299db9ec823/borsh-derive-0.8.1/src/lib.rs:11:1
    |
11  | pub fn borsh_serialize(input: TokenStream) -> TokenStream {
    | --------------------------------------------------------- in this expansion of `#[derive(BorshSerialize)]`

error: aborting due to 2 previous errors
```

Repro:
```bash
git clone https://github.com/evgenykuzyakov/oysterpack-near-stake-token
cd oysterpack-near-stake-token
git checkout borsh-bug
cd contract
./build.sh
```


Pull request description:
feat: avoid collisions of imports due to derive-generated code
Resolves #11

Patch:
diff --git a/borsh-derive-internal/src/struct_de.rs b/borsh-derive-internal/src/struct_de.rs
index 545ac3ae..d26192d2 100644
--- a/borsh-derive-internal/src/struct_de.rs
+++ b/borsh-derive-internal/src/struct_de.rs
@@ -64,7 +64,7 @@ pub fn struct_de(input: &ItemStruct, cratename: Ident) -> syn::Result<TokenStrea
     if let Some(method_ident) = init_method {
         Ok(quote! {
             impl #impl_generics #cratename::de::BorshDeserialize for #name #ty_generics #where_clause {
-                fn deserialize(buf: &mut &[u8]) ->  core::result::Result<Self, #cratename::maybestd::io::Error> {
+                fn deserialize(buf: &mut &[u8]) -> ::core::result::Result<Self, #cratename::maybestd::io::Error> {
                     let mut return_value = #return_value;
                     return_value.#method_ident();
                     Ok(return_value)
@@ -74,7 +74,7 @@ pub fn struct_de(input: &ItemStruct, cratename: Ident) -> syn::Result<TokenStrea
     } else {
         Ok(quote! {
             impl #impl_generics #cratename::de::BorshDeserialize for #name #ty_generics #where_clause {
-                fn deserialize(buf: &mut &[u8]) -> core::result::Result<Self, #cratename::maybestd::io::Error> {
+                fn deserialize(buf: &mut &[u8]) -> ::core::result::Result<Self, #cratename::maybestd::io::Error> {
                     Ok(#return_value)
                 }
             }
diff --git a/borsh-derive-internal/src/struct_ser.rs b/borsh-derive-internal/src/struct_ser.rs
index 2e118b87..ea3ab955 100644
--- a/borsh-derive-internal/src/struct_ser.rs
+++ b/borsh-derive-internal/src/struct_ser.rs
@@ -54,7 +54,7 @@ pub fn struct_ser(input: &ItemStruct, cratename: Ident) -> syn::Result<TokenStre
     }
     Ok(quote! {
         impl #impl_generics #cratename::ser::BorshSerialize for #name #ty_generics #where_clause {
-            fn serialize<W: #cratename::maybestd::io::Write>(&self, writer: &mut W) -> core::result::Result<(), #cratename::maybestd::io::Error> {
+            fn serialize<W: #cratename::maybestd::io::Write>(&self, writer: &mut W) -> ::core::result::Result<(), #cratename::maybestd::io::Error> {
                 #body
                 Ok(())
             }
@@ -88,7 +88,7 @@ mod tests {
                 u64: borsh::ser::BorshSerialize,
                 String: borsh::ser::BorshSerialize
             {
-                fn serialize<W: borsh::maybestd::io::Write>(&self, writer: &mut W) -> core::result::Result<(), borsh::maybestd::io::Error> {
+                fn serialize<W: borsh::maybestd::io::Write>(&self, writer: &mut W) -> ::core::result::Result<(), borsh::maybestd::io::Error> {
                     borsh::BorshSerialize::serialize(&self.x, writer)?;
                     borsh::BorshSerialize::serialize(&self.y, writer)?;
                     Ok(())
@@ -114,7 +114,7 @@ mod tests {
                 HashMap<K, V>: borsh::ser::BorshSerialize,
                 String: borsh::ser::BorshSerialize
             {
-                fn serialize<W: borsh::maybestd::io::Write>(&self, writer: &mut W) -> core::result::Result<(), borsh::maybestd::io::Error> {
+                fn serialize<W: borsh::maybestd::io::Write>(&self, writer: &mut W) -> ::core::result::Result<(), borsh::maybestd::io::Error> {
                     borsh::BorshSerialize::serialize(&self.x, writer)?;
                     borsh::BorshSerialize::serialize(&self.y, writer)?;
                     Ok(())
@@ -141,7 +141,7 @@ mod tests {
                 HashMap<K, V>: borsh::ser::BorshSerialize,
                 String: borsh::ser::BorshSerialize
             {
-                fn serialize<W: borsh::maybestd::io::Write>(&self, writer: &mut W) -> core::result::Result<(), borsh::maybestd::io::Error> {
+                fn serialize<W: borsh::maybestd::io::Write>(&self, writer: &mut W) -> ::core::result::Result<(), borsh::maybestd::io::Error> {
                     borsh::BorshSerialize::serialize(&self.x, writer)?;
                     borsh::BorshSerialize::serialize(&self.y, writer)?;
                     Ok(())


Test patch:
diff --git a/borsh/tests/test_macro_namespace_collisions.rs b/borsh/tests/test_macro_namespace_collisions.rs
new file mode 100644
index 00000000..a035350c
--- /dev/null
+++ b/borsh/tests/test_macro_namespace_collisions.rs
@@ -0,0 +1,7 @@
+// Borsh macros should not collide with the local modules:
+// https://github.com/near/borsh-rs/issues/11
+mod std {}
+mod core {}
+
+#[derive(borsh::BorshSerialize, borsh::BorshDeserialize)]
+struct A;