Factor out some repeated feature-getting code.
This commit is contained in:
parent
e24f394404
commit
9e2cd038b0
1 changed files with 11 additions and 18 deletions
|
@ -24,6 +24,7 @@ use rustc_session::Session;
|
||||||
use rustc_span::edition::{Edition, ALL_EDITIONS};
|
use rustc_span::edition::{Edition, ALL_EDITIONS};
|
||||||
use rustc_span::symbol::{sym, Symbol};
|
use rustc_span::symbol::{sym, Symbol};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
use thin_vec::ThinVec;
|
||||||
|
|
||||||
/// A folder that strips out items that do not belong in the current configuration.
|
/// A folder that strips out items that do not belong in the current configuration.
|
||||||
pub struct StripUnconfigured<'a> {
|
pub struct StripUnconfigured<'a> {
|
||||||
|
@ -54,6 +55,14 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute]) -> Features {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn feature_list(attr: &Attribute) -> ThinVec<ast::NestedMetaItem> {
|
||||||
|
if attr.has_name(sym::feature) && let Some(list) = attr.meta_item_list() {
|
||||||
|
list
|
||||||
|
} else {
|
||||||
|
ThinVec::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut features = Features::default();
|
let mut features = Features::default();
|
||||||
let mut edition_enabled_features = FxHashMap::default();
|
let mut edition_enabled_features = FxHashMap::default();
|
||||||
let crate_edition = sess.edition();
|
let crate_edition = sess.edition();
|
||||||
|
@ -81,15 +90,7 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute]) -> Features {
|
||||||
// - E.g. enable `test_2018_feature` if the crate edition is 2015 but
|
// - E.g. enable `test_2018_feature` if the crate edition is 2015 but
|
||||||
// `rust_2018_preview` is present
|
// `rust_2018_preview` is present
|
||||||
for attr in krate_attrs {
|
for attr in krate_attrs {
|
||||||
if !attr.has_name(sym::feature) {
|
for mi in feature_list(attr) {
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let Some(list) = attr.meta_item_list() else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
|
|
||||||
for mi in list {
|
|
||||||
if !mi.is_word() {
|
if !mi.is_word() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -114,15 +115,7 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute]) -> Features {
|
||||||
|
|
||||||
// Process all features declared in the code.
|
// Process all features declared in the code.
|
||||||
for attr in krate_attrs {
|
for attr in krate_attrs {
|
||||||
if !attr.has_name(sym::feature) {
|
for mi in feature_list(attr) {
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let Some(list) = attr.meta_item_list() else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
|
|
||||||
for mi in list {
|
|
||||||
let name = match mi.ident() {
|
let name = match mi.ident() {
|
||||||
Some(ident) if mi.is_word() => ident.name,
|
Some(ident) if mi.is_word() => ident.name,
|
||||||
Some(ident) => {
|
Some(ident) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue