3
3
use rustc_ast:: Attribute ;
4
4
use rustc_data_structures:: sync:: Lrc ;
5
5
use rustc_expand:: base:: resolve_path;
6
+ use rustc_middle:: {
7
+ query:: { LocalCrate , Providers } ,
8
+ ty:: TyCtxt ,
9
+ } ;
6
10
use rustc_session:: Session ;
7
11
use rustc_span:: { sym, DebuggerVisualizerFile , DebuggerVisualizerType } ;
8
12
@@ -12,7 +16,7 @@ impl DebuggerVisualizerCollector<'_> {
12
16
fn check_for_debugger_visualizer ( & mut self , attr : & Attribute ) {
13
17
if attr. has_name ( sym:: debugger_visualizer) {
14
18
let Some ( hints) = attr. meta_item_list ( ) else {
15
- self . sess . emit_err ( DebugVisualizerInvalid { span : attr. span } ) ;
19
+ self . sess . emit_err ( DebugVisualizerInvalid { span : attr. span } ) ;
16
20
return ;
17
21
} ;
18
22
@@ -82,12 +86,18 @@ impl<'ast> rustc_ast::visit::Visitor<'ast> for DebuggerVisualizerCollector<'_> {
82
86
}
83
87
84
88
/// Traverses and collects the debugger visualizers for a specific crate.
85
- pub fn collect ( sess : & Session , krate : & rustc_ast:: ast:: Crate ) -> Vec < DebuggerVisualizerFile > {
86
- // Initialize the collector.
87
- let mut visitor = DebuggerVisualizerCollector { sess, visualizers : Vec :: new ( ) } ;
89
+ fn debugger_visualizers ( tcx : TyCtxt < ' _ > , _: LocalCrate ) -> Vec < DebuggerVisualizerFile > {
90
+ let resolver_and_krate = tcx. resolver_for_lowering ( ( ) ) . borrow ( ) ;
91
+ let krate = & * resolver_and_krate. 1 ;
92
+
93
+ let mut visitor = DebuggerVisualizerCollector { sess : tcx. sess , visualizers : Vec :: new ( ) } ;
88
94
rustc_ast:: visit:: Visitor :: visit_crate ( & mut visitor, krate) ;
89
95
90
96
// Sort the visualizers so we always get a deterministic query result.
91
97
visitor. visualizers . sort_unstable ( ) ;
92
98
visitor. visualizers
93
99
}
100
+
101
+ pub fn provide ( providers : & mut Providers ) {
102
+ providers. debugger_visualizers = debugger_visualizers;
103
+ }
0 commit comments