@@ -16,7 +16,6 @@ use rustc_ast::ast;
1616use rustc_data_structures:: fx:: FxHashMap ;
1717use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
1818use rustc_macros:: HashStable_Generic ;
19- use rustc_session:: Session ;
2019use rustc_span:: symbol:: { kw, sym, Symbol } ;
2120use rustc_span:: Span ;
2221
@@ -142,12 +141,20 @@ impl<CTX> HashStable<CTX> for LangItem {
142141/// Extracts the first `lang = "$name"` out of a list of attributes.
143142/// The attributes `#[panic_handler]` and `#[alloc_error_handler]`
144143/// are also extracted out when found.
145- pub fn extract ( sess : & Session , attrs : & [ ast:: Attribute ] ) -> Option < ( Symbol , Span ) > {
144+ ///
145+ /// About the `check_name` argument: passing in a `Session` would be simpler,
146+ /// because then we could call `Session::check_name` directly. But we want to
147+ /// avoid the need for `librustc_hir` to depend on `librustc_session`, so we
148+ /// use a closure instead.
149+ pub fn extract < ' a , F > ( check_name : F , attrs : & ' a [ ast:: Attribute ] ) -> Option < ( Symbol , Span ) >
150+ where
151+ F : Fn ( & ' a ast:: Attribute , Symbol ) -> bool ,
152+ {
146153 attrs. iter ( ) . find_map ( |attr| {
147154 Some ( match attr {
148- _ if sess . check_name ( attr, sym:: lang) => ( attr. value_str ( ) ?, attr. span ) ,
149- _ if sess . check_name ( attr, sym:: panic_handler) => ( sym:: panic_impl, attr. span ) ,
150- _ if sess . check_name ( attr, sym:: alloc_error_handler) => ( sym:: oom, attr. span ) ,
155+ _ if check_name ( attr, sym:: lang) => ( attr. value_str ( ) ?, attr. span ) ,
156+ _ if check_name ( attr, sym:: panic_handler) => ( sym:: panic_impl, attr. span ) ,
157+ _ if check_name ( attr, sym:: alloc_error_handler) => ( sym:: oom, attr. span ) ,
151158 _ => return None ,
152159 } )
153160 } )
0 commit comments