@@ -16,7 +16,6 @@ use rustc_ast::ast;
16
16
use rustc_data_structures:: fx:: FxHashMap ;
17
17
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
18
18
use rustc_macros:: HashStable_Generic ;
19
- use rustc_session:: Session ;
20
19
use rustc_span:: symbol:: { kw, sym, Symbol } ;
21
20
use rustc_span:: Span ;
22
21
@@ -142,12 +141,20 @@ impl<CTX> HashStable<CTX> for LangItem {
142
141
/// Extracts the first `lang = "$name"` out of a list of attributes.
143
142
/// The attributes `#[panic_handler]` and `#[alloc_error_handler]`
144
143
/// 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
+ {
146
153
attrs. iter ( ) . find_map ( |attr| {
147
154
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 ) ,
151
158
_ => return None ,
152
159
} )
153
160
} )
0 commit comments