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

Nightly allow-feature detection does not take Cargo build.rustflags into account #290

Closed
jonhoo opened this issue Jun 30, 2021 · 2 comments

Comments

@jonhoo
Copy link
Sponsor

jonhoo commented Jun 30, 2021

The feature detection just checks RUSTFLAGS directly, which does not include configuration added by Cargo itself. This causes problems in environments where that configuration may change whether or not backtrace is available (or compiles):

cargo new proc-macro2-issue
cd proc-macro2-issue
mkdir .cargo
echo '[build]' >> .cargo/config.toml
echo 'rustflags = ["-Zallow-features="]' >> .cargo/config.toml
echo 'proc-macro2 = "1"' >> Cargo.toml
rustup override set nightly
cargo check

produces

    Updating crates.io index
   Compiling proc-macro2 v1.0.27
    Checking unicode-xid v0.2.2
error[E0725]: the feature `proc_macro_span` is not in the list of allowed features
  --> /Users/jongje/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-1.0.27/src/lib.rs:82:59
   |
82 | #![cfg_attr(any(proc_macro_span, super_unstable), feature(proc_macro_span))]
   |                                                           ^^^^^^^^^^^^^^^

error[E0658]: use of unstable library feature 'proc_macro_span'
   --> /Users/jongje/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-1.0.27/src/wrapper.rs:517:72
    |
517 |             (Span::Compiler(a), Span::Compiler(b)) => Span::Compiler(a.join(b)?),
    |                                                                        ^^^^
    |
    = note: see issue #54725 <https://github.com/rust-lang/rust/issues/54725> for more information
    = help: add `#![feature(proc_macro_span)]` to the crate attributes to enable
...

To fix this, we'll need Cargo to expose its final configuration for rustc, which is rust-lang/cargo#9600. A fix for that is pending in rust-lang/cargo#9601.

@jonhoo
Copy link
Sponsor Author

jonhoo commented Jun 30, 2021

See also dtolnay/anyhow#156

@jonhoo
Copy link
Sponsor Author

jonhoo commented Aug 13, 2021

This is fixed on nightly (which has rust-lang/cargo#9601) by #294 🎉

@jonhoo jonhoo closed this as completed Aug 13, 2021
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

1 participant