Rollup merge of #92702 - ehuss:clean-lang_items-extract, r=petrochenkov
Clean up lang_items::extract Noted in https://github.com/rust-lang/rust/pull/87739#pullrequestreview-740497194, lang_items::extract no longer needs to take a closure.
This commit is contained in:
commit
6719e3eb18
5 changed files with 9 additions and 27 deletions
|
@ -151,20 +151,12 @@ impl<CTX> HashStable<CTX> for LangItem {
|
|||
/// Extracts the first `lang = "$name"` out of a list of attributes.
|
||||
/// The attributes `#[panic_handler]` and `#[alloc_error_handler]`
|
||||
/// are also extracted out when found.
|
||||
///
|
||||
/// About the `check_name` argument: passing in a `Session` would be simpler,
|
||||
/// because then we could call `Session::check_name` directly. But we want to
|
||||
/// avoid the need for `rustc_hir` to depend on `rustc_session`, so we
|
||||
/// use a closure instead.
|
||||
pub fn extract<'a, F>(check_name: F, attrs: &'a [ast::Attribute]) -> Option<(Symbol, Span)>
|
||||
where
|
||||
F: Fn(&'a ast::Attribute, Symbol) -> bool,
|
||||
{
|
||||
pub fn extract(attrs: &[ast::Attribute]) -> Option<(Symbol, Span)> {
|
||||
attrs.iter().find_map(|attr| {
|
||||
Some(match attr {
|
||||
_ if check_name(attr, sym::lang) => (attr.value_str()?, attr.span),
|
||||
_ if check_name(attr, sym::panic_handler) => (sym::panic_impl, attr.span),
|
||||
_ if check_name(attr, sym::alloc_error_handler) => (sym::oom, attr.span),
|
||||
_ if attr.has_name(sym::lang) => (attr.value_str()?, attr.span),
|
||||
_ if attr.has_name(sym::panic_handler) => (sym::panic_impl, attr.span),
|
||||
_ if attr.has_name(sym::alloc_error_handler) => (sym::oom, attr.span),
|
||||
_ => return None,
|
||||
})
|
||||
})
|
||||
|
|
|
@ -18,13 +18,9 @@ pub static WEAK_ITEMS_REFS: SyncLazy<StableMap<Symbol, LangItem>> = SyncLazy::ne
|
|||
map
|
||||
});
|
||||
|
||||
/// The `check_name` argument avoids the need for `rustc_hir` to depend on
|
||||
/// `rustc_session`.
|
||||
pub fn link_name<'a, F>(check_name: F, attrs: &'a [ast::Attribute]) -> Option<Symbol>
|
||||
where
|
||||
F: Fn(&'a ast::Attribute, Symbol) -> bool
|
||||
pub fn link_name(attrs: &[ast::Attribute]) -> Option<Symbol>
|
||||
{
|
||||
lang_items::extract(check_name, attrs).and_then(|(name, _)| {
|
||||
lang_items::extract(attrs).and_then(|(name, _)| {
|
||||
$(if name == sym::$name {
|
||||
Some(sym::$sym)
|
||||
} else)* {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue