|
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,43 @@ 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) { |
58 | | - let def_id = def_id.to_def_id(); |
59 | | - let instance = Instance::new_raw( |
60 | | - def_id, |
61 | | - tcx.erase_and_anonymize_regions(GenericArgs::identity_for_item(tcx, def_id)), |
62 | | - ); |
63 | | - let mangled = tcx.symbol_name(instance); |
| 55 | + |
| 56 | + let Some(attr_span) = find_attr!( |
| 57 | + tcx.get_all_attrs(def_id), |
| 58 | + AttributeKind::RustcSymbolName(span) => span |
| 59 | + ) else { |
| 60 | + return; |
| 61 | + }; |
| 62 | + let def_id = def_id.to_def_id(); |
| 63 | + let instance = Instance::new_raw( |
| 64 | + def_id, |
| 65 | + tcx.erase_and_anonymize_regions(GenericArgs::identity_for_item(tcx, def_id)), |
| 66 | + ); |
| 67 | + let mangled = tcx.symbol_name(instance); |
| 68 | + tcx.dcx().emit_err(TestOutput { |
| 69 | + span: *attr_span, |
| 70 | + kind: Kind::SymbolName, |
| 71 | + content: format!("{mangled}"), |
| 72 | + }); |
| 73 | + if let Ok(demangling) = rustc_demangle::try_demangle(mangled.name) { |
| 74 | + tcx.dcx().emit_err(TestOutput { |
| 75 | + span: *attr_span, |
| 76 | + kind: Kind::Demangling, |
| 77 | + content: format!("{demangling}"), |
| 78 | + }); |
64 | 79 | tcx.dcx().emit_err(TestOutput { |
65 | | - span: attr.span(), |
66 | | - kind: Kind::SymbolName, |
67 | | - content: format!("{mangled}"), |
| 80 | + span: *attr_span, |
| 81 | + kind: Kind::DemanglingAlt, |
| 82 | + content: format!("{demangling:#}"), |
68 | 83 | }); |
69 | | - if let Ok(demangling) = rustc_demangle::try_demangle(mangled.name) { |
70 | | - tcx.dcx().emit_err(TestOutput { |
71 | | - span: attr.span(), |
72 | | - kind: Kind::Demangling, |
73 | | - content: format!("{demangling}"), |
74 | | - }); |
75 | | - tcx.dcx().emit_err(TestOutput { |
76 | | - span: attr.span(), |
77 | | - kind: Kind::DemanglingAlt, |
78 | | - content: format!("{demangling:#}"), |
79 | | - }); |
80 | | - } |
81 | 84 | } |
82 | 85 |
|
83 | | - for attr in tcx.get_attrs(def_id, DEF_PATH) { |
| 86 | + if let Some(attr_span) = find_attr!( |
| 87 | + tcx.get_all_attrs(def_id), |
| 88 | + AttributeKind::RustcDefPath(span) => span |
| 89 | + ) { |
84 | 90 | tcx.dcx().emit_err(TestOutput { |
85 | | - span: attr.span(), |
| 91 | + span: *attr_span, |
86 | 92 | kind: Kind::DefPath, |
87 | 93 | content: with_no_trimmed_paths!(tcx.def_path_str(def_id)), |
88 | 94 | }); |
|
0 commit comments