Skip to content

Commit

Permalink
derive: fix compilation error if user define its own Result type
Browse files Browse the repository at this point in the history
  • Loading branch information
abernardeau-wallix committed Jul 11, 2024
1 parent 7ed2a89 commit 48714b2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions dxr/tests/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ fn try_build_pass() {
t.pass("tests/trybuild/moo.rs");
t.pass("tests/trybuild/appendix.rs");
t.pass("tests/trybuild/recursive.rs");
t.pass("tests/trybuild/custom_result_type.rs");
t.pass("tests/trybuild/ownership.rs");
t.pass("tests/trybuild/collections.rs");
}
Expand Down
10 changes: 10 additions & 0 deletions dxr/tests/trybuild/custom_result_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use dxr::{TryFromValue, TryToValue};

type Result<T> = std::result::Result<T, ()>;

#[derive(TryFromValue, TryToValue)]
pub struct Array {
array: [i32; 4],
}

fn main() {}
4 changes: 2 additions & 2 deletions dxr_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ pub fn try_from_value(input: TokenStream) -> TokenStream {

let impl_block = quote! {
impl #impl_generics #dxr::TryFromValue for #name #ty_generics #where_clause {
fn try_from_value(value: &#dxr::Value) -> Result<#name #ty_generics, #dxr::DxrError> {
fn try_from_value(value: &#dxr::Value) -> std::result::Result<#name #ty_generics, #dxr::DxrError> {
use ::std::collections::HashMap;
use ::std::string::String;
use #dxr::{Value, DxrError};
Expand Down Expand Up @@ -258,7 +258,7 @@ pub fn try_to_value(input: TokenStream) -> TokenStream {

let impl_block = quote! {
impl #impl_generics #dxr::TryToValue for #name #ty_generics #where_clause {
fn try_to_value(&self) -> Result<#dxr::Value, #dxr::DxrError> {
fn try_to_value(&self) -> std::result::Result<#dxr::Value, #dxr::DxrError> {
use ::std::collections::HashMap;
use ::std::string::String;
use #dxr::Value;
Expand Down

0 comments on commit 48714b2

Please sign in to comment.