Skip to content

Commit 64b4284

Browse files
fmeaseJonathanBrouwer
authored andcommitted
Simplify impl of dump_symbol_names_and_def_paths
1 parent cb4a7f4 commit 64b4284

5 files changed

Lines changed: 23 additions & 110 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4692,7 +4692,6 @@ dependencies = [
46924692
"rustc-demangle",
46934693
"rustc_abi",
46944694
"rustc_data_structures",
4695-
"rustc_errors",
46964695
"rustc_hashes",
46974696
"rustc_hir",
46984697
"rustc_middle",

compiler/rustc_symbol_mangling/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ punycode = "0.4.0"
99
rustc-demangle = "0.1.27"
1010
rustc_abi = { path = "../rustc_abi" }
1111
rustc_data_structures = { path = "../rustc_data_structures" }
12-
rustc_errors = { path = "../rustc_errors" }
1312
rustc_hashes = { path = "../rustc_hashes" }
1413
rustc_hir = { path = "../rustc_hir" }
1514
rustc_middle = { path = "../rustc_middle" }

compiler/rustc_symbol_mangling/src/errors.rs

Lines changed: 0 additions & 41 deletions
This file was deleted.

compiler/rustc_symbol_mangling/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ mod hashed;
101101
mod legacy;
102102
mod v0;
103103

104-
pub mod errors;
105104
pub mod test;
106105

107106
pub use v0::mangle_internal_symbol;

compiler/rustc_symbol_mangling/src/test.rs

Lines changed: 23 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@
44
//! def-path. This is used for unit testing the code that generates
55
//! paths etc in all kinds of annoying scenarios.
66
7-
use rustc_hir::def_id::LocalDefId;
8-
use rustc_hir::find_attr;
7+
use rustc_hir::{CRATE_OWNER_ID, find_attr};
98
use rustc_middle::ty::print::with_no_trimmed_paths;
109
use rustc_middle::ty::{GenericArgs, Instance, TyCtxt};
1110

12-
use crate::errors::{Kind, TestOutput};
13-
1411
pub fn dump_symbol_names_and_def_paths(tcx: TyCtxt<'_>) {
1512
// if the `rustc_attrs` feature is not enabled, then the
1613
// attributes we are interested in cannot be present anyway, so
@@ -20,73 +17,33 @@ pub fn dump_symbol_names_and_def_paths(tcx: TyCtxt<'_>) {
2017
}
2118

2219
tcx.dep_graph.with_ignore(|| {
23-
let mut symbol_names = SymbolNamesTest { tcx };
24-
let crate_items = tcx.hir_crate_items(());
25-
26-
for id in crate_items.free_items() {
27-
symbol_names.process_attrs(id.owner_id.def_id);
28-
}
29-
30-
for id in crate_items.trait_items() {
31-
symbol_names.process_attrs(id.owner_id.def_id);
32-
}
33-
34-
for id in crate_items.impl_items() {
35-
symbol_names.process_attrs(id.owner_id.def_id);
36-
}
20+
for id in tcx.hir_crate_items(()).owners() {
21+
if id == CRATE_OWNER_ID {
22+
continue;
23+
}
3724

38-
for id in crate_items.foreign_items() {
39-
symbol_names.process_attrs(id.owner_id.def_id);
40-
}
41-
})
42-
}
25+
// The format `$tag($value)` is chosen so that tests can elect to test the
26+
// entirety of the string, if they choose, or else just some subset.
4327

44-
struct SymbolNamesTest<'tcx> {
45-
tcx: TyCtxt<'tcx>,
46-
}
28+
if let Some(&span) = find_attr!(tcx, id.def_id, RustcDumpSymbolName(span) => span) {
29+
let def_id = id.def_id.to_def_id();
30+
let args = GenericArgs::identity_for_item(tcx, id.def_id);
31+
let args = tcx.erase_and_anonymize_regions(args);
32+
let instance = Instance::new_raw(def_id, args);
33+
let mangled = tcx.symbol_name(instance);
4734

48-
impl SymbolNamesTest<'_> {
49-
fn process_attrs(&mut self, def_id: LocalDefId) {
50-
let tcx = self.tcx;
51-
// The formatting of `tag({})` is chosen so that tests can elect
52-
// to test the entirety of the string, if they choose, or else just
53-
// some subset.
35+
tcx.dcx().span_err(span, format!("symbol-name({mangled})"));
5436

55-
if let Some(attr_span) = find_attr!(tcx, def_id, RustcDumpSymbolName(span) => span) {
56-
let def_id = def_id.to_def_id();
57-
let instance = Instance::new_raw(
58-
def_id,
59-
tcx.erase_and_anonymize_regions(GenericArgs::identity_for_item(tcx, def_id)),
60-
);
61-
let mangled = tcx.symbol_name(instance);
62-
tcx.dcx().emit_err(TestOutput {
63-
span: *attr_span,
64-
kind: Kind::SymbolName,
65-
content: format!("{mangled}"),
66-
});
67-
if let Ok(demangling) = rustc_demangle::try_demangle(mangled.name) {
68-
tcx.dcx().emit_err(TestOutput {
69-
span: *attr_span,
70-
kind: Kind::Demangling,
71-
content: format!("{demangling}"),
72-
});
73-
tcx.dcx().emit_err(TestOutput {
74-
span: *attr_span,
75-
kind: Kind::DemanglingAlt,
76-
content: format!("{demangling:#}"),
77-
});
37+
if let Ok(demangling) = rustc_demangle::try_demangle(mangled.name) {
38+
tcx.dcx().span_err(span, format!("demangling({demangling})"));
39+
tcx.dcx().span_err(span, format!("demangling-alt({demangling:#})"));
40+
}
7841
}
79-
}
8042

81-
if let Some(attr_span) = find_attr!(
82-
tcx, def_id,
83-
RustcDumpDefPath(span) => span
84-
) {
85-
tcx.dcx().emit_err(TestOutput {
86-
span: *attr_span,
87-
kind: Kind::DefPath,
88-
content: with_no_trimmed_paths!(tcx.def_path_str(def_id)),
89-
});
43+
if let Some(&span) = find_attr!(tcx, id.def_id, RustcDumpDefPath(span) => span) {
44+
let def_path = with_no_trimmed_paths!(tcx.def_path_str(id.def_id));
45+
tcx.dcx().span_err(span, format!("def-path({def_path})"));
46+
}
9047
}
91-
}
48+
})
9249
}

0 commit comments

Comments
 (0)