Skip to content

Make proc_macro_span optional with nightly #415

@andreeaflorescu

Description

@andreeaflorescu

From the documentation of proc_macro_span I was understanding that if you don't allow unstable features in your nightly build, then the build of the crate should still work:
"Enabled when building with nightly, unless -Z allow-feature in RUSTFLAGS disallows unstable features."

I am using the following configuration in my .cargo/config.toml:

[unstable]
allow-features = []

And the following rust nightly: nightly-2023-09-25.

When building a dummy crate that just has proc-macro2 as a dependency, the following happens:

 cargo build --verbose
       Dirty proc-macro2 v1.0.67: the config settings changed
   Compiling proc-macro2 v1.0.67
       Dirty unicode-ident v1.0.12: the config settings changed
   Compiling unicode-ident v1.0.12
     Running `/Users/fandree/.rustup/toolchains/nightly-2023-09-25-aarch64-apple-darwin/bin/rustc --crate-name build_script_build --edition=2021 /Users/fandree/.cargo/registry/src/index.crates.io-6f17d22bba15001f/proc-macro2-1.0.67/build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=312 -Zallow-features= --crate-type bin --emit=dep-info,link -C embed-bitcode=no --cfg 'feature="default"' --cfg 'feature="proc-macro"' -C metadata=643d0f678a6ab910 -C extra-filename=-643d0f678a6ab910 --out-dir /Users/fandree/sources/rust-crates/test-crate/target/debug/build/proc-macro2-643d0f678a6ab910 -L dependency=/Users/fandree/sources/rust-crates/test-crate/target/debug/deps --cap-lints allow`
     Running `/Users/fandree/.rustup/toolchains/nightly-2023-09-25-aarch64-apple-darwin/bin/rustc --crate-name unicode_ident --edition=2018 /Users/fandree/.cargo/registry/src/index.crates.io-6f17d22bba15001f/unicode-ident-1.0.12/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=312 -Zallow-features= --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked -C metadata=19688c2ad055990d -C extra-filename=-19688c2ad055990d --out-dir /Users/fandree/sources/rust-crates/test-crate/target/debug/deps -L dependency=/Users/fandree/sources/rust-crates/test-crate/target/debug/deps --cap-lints allow`
     Running `/Users/fandree/sources/rust-crates/test-crate/target/debug/build/proc-macro2-643d0f678a6ab910/build-script-build`
     Running `/Users/fandree/.rustup/toolchains/nightly-2023-09-25-aarch64-apple-darwin/bin/rustc --crate-name proc_macro2 --edition=2021 /Users/fandree/.cargo/registry/src/index.crates.io-6f17d22bba15001f/proc-macro2-1.0.67/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=312 -Zallow-features= --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked --cfg 'feature="default"' --cfg 'feature="proc-macro"' -C metadata=aef881fdd2157960 -C extra-filename=-aef881fdd2157960 --out-dir /Users/fandree/sources/rust-crates/test-crate/target/debug/deps -L dependency=/Users/fandree/sources/rust-crates/test-crate/target/debug/deps --extern unicode_ident=/Users/fandree/sources/rust-crates/test-crate/target/debug/deps/libunicode_ident-19688c2ad055990d.rmeta --cap-lints allow --cfg wrap_proc_macro --cfg proc_macro_span`
error[E0725]: the feature `proc_macro_span` is not in the list of allowed features
  --> /Users/fandree/.cargo/registry/src/index.crates.io-6f17d22bba15001f/proc-macro2-1.0.67/src/lib.rs:90:59
   |
90 | #![cfg_attr(any(proc_macro_span, super_unstable), feature(proc_macro_span))]

The --cfg proc_macro_span was added even though we also pass the -Zallow-features= flag. Is this the expected behavior?

I would like to be able to build proc-macro2 with nightly without having to enable the unstable feature. Is this possible?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions