idanarye/rust-typed-builder

use of undeclared crate or module `proc_macro`

dblock opened this issue · 4 comments

Trying to use dry run in lycheeverse/lychee#304 seeing this:

rustc --edition=2018 --crate-name typed_builder /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/typed-builder-0.9.0/src/lib.rs --color always --crate-type proc-macro --emit=dep-info,link -C prefer-dynamic -C debuginfo=2 -C metadata=72ebad225c590f6d -C extra-filename=-72ebad225c590f6d --out-dir /home/ubuntu/source/lychee/dblock-lychee/target/package/lychee-lib-0.7.1/target/debug/deps -L dependency=/home/ubuntu/source/lychee/dblock-lychee/target/package/lychee-lib-0.7.1/target/debug/deps --extern proc_macro2=/home/ubuntu/source/lychee/dblock-lychee/target/package/lychee-lib-0.7.1/target/debug/deps/libproc_macro2-6f5ad8ea0bdf5b2f.rlib --extern quote=/home/ubuntu/source/lychee/dblock-lychee/target/package/lychee-lib-0.7.1/target/debug/deps/libquote-9b9b7563b6863207.rlib --extern syn=/home/ubuntu/source/lychee/dblock-lychee/target/package/lychee-lib-0.7.1/target/debug/deps/libsyn-c3d8aa50fc12e127.rlib --cap-lints allow
   Verifying lychee-lib
error[E0433]: failed to resolve: use of undeclared crate or module `proc_macro`
   --> /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/typed-builder-0.9.0/src/lib.rs:138:36
    |
138 | pub fn derive_typed_builder(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
    |                                    ^^^^^^^^^^ use of undeclared crate or module `proc_macro`

error[E0433]: failed to resolve: use of undeclared crate or module `proc_macro`
   --> /home/ubuntu/.cargo/registry/src/github.com-1ecc6299db9ec823/typed-builder-0.9.0/src/lib.rs:138:64
    |
138 | pub fn derive_typed_builder(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
    |                                                                ^^^^^^^^^^ use of undeclared crate or module `proc_macro`

Ideas?

This is weird. When I try to run this command (paths adjusted):

rustc --edition=2018 \
    --crate-name typed_builder \
    /home/idanarye/.cargo/registry/src/github.com-1ecc6299db9ec823/typed-builder-0.9.0/src/lib.rs \
    --color always \
    --crate-type proc-macro \
    --emit=dep-info,link \
    -C prefer-dynamic \
    -C debuginfo=2 \
    -C metadata=72ebad225c590f6d \
    -C extra-filename=-72ebad225c590f6d \
    --out-dir /tmp/ \
    -L dependency=/media/d/Programming/Projects/rust-typed-builder/target/debug/deps/ \
    --extern /home/idanarye/.cargo/registry/src/github.com-1ecc6299db9ec823/typed-builder-0.9.0/target/debug/deps/libproc_macro2-5c21d599c997d506.rlib \
    --extern /home/idanarye/.cargo/registry/src/github.com-1ecc6299db9ec823/typed-builder-0.9.0/target/debug/deps/libquote-5643644f696ec073.rlib \
    --extern /home/idanarye/.cargo/registry/src/github.com-1ecc6299db9ec823/typed-builder-0.9.0/target/debug/deps/libsyn-aa7c69dcc752b5dd.rlib \
    --cap-lints allow

I get a long list of complaints about not finding proc_macro2, syn and quote. Which I can fix by putting name on the --extern targets:

rustc --edition=2018 \
    --crate-name typed_builder \
    /home/idanarye/.cargo/registry/src/github.com-1ecc6299db9ec823/typed-builder-0.9.0/src/lib.rs \
    --color always \
    --crate-type proc-macro \
    --emit=dep-info,link \
    -C prefer-dynamic \
    -C debuginfo=2 \
    -C metadata=72ebad225c590f6d \
    -C extra-filename=-72ebad225c590f6d \
    --out-dir /tmp/ \
    -L dependency=/media/d/Programming/Projects/rust-typed-builder/target/debug/deps/ \
    --extern proc_macro2=/home/idanarye/.cargo/registry/src/github.com-1ecc6299db9ec823/typed-builder-0.9.0/target/debug/deps/libproc_macro2-5c21d599c997d506.rlib \
    --extern quote=/home/idanarye/.cargo/registry/src/github.com-1ecc6299db9ec823/typed-builder-0.9.0/target/debug/deps/libquote-5643644f696ec073.rlib \
    --extern syn=/home/idanarye/.cargo/registry/src/github.com-1ecc6299db9ec823/typed-builder-0.9.0/target/debug/deps/libsyn-aa7c69dcc752b5dd.rlib \
    --cap-lints allow

And now I only get complaints about proc_macro.

But... proc_macro is part of the standard library, and --crate-type proc-macro should have exposed it to the code.

An

extern crate proc_macro;

Seems to fix this. Which is very weird, because the 2018 edition should mean we don't need to declare extern crate anymore. I guess proc_macro is a special case? And in regular builds Cargo is doing something about it in the background?

Thank you for fixing this! Care to cut a release please?

Already have

Seems like this is happening again in lycheeverse/lychee#346, I think they could use some help, I don't understand what's going on - maybe you do @idanarye?