Port #[rustc_diagnostic_item] to the new attribute parsers
This commit is contained in:
parent
bb8b30a5fc
commit
cbc661022e
9 changed files with 61 additions and 25 deletions
|
|
@ -307,6 +307,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||
| AttributeKind::RustcDelayedBugFromInsideQuery
|
||||
| AttributeKind::RustcDenyExplicitImpl(..)
|
||||
| AttributeKind::RustcDeprecatedSafe2024 {..}
|
||||
| AttributeKind::RustcDiagnosticItem(..)
|
||||
| AttributeKind::RustcDummy
|
||||
| AttributeKind::RustcDumpDefParents
|
||||
| AttributeKind::RustcDumpItemBounds
|
||||
|
|
@ -398,7 +399,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||
| sym::panic_handler
|
||||
| sym::lang
|
||||
| sym::default_lib_allocator
|
||||
| sym::rustc_diagnostic_item
|
||||
| sym::rustc_nonnull_optimization_guaranteed
|
||||
| sym::rustc_inherit_overflow_checks
|
||||
| sym::rustc_on_unimplemented
|
||||
|
|
|
|||
|
|
@ -9,20 +9,21 @@
|
|||
//!
|
||||
//! * Compiler internal types like `Ty` and `TyCtxt`
|
||||
|
||||
use rustc_hir::attrs::AttributeKind;
|
||||
use rustc_hir::diagnostic_items::DiagnosticItems;
|
||||
use rustc_hir::{Attribute, CRATE_OWNER_ID, OwnerId};
|
||||
use rustc_hir::{CRATE_OWNER_ID, OwnerId, find_attr};
|
||||
use rustc_middle::query::{LocalCrate, Providers};
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_span::Symbol;
|
||||
use rustc_span::def_id::{DefId, LOCAL_CRATE};
|
||||
use rustc_span::{Symbol, sym};
|
||||
|
||||
use crate::errors::DuplicateDiagnosticItemInCrate;
|
||||
|
||||
fn observe_item<'tcx>(tcx: TyCtxt<'tcx>, diagnostic_items: &mut DiagnosticItems, owner: OwnerId) {
|
||||
let attrs = tcx.hir_attrs(owner.into());
|
||||
if let Some(name) = extract(attrs) {
|
||||
if let Some(name) = find_attr!(attrs, AttributeKind::RustcDiagnosticItem(name) => name) {
|
||||
// insert into our table
|
||||
collect_item(tcx, diagnostic_items, name, owner.to_def_id());
|
||||
collect_item(tcx, diagnostic_items, *name, owner.to_def_id());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -53,13 +54,6 @@ fn report_duplicate_item(
|
|||
});
|
||||
}
|
||||
|
||||
/// Extract the first `rustc_diagnostic_item = "$name"` out of a list of attributes.
|
||||
fn extract(attrs: &[Attribute]) -> Option<Symbol> {
|
||||
attrs.iter().find_map(|attr| {
|
||||
if attr.has_name(sym::rustc_diagnostic_item) { attr.value_str() } else { None }
|
||||
})
|
||||
}
|
||||
|
||||
/// Traverse and collect the diagnostic items in the current
|
||||
fn diagnostic_items(tcx: TyCtxt<'_>, _: LocalCrate) -> DiagnosticItems {
|
||||
// Initialize the collector.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue