Skip to content

Commit

Permalink
Fix Result scoping (#162)
Browse files Browse the repository at this point in the history
* Fixes a scoping issue with derive macros where Result is used instead of core::result::Result, which can conflict with crate-local Result types.

* adding test to detect Result scoping.

* adding test comment
  • Loading branch information
orthecreedence committed Sep 28, 2023
1 parent 58fb945 commit f4e692b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion macros/src/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl Enum {
quote! {
#[automatically_derived]
impl #impl_generics #crate_root::types::DecodeChoice for #name #ty_generics #where_clause {
fn from_tag<D: #crate_root::Decoder>(decoder: &mut D, tag: #crate_root::Tag) -> Result<Self, D::Error> {
fn from_tag<D: #crate_root::Decoder>(decoder: &mut D, tag: #crate_root::Tag) -> core::result::Result<Self, D::Error> {
use #crate_root::de::Decode;
#from_tag
}
Expand Down
16 changes: 16 additions & 0 deletions tests/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,19 @@ pub struct BasicConstraints {
pub ca: bool,
pub path_len_constraint: Option<Integer>,
}

// This test will fail to compile if `Result` is used in the derive/proc macros instead of
// `core::result::Result`
#[test]
fn result_scoping() {
enum Error {}
type Result<T> = core::result::Result<T, Error>;

#[derive(rasn::AsnType, rasn::Encode, rasn::Decode)]
#[rasn(choice)]
enum Choose {
Single(String),
}

let _: Result<()> = Ok(());
}

0 comments on commit f4e692b

Please sign in to comment.