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

libcnb_newtype! doctest fails with Rust 1.62 #410

Closed
edmorley opened this issue Jun 17, 2022 · 0 comments · Fixed by #411
Closed

libcnb_newtype! doctest fails with Rust 1.62 #410

edmorley opened this issue Jun 17, 2022 · 0 comments · Fixed by #411
Assignees
Labels
documentation Improvements or additions to documentation libcnb-data

Comments

@edmorley
Copy link
Member

edmorley commented Jun 17, 2022

I run Rust beta by default, which is currently at v1.62.

Running cargo test on my machine, libcnb main fails with:

...
failures:

---- src/newtypes.rs - newtypes::libcnb_newtype (line 24) stdout ----
error: cannot find macro `buildpack_id` in this scope
  --> src/newtypes.rs:45:13
   |
23 | let bp_id = buildpack_id!("foo");
   |             ^^^^^^^^^^^^
   |
   = note: consider importing this macro:
           libcnb_data::buildpack_id

error: cannot find macro `libcnb_newtype` in this scope
 --> src/newtypes.rs:25:1
  |
3 | libcnb_newtype!(
  | ^^^^^^^^^^^^^^

error[E0412]: cannot find type `BuildpackId` in this scope
  --> src/newtypes.rs:42:27
   |
20 | let bp_id = "bar".parse::<BuildpackId>().unwrap();
   |                           ^^^^^^^^^^^ not found in this scope
   |
help: consider importing this struct
   |
2  | use libcnb_data::buildpack::BuildpackId;
   |

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0412`.
Couldn't compile the test.

failures:
    src/newtypes.rs - newtypes::libcnb_newtype (line 24)

This appears to be due to the fact that until Rust 1.62, doctests that contain non-exported macro_rules! macros were not tested:
rust-lang/rust#96630

GUS-W-11312457.

@edmorley edmorley added documentation Improvements or additions to documentation libcnb-data labels Jun 17, 2022
@edmorley edmorley self-assigned this Jun 17, 2022
edmorley added a commit that referenced this issue Jun 17, 2022
As of Rust 1.62, doctests that contain non-exported `macro_rules!`
macros are now tested, when they were not before.

This causes `cargo test` to fail for this repository, due to the
`libcnb_newtype!` doctest trying to test a private macro.

Doctests can only test things that are public, so we can to either:
1. Make `libcnb_newtype!` public.
2. Annotate the doctest with `compile_fail`, so failure is expected.
3. Remove the example from the doctest.

I've gone with option (2), since it's useful to have the example (so
that people working on libcnb's codebase can use the macro more
easily), however the macro is really an internal thing, so I don't think
we want to export it publicly.

Fixes #410.
GUS-W-11312457.
edmorley added a commit that referenced this issue Jun 20, 2022
As of Rust 1.62, doctests that contain non-exported `macro_rules!`
macros are now tested, when they were not before.

This causes `cargo test` to fail for this repository, due to the
`libcnb_newtype!` doctest trying to test a private macro.

Doctests can only test things that are public, so we have to either:
1. Make `libcnb_newtype!` public.
2. Annotate the doctest with `compile_fail`, so failure is expected.
3. Remove the code example from the doctest.

I've gone with option (2), since it's useful to have the example (so
that people working on libcnb's codebase can use the macro more
easily), however the macro is really an internal thing, so I don't think
we want to export it publicly.

Fixes #410.
GUS-W-11312457.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation libcnb-data
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant