recmo/uint

Current macro definition is not easily re-exportable

Closed this issue · 3 comments

Refer this line:

let source = format!("::ruint::{base_type}::<{bits}, {limbs}>::from_limbs([{limbs_str}])");

The use of ::ruint means that re-export (e.g. here) breaks unless the user of the re-exported macro also has ruint in their top-level module hierarchy (which suggests they need to add to Cargo.toml and breaks the point of the re-export).

I'm opening this issue to discuss possible fixes. I haven't verified this but I think just using $crate:: in lieu of ::ruint will fit the bill (cf. https://doc.rust-lang.org/1.5.0/book/macros.html#the-variable-crate). Otherwise I think ruint by itself would also work as then we could just use re_exporter::{ruint, uint}; (which is not as nice but is better IMO than adding the explicit ruint dependency and possible in alloy_primitives).

If we find a solution we like, I'm happy to open a PR.

I'm opening this issue to discuss possible fixes. I haven't verified this but I think just using $crate:: in lieu of ::ruint will fit the bill (cf. https://doc.rust-lang.org/1.5.0/book/macros.html#the-variable-crate).

The specal $crate variable only works in declarative macros, while the uint! macro is a procedural macro. So it's not as simple as swapping it out. The proc macro is effectively codegen. We have to design some clean code that achieves this

It seems bad for the ruint-macro crate to get a redesign to support sideloading the ruint types that it relies on from other crates.

In the meantime, adding ruint to your dependencies is the correct workaround, and we'll document this workaround in the primitives library