Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doctest failure for custom quantity #119

Closed
svartalf opened this issue Mar 25, 2019 · 4 comments
Closed

Doctest failure for custom quantity #119

svartalf opened this issue Mar 25, 2019 · 4 comments

Comments

@svartalf
Copy link
Contributor

I've created a custom quantities system and for some weird reasons doc example for the quantity! macro somehow breaks the documentation tests in my crate with the following error:

$ cargo test --all
..

failures:

---- <::uom::system::system macros> - IEC (line 803) stdout ----
error[E0432]: unresolved import `mks`
  --> doctest.rs:861:5
   |
59 |     Q!(mks, f32/*, (centimeter, gram, second)*/);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `mks` external crate
   |
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

thread '<::uom::system::system macros> - IEC (line 803)' panicked at 'couldn't compile the test', src/librustdoc/test.rs:351:13

Commenting these lines in the uom sources removes an error completely.

rustc version: 1.33.0
uom version:

[dependencies.uom]
version = "0.21.1"
default-features = false
features = ["autoconvert", "usize", "u64", "f64", "si", "std"]

I guess, doc test for exported IEC! macro breaks for some unknown reasons?

So, here is what makes this bug "weird": it is reproducible in the existing code, but I can't reproduce it with a new cargo project.
Unfortunately, existing code is not public (yet), so at the moment I'm failing to find the way of how to show it.

@iliekturtles, any thoughts, maybe?

@iliekturtles
Copy link
Owner

This is an issue caused by edition="2018". I'm able to reproduce by copying the doc example into a new project. It fails to compile with edition="2018" but is successful with edition="2015". The $quantities! macro is generating code is that isn't compatible for edition="2018".

Short term it looks like changing the macro invocation to Q!(crate::mks, f32/*, (centimeter, gram, second)*/); is compatible with both editions. Long term I want to think about having uom documentation being generated on the $quantities! macro and inserted into the caller's crate. The doc comments for this macro should should possibly be specified in the system! macro call.

Cross-edition tests should also be added to uom so that issues like this get caught in the future.

@svartalf
Copy link
Contributor Author

Yeah, this explains everything, thanks :)
I think I can manage the workaround until uom will be compatible with the edition="2018".

Not sure if this issue should be closed now, feel free to do that.

@iliekturtles
Copy link
Owner

Leave it open. I have some local changes to fix the generated code to be compatible with both editions. uom itself is going to remain 2015 to support older compilers but I should be able to make generated code compatible. I'll try to get the changes committed and released in the next couple days.

iliekturtles added a commit that referenced this issue Mar 25, 2019
Doc test on the `$quantities!` macro would fail with the error `no
``mks`` external crate` when the `system!` macro was invoked in a crate
using the 2018 edition. All invocations of the `$quantities!` macro are
corrected and a new test crate, edition_check, is added to validate
`uom` can be used in 2018 edition code. Resolves #119.
iliekturtles added a commit that referenced this issue Mar 25, 2019
Doc test on the `$quantities!` macro would fail with the error `no
``mks`` external crate` when the `system!` macro was invoked in a crate
using the 2018 edition. All invocations of the `$quantities!` macro are
corrected and a new test crate, `edition_check`, is added to validate
`uom` can be used in 2018 edition code. Resolves #119.
iliekturtles added a commit that referenced this issue Mar 26, 2019
Doc test on the `$quantities!` macro would fail with the error `no
``mks`` external crate` when the `system!` macro was invoked in a crate
using the 2018 edition. All invocations of the `$quantities!` macro are
corrected and a new test crate, `edition_check`, is added to validate
`uom` can be used in 2018 edition code. Resolves #119.
iliekturtles added a commit that referenced this issue Mar 26, 2019
Doc test on the `$quantities!` macro would fail with the error `no
``mks`` external crate` when the `system!` macro was invoked in a crate
using the 2018 edition. All invocations of the `$quantities!` macro are
corrected and a new test crate, `edition_check`, is added to validate
`uom` can be used in 2018 edition code. Resolves #119.
iliekturtles added a commit that referenced this issue Mar 27, 2019
Doc test on the `$quantities!` macro would fail with the error `no
``mks`` external crate` when the `system!` macro was invoked in a crate
using the 2018 edition. All invocations of the `$quantities!` macro are
corrected and a new test crate, `edition_check`, is added to validate
`uom` can be used in 2018 edition code. Resolves #119.
@iliekturtles
Copy link
Owner

v0.22.0 with the doc test fixes released to crates.io.

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

No branches or pull requests

2 participants