|
9 | 9 | //! |
10 | 10 | //! * Compiler internal types like `Ty` and `TyCtxt` |
11 | 11 |
|
| 12 | +use rustc_hir::attrs::AttributeKind; |
12 | 13 | use rustc_hir::diagnostic_items::DiagnosticItems; |
13 | | -use rustc_hir::{Attribute, CRATE_OWNER_ID, OwnerId}; |
| 14 | +use rustc_hir::{CRATE_OWNER_ID, OwnerId, find_attr}; |
14 | 15 | use rustc_middle::query::{LocalCrate, Providers}; |
15 | 16 | use rustc_middle::ty::TyCtxt; |
| 17 | +use rustc_span::Symbol; |
16 | 18 | use rustc_span::def_id::{DefId, LOCAL_CRATE}; |
17 | | -use rustc_span::{Symbol, sym}; |
18 | 19 |
|
19 | 20 | use crate::errors::DuplicateDiagnosticItemInCrate; |
20 | 21 |
|
21 | 22 | fn observe_item<'tcx>(tcx: TyCtxt<'tcx>, diagnostic_items: &mut DiagnosticItems, owner: OwnerId) { |
22 | 23 | let attrs = tcx.hir_attrs(owner.into()); |
23 | | - if let Some(name) = extract(attrs) { |
| 24 | + if let Some(name) = find_attr!(attrs, AttributeKind::RustcDiagnosticItem(name) => name) { |
24 | 25 | // insert into our table |
25 | | - collect_item(tcx, diagnostic_items, name, owner.to_def_id()); |
| 26 | + collect_item(tcx, diagnostic_items, *name, owner.to_def_id()); |
26 | 27 | } |
27 | 28 | } |
28 | 29 |
|
@@ -53,13 +54,6 @@ fn report_duplicate_item( |
53 | 54 | }); |
54 | 55 | } |
55 | 56 |
|
56 | | -/// Extract the first `rustc_diagnostic_item = "$name"` out of a list of attributes. |
57 | | -fn extract(attrs: &[Attribute]) -> Option<Symbol> { |
58 | | - attrs.iter().find_map(|attr| { |
59 | | - if attr.has_name(sym::rustc_diagnostic_item) { attr.value_str() } else { None } |
60 | | - }) |
61 | | -} |
62 | | - |
63 | 57 | /// Traverse and collect the diagnostic items in the current |
64 | 58 | fn diagnostic_items(tcx: TyCtxt<'_>, _: LocalCrate) -> DiagnosticItems { |
65 | 59 | // Initialize the collector. |
|
0 commit comments