How to extract nightly features used in a crate?

I want to extract all nightly features used by a crate for some research purposes.

Just to be clear, "nightly features" means codes like #![feature(...)]", but not crate provided optional features.

I tried using regex, and it works, but not accurate enough. cfg defined features may not be detected: #![cfg_attr(target_os = "macos", feature(...))].

So I turn to rustc compiler, I wish to modify some source code and print out what features crate uses. Now I'm still trying to find out how rustc deals with nightly features.

I hope someone can give me some tips and help about the process of rustc dealing with nightly features. I'm almost lost in codes.

I have post this question on stack overflow: rust - How to extract nightly features used in a crate? - Stack Overflow, just wish I can get some ideas here, too.

Features of a crate is available as features query, so you'd get them like this:

let features = tcx.features();

If you are not familiar with what query is, check rustc-dev-guide:

1 Like

Thanks so much!!!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.