Skip to content

Enforce absolute paths in all macro_rules and call_site sections of proc macros - #6

Open
anglesideangle wants to merge 1 commit into
Oblarg:mainfrom
anglesideangle:hygenic-macros
Open

Enforce absolute paths in all macro_rules and call_site sections of proc macros#6
anglesideangle wants to merge 1 commit into
Oblarg:mainfrom
anglesideangle:hygenic-macros

Conversation

@anglesideangle

@anglesideangle anglesideangle commented Jul 7, 2026

Copy link
Copy Markdown

This replaces all call-site instances of e.g. Result with ::core::result::Result, and re-exports whippyunits' dependency crates (num_traits, whippyunits_core, whippyunits_proc_macros) for use within whippyunits macros as e.g. $crate::__private_num_traits. It also adds macro_hygiene_tests for shadowing issues and a transitive_dependency test for ensuring a crate depending on whippyunits can successfully compile without itself depending on num_traits or whippyunits_core/whippyunits_proc_macros.

A few notes:

  • Proc macros currently cannot make use of the $crate:: mechanism that is used for macro_rules, so they currently directly reference whippyunits:: paths. This would break if, e.g. they are in the same scope as a struct whippyunits or a dependent crate imports whippyunits under a different name (wpiunits = { package = "whippyunits", version = "0.2" }). There seems to be proc-macro-crate to address this, but that's adding a dep so I didn't implement it here. What are your thoughts on this?
  • This removes the distinction of the DynDimensionExponents and ScaleExponents between whippyunits_proc_macros::compute_unit_dimensions and various serialization macros because whippyunits_proc_macro doesn't re-export whippyunits_core for something like the $crate::__private_whippyunits_core hack
  • This makes a parts of the code pretty ugly
  • ^ Some of the un-prettified error messages are kind of ridiculous now, e.g. tests/compile_fail_stable/compare_different_scales.stderr:
error[E0308]: mismatched types
  --> tests/compile_fail_stable/compare_different_scales.rs:11:28
   |
11 |     let _result = meters > millimeters;
   |                            ^^^^^^^^^^^ expected `0`, found `-3`
   |
   = note: expected struct `Quantity<Scale, whippyunits::quantity::Dimension<whippyunits::quantity::_M, whippyunits::quantity::_L<1>>>`
              found struct `Quantity<Scale<_2<-3>, _3, _5<-3>>, whippyunits::quantity::Dimension<whippyunits::quantity::_M, whippyunits::quantity::_L<1>>>`

Some of the grunt work in this PR was done by an llm, but I've thoroughly reviewed and edited its output, and written more concise docs.

It also seems my editor's autoformatting caused a bit of churn. I can make a follow up PR enforcing formatting and strict clippy rules

This replaces all call-site instances of e.g. `Result` with
`::core::result::Result`, and re-exports whippyunits' dependency crates
(`num_traits`, `whippyunits_core`, `whippyunits_proc_macros`) for use
within whippyunits macros as e.g. `$crate::__private_num_traits`.

It also adds `macro_hygiene_tests` for shadowing issues and a
`transitive_dependency` test for ensuring a crate depending on
whippyunits can successfully compile without itself depending on
`num_traits` or `whippyunits_core`/`whippyunits_proc_macros`.
@anglesideangle
anglesideangle marked this pull request as ready for review July 7, 2026 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant