|
4 | 4 | //! def-path. This is used for unit testing the code that generates |
5 | 5 | //! paths etc in all kinds of annoying scenarios. |
6 | 6 |
|
| 7 | +use rustc_hir::attrs::AttributeKind; |
7 | 8 | use rustc_hir::def_id::LocalDefId; |
| 9 | +use rustc_hir::find_attr; |
8 | 10 | use rustc_middle::ty::print::with_no_trimmed_paths; |
9 | 11 | use rustc_middle::ty::{GenericArgs, Instance, TyCtxt}; |
10 | | -use rustc_span::{Symbol, sym}; |
11 | 12 |
|
12 | 13 | use crate::errors::{Kind, TestOutput}; |
13 | 14 |
|
14 | | -const SYMBOL_NAME: Symbol = sym::rustc_symbol_name; |
15 | | -const DEF_PATH: Symbol = sym::rustc_def_path; |
16 | | - |
17 | 15 | pub fn report_symbol_names(tcx: TyCtxt<'_>) { |
18 | 16 | // if the `rustc_attrs` feature is not enabled, then the |
19 | 17 | // attributes we are interested in cannot be present anyway, so |
@@ -54,35 +52,42 @@ impl SymbolNamesTest<'_> { |
54 | 52 | // The formatting of `tag({})` is chosen so that tests can elect |
55 | 53 | // to test the entirety of the string, if they choose, or else just |
56 | 54 | // some subset. |
57 | | - for attr in tcx.get_attrs(def_id, SYMBOL_NAME) { |
| 55 | + |
| 56 | + if let Some(attr_span) = find_attr!( |
| 57 | + tcx.get_all_attrs(def_id), |
| 58 | + AttributeKind::RustcSymbolName(span) => span |
| 59 | + ) { |
58 | 60 | let def_id = def_id.to_def_id(); |
59 | 61 | let instance = Instance::new_raw( |
60 | 62 | def_id, |
61 | 63 | tcx.erase_and_anonymize_regions(GenericArgs::identity_for_item(tcx, def_id)), |
62 | 64 | ); |
63 | 65 | let mangled = tcx.symbol_name(instance); |
64 | 66 | tcx.dcx().emit_err(TestOutput { |
65 | | - span: attr.span(), |
| 67 | + span: *attr_span, |
66 | 68 | kind: Kind::SymbolName, |
67 | 69 | content: format!("{mangled}"), |
68 | 70 | }); |
69 | 71 | if let Ok(demangling) = rustc_demangle::try_demangle(mangled.name) { |
70 | 72 | tcx.dcx().emit_err(TestOutput { |
71 | | - span: attr.span(), |
| 73 | + span: *attr_span, |
72 | 74 | kind: Kind::Demangling, |
73 | 75 | content: format!("{demangling}"), |
74 | 76 | }); |
75 | 77 | tcx.dcx().emit_err(TestOutput { |
76 | | - span: attr.span(), |
| 78 | + span: *attr_span, |
77 | 79 | kind: Kind::DemanglingAlt, |
78 | 80 | content: format!("{demangling:#}"), |
79 | 81 | }); |
80 | 82 | } |
81 | 83 | } |
82 | 84 |
|
83 | | - for attr in tcx.get_attrs(def_id, DEF_PATH) { |
| 85 | + if let Some(attr_span) = find_attr!( |
| 86 | + tcx.get_all_attrs(def_id), |
| 87 | + AttributeKind::RustcDefPath(span) => span |
| 88 | + ) { |
84 | 89 | tcx.dcx().emit_err(TestOutput { |
85 | | - span: attr.span(), |
| 90 | + span: *attr_span, |
86 | 91 | kind: Kind::DefPath, |
87 | 92 | content: with_no_trimmed_paths!(tcx.def_path_str(def_id)), |
88 | 93 | }); |
|
0 commit comments