mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-08 05:06:52 +00:00

`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
50 lines
1.4 KiB
Rust
50 lines
1.4 KiB
Rust
use rustc_ast::attr::{AttributeExt, filter_by_name};
|
|
use rustc_session::Session;
|
|
use rustc_span::{Symbol, sym};
|
|
|
|
use crate::session_diagnostics;
|
|
|
|
pub fn allow_internal_unstable<'a>(
|
|
sess: &'a Session,
|
|
attrs: &'a [impl AttributeExt],
|
|
) -> impl Iterator<Item = Symbol> + 'a {
|
|
allow_unstable(sess, attrs, sym::allow_internal_unstable)
|
|
}
|
|
|
|
pub fn rustc_allow_const_fn_unstable<'a>(
|
|
sess: &'a Session,
|
|
attrs: &'a [impl AttributeExt],
|
|
) -> impl Iterator<Item = Symbol> + 'a {
|
|
allow_unstable(sess, attrs, sym::rustc_allow_const_fn_unstable)
|
|
}
|
|
|
|
fn allow_unstable<'a>(
|
|
sess: &'a Session,
|
|
attrs: &'a [impl AttributeExt],
|
|
symbol: Symbol,
|
|
) -> impl Iterator<Item = Symbol> + 'a {
|
|
let attrs = filter_by_name(attrs, symbol);
|
|
let list = attrs
|
|
.filter_map(move |attr| {
|
|
attr.meta_item_list().or_else(|| {
|
|
sess.dcx().emit_err(session_diagnostics::ExpectsFeatureList {
|
|
span: attr.span(),
|
|
name: symbol.to_ident_string(),
|
|
});
|
|
None
|
|
})
|
|
})
|
|
.flatten();
|
|
|
|
list.into_iter().filter_map(move |it| {
|
|
let name = it.ident().map(|ident| ident.name);
|
|
if name.is_none() {
|
|
sess.dcx().emit_err(session_diagnostics::ExpectsFeatures {
|
|
span: it.span(),
|
|
name: symbol.to_ident_string(),
|
|
});
|
|
}
|
|
name
|
|
})
|
|
}
|